By aholladay on
Hi..I just fired up a site in drupal and its great. But for the life of me, I can't figure where to manually edit the header to put in a tracking code. I successfully downloaded the Google analytics module to isntall that, but I have another third party, lesser known, tracking tool where I just need to paste a few lines in. Presumably there is a file somewhere in drupal or in the db I can just go and paste it in. If so, where might it be located? Is this a correction assumption?
Thanks for any help!
Comments
Tracking code as in meta data
Tracking code as in meta data or as in javascript?
The short answer is it depends on whether or not you want this to be accessible across your entire Drupal installation regardless of theme or not. I never bothered learning how to do this across the entire installation because I only use 2 themes on my sites (1 for admin and 1 for viewing.) I do mine through my site's theme.
For the meta data, open page.tpl.php and edit/add meta tags immediately below
<title></title>in the header.If it's a javascript, you will need to upload it to your theme's scripts directory and add it's location to your theme's .info file. (Most page.tpl.php files already seem to have the
<?php print $scripts ?>needed to call the script.)Thanks kcyarn. It is
Thanks kcyarn. It is actually javascript where one piece goes in the head and the other piece goes just above the closing body tag. the page.tpl.php file does already have this...
print $scriptsCan you be more specific of what the "theme's script directory" is? How do I dentify that? Is it a file that i just paste the javascript in or do I need to create a file with the javascript in it and place it in that directory?
Also, will it hurt if i just paste the javascript directly into the page.tlp.php file? It seems that would be easiest at this point....
Thanks again!
The short answer.... Yes, you
The short answer.... Yes, you can run this code directly through your page.tlp.php file. It's probably not something you want to do in the long run.
Before you do any of the below, at a minimum make sure the script is from a trusted source. Read it if you can. Javascript can be a computer WMD in the wrong hands...
Just paste the
section into the template immediately below<? php print $scripts ?>. I wouldn't paste the javascript directly in to the page.tlp.php file because I like keeping my javascript and css separate from my template files. I find this easier to maintain. Below is the way I like to do my scripts. This adds the script to those called by the print $scripts. The scripts directory is whatever you tell it to be. For example, lets say my theme is called ThemeA, and it's in a folder named ThemeA. Inside of that directory, I have several folders in addition to my files: scripts, css, and images. So I create a new .js file inside the scripts folder and name it tracker.js. I paste my javascript into it. Now, Drupal has its own Javascript api and you may need to do a little work to get your script to play nicely with the existing scripts. Here's the javascript startup guide. You also may not need to do anything other than paste the script into the .js file. (If it has a<script type...at the top and the close script at the bottom, you'll need to remove these as they are for pasting into a web page.) Then in your ThemeA.info file, you need to add ascripts[] = scripts/tracker.jsreference. Clear your cache under Performance and you should have your script working.Thanks!
Got to work! Thanks so much. I just pasted it straight in..maybe one day I'll have the time to delve more into it to do it properly.
Thanks again.
It's strange to paste in
It's strange to paste in straight in. It's a bad habbit and it is inconvenient in the long run. Best to let drupal know the script exists. The example pointed out above is actually quite easy, just make a .js file somewhere in your theme directory or subdirectory of it. Got to the theme.info file and add it. There probably already an example there of another .js file.
No <? php print $scripts>
Hi,
I am also a "newbie" and I found this thread to be very helpful, however, the <? php print $scripts> is not called in my page.tpl.php. Can/Where should I place the <? php print $scripts> ? Or do you suggest I do something different from the course of action above?
Thanks!