The usual method, like explained here: http://www.netmechanic.com/news/vol5/html_no3.htm
does not work, eventhough linking external css works fine.

Could you please share how you attach your js files? Been pulling my hair out trying to make this work. Using version 4.6 and xtemplate.

Comments

reikiman’s picture

Google Analytics is their new service to support measuring traffic on web sites. I'm kicking the tires right now. Installation is to insert a bit of javascript code into the HEAD of the page.

The drupal_set_html_head function lets you add code to the HEAD section.

I'm using an "_init" hook so that this code is added for every page.

function google_init() {
drupal_set_html_head('
<script src="http://www.google-analytics.com/urchin.js"
type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-xxxxxx--xx";
urchinTracker();
</script>
');
}

Replace the &lt; with a proper '<' ... I had to do that to avoid the security filtering on this site.

- David Herron - http://7gen.com/

Aleet’s picture

Hi David, Thanks for your reply.

Excuse my ignorance, but where do I put the code you provided?

Do I put it in common.inc? Or do I put it in my page.tpl.php of the template? (using Lincolns_revenge template---not xtemplate).

I put the following in common.inc after drupal_set_html_head but doesn't work:

function google_init() {
drupal_set_html_head('
&lt;script src="http://baby.com/myscripts.js" type="text/javascript">
&lt;/script>
');
}

(I took out the script containing

_uacct = "UA-xxxxxx--xx";
urchinTracker();

because I don't think that applies to me, am I right?)

reikiman’s picture

Go to .../modules, make a "google" directory, then create "google.module" and add the google_init function to that file. Then go to administer/modules and enable the google module.

- David Herron - http://7gen.com/

reikiman’s picture

If you want to force your users to use just one template, then just edit page.tpl.php to include the code you want.

I went with that module because it will support the users selecting their own modules.

And you're right about dropping the urchinTracker .. that's specific to google analytics. Just put whatever you need there.

And of course one thing to do is determine whether you're on an admin page, and not spit out the google analytics code for admin pages. Maybe the same holds true for other kinds of javascript libraries.

- David Herron - http://7gen.com/

Aleet’s picture

Module is the way to go but I have a single-template site so I just put this in the head of the template:


php print "script type=\"text/javascript\" src=\"myscripts.js\"></script" 

(With some < > missing to get this site to accept the post. )

Thanks for getting back to me.

oziumjinx’s picture

Thanks for the tips Crispy,
This code snippet seems to work well when looking at the site in FireFox but for some reason its killing the site when viewed in IE. It looks like the stylesheet is dropped and all the elements on my page are scattered.

I've tried just inserting the standard call:
<SCRIPT language=JavaScript src="/themes/box_grey/hitboxcode.js" type=text/javascript></SCRIPT> within the head portion of page.tpl.php and the same occurs. Any thoughts,
-=Vince

Technology White Papers

Aleet’s picture

I'm sorry it didn't work for you. I am pretty sure you have to put it inside php tags (with the ?, of course, my snippet shown above did't have it to get this site to accept my post). So just take the

and PRINT it using php.
zJoriz’s picture

Five years after the fact. Still, this might be useful:
I noted you started your script with SCRIPT language=JavaScript. I never saw that before, i'm used to script type="text/javascript". Went to check, and allegedly the latter is the right way to define js.

http://www.ahfb2000.com/webmaster_help_desk/showthread.php?t=3284