Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By Aleet on
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
Here's what I did for adding google analytics
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.
Replace the < with a proper '<' ... I had to do that to avoid the security filtering on this site.
- David Herron - http://7gen.com/
+ David Herron - 7gen.com/, The Long Tail Pipe, davidherron.com/drupal-blogging-hints
Where should I put the code?
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:
(I took out the script containing
_uacct = "UA-xxxxxx--xx";
urchinTracker();
because I don't think that applies to me, am I right?)
You make it a module
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/
+ David Herron - 7gen.com/, The Long Tail Pipe, davidherron.com/drupal-blogging-hints
Oh, and it could be simpler to just edit the template
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/
+ David Herron - 7gen.com/, The Long Tail Pipe, davidherron.com/drupal-blogging-hints
Module is the way to go but
Module is the way to go but I have a single-template site so I just put this in the head of the template:
(With some < > missing to get this site to accept the post. )
Thanks for getting back to me.
Works for FF, but not IE...
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
I'm sorry it didn't work for
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.Not sure if this is still relevant...
Five years after the fact. Still, this might be useful:
I noted you started your script with . I never saw that before, i'm used to . 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