This is probably terribly simple, but...
I want to use the new Google Analytics service, but it offers a bit of javascript code to go before the /head tag in html... How would I translate that to php for my chameleon theme?

I tried to submit the code using the code tag here, but it still got kicked out for suspicious input... So here's a screenshot instead.
http://slackdaddy.org//jpg/code.jpg

Thanks in advance

Comments

paulr’s picture

I edited chameleon.theme directly to add the analytics js code directly before the line containing $output .= "</head>";
e.g.

$output .= ' [your google analytics code here] ';
$output .= "</head>";

I didn't have to escape anything in the code, just worked as described above. Good Luck.

keto-1’s picture

thanks paulr for posting this.

hypersloth’s picture

for the prompt response - I'll try it when I get home.

legacyb4’s picture

That seemed to work.

www.lumine.net

Cheers.

keto-1’s picture

legacyb4, you might want to move where you have your code placed. having anthing above your title tag other then your doctype is not recommended.

best of luck,

keto

legacyb4’s picture

Code moved to right above </head>.

Thanks for the tip.

Noticing that in different theme (Chameleon, for example), the code appears as one long string. Assume that still works?

www.lumine.net

budda’s picture

You'll be happy to know the solution is much easier with the module located at http://www.ixis.co.uk/drupal-modules/google-analytics

Happy analysing!

--
www.bargainspy.co.uk

keto-1’s picture

Thanks budda. I just got everything setup last night and I am still not seeing any stats. I am assuming that is because 3 million people signed up for this service today after the news stories all over the web. stupid slashdot! heheh

- keto

budda’s picture

Yeah I've got no stats yet either, still claiming they will be available in 12 hours, it's been a good few days now!

--
www.bargainspy.co.uk | More Drupal modules

hypersloth’s picture

and my other site is old-fashioned html, and had a good 15 hour head start. Good to know I'm not the only one not getting reports yet.. I'm off to look for answers outside drupal.

Meanwhile, thanks for the link to the module, budda!

Marc Bijl’s picture

Got this message today at my Analytics account:

The demand for Google Analytics surpassed even our highest expectations and as a result some customers may temporarily experience report-update delays. All data continues to be collected and no data has been lost. We are currently adding resources to ensure high-quality service. We apologize for any inconvenience.

___________________
discover new oceans
lose sight of the shore

legacyb4’s picture

Not sure if it's coincidence, but since trying out the module, my stats have gone flat...

jbrauer’s picture

I did a quick conversion of the module to work with Drupal 4.7b4 (and it shouldn't break with the release).

http://addingunderstanding.com/google_analytics_module_drupal_4.7

------------------------------
Adding Understanding

--

Marco Palmero’s picture

Wow... Thank god I stumbled on this post...

This service looks to be a killer for all those other counter utilities out there...

Its free and looks great.

http://www.google.com/analytics/

Thanks guys for the drupal module and info.
_________________________________________________
Blog - Sydney News, Current Affairs, Photography, Travelling & University...

Jesse Grosjean’s picture

Does anyone know if this module will work to track file downloads. I have Drupal's download method set to:

Private - files are transferred by Drupal.

Does anyone know if that will work? I know that I can use this method to track file downloads:

http://www.google.com/support/analytics/bin/answer.py?answer=27242&hl=en

But I'm wondering if there is a way to make drupal do this automatically so I don't need to update all the download links on my site.

budda’s picture

Interesting, please file a feature request!

--
Ixis (UK) providing Drupal consultancy and Drupal theme design.

gari’s picture

I dont think putting the analytics code inside the head section is required. I put the code inside a block and it still works.

What I did was put the analytics code inside a Google Adsense block that I created. Like this:

Excluding Drupal Admin activities in Google Analytics

So that when I'm logged in as administrator, my activities don't get reflected in my Google Analytics stats.

(Sorry for the link. I too cant post code due to 'suspicious input'.)

budda’s picture

Good idea about not putting tracking data in the head of admin pages. I'll amend the module to reflect this sometime soon.

--
www.bargainspy.co.uk | More Drupal modules

Matt Fleming’s picture

Hi there,

I just installed your module and decided to have a look at the code. How does drupal persist "googleanalytics_account" variable that is set in the module? Is it in the db somewhere?

budda’s picture

You enter the account id in the module settings page.
This is saved in the variables table in the dbase.

--
www.bargainspy.co.uk | More Drupal modules

noid’s picture

Thanks for the googleanalytics module, budda!

What should be the format of the user ID to be entered in the googleanalytics setting? Should it be UA-xxxxxx-x including the UA (and without the quotes)?

budda’s picture

Yeah enter it exactly as you would have it in the javascript provided by Google.

--
www.bargainspy.co.uk | More Drupal modules

noid’s picture

Entered the proper user account format, but after 24 hours it still says in my account, 'Tracking not installed,' even if my site was checked recently by Google Analytics. I've also viewed the source for each of my web pages and the script is there. Any step I might have missed?

I am using a customized phptemplate version of the bluemarine theme btw.

budda’s picture

Template types don't matter.
Google is pretty slack. Give it a good few days.

As a 2nd check, view your sites html and compare the generated javascript at the top of the page with that which Google provides. it should be identical.

--
www.bargainspy.co.uk | More Drupal modules

aliceerickson’s picture

I added the Google module to a website a couple of weeks ago, and it works great. Now, however, the site owners want to track downloads through Google as well. I coerced the Google tracking code in the download links, and thought I was home free. Then I read the through the stuff at Google. If you want to use the download tracking code, then the Google stats code has to be above the links in the page! The nice Google module puts it at the botom. I'm not sure what the best thing is to do here, but I suppose I'm going to have to disabled the Google module and work the code into a block that I can put farther up on the page. Does anybody out there have some advice on that? I'm pretty new to Drupal, and I'm poking around in the dark.

budda’s picture

Excluding admin/ pages is now included in the Drupal 4.7 release of the Google Analytics module available right here on drupal.org!

--
Drupal consultancy

jrstmartin’s picture

How exactly do you exclude admin pages with the google_analytics.module? I don't see anywhere to specify this other than in the custom script section, but I don't know what to put anyway.

meenik’s picture

I'm confused about where to, or whether to, add the tracking code provided by google.

If we have to add the tracking code manually, what is the module doing?

Where is the best place to add the tracking code? I tried putting it in the footer, using the footer field via settings, but now it actually displays some "_uacct = "UA-296245-1"; urchinTracker();" at the bottom of my site, which I obviosly don't want.

I originally assumed I would just enter my UA code into the module settings and it would enter the code for me, but that didn't seem to happen.

I spent some time searching and reading all the posts, but it got pretty confusing and there is currently a lot of conflicting advice.

Help.

Thank you!

budda’s picture

All you need to do is enter your UA-296245-1 ID in the module settings page. Set what user roles you want to track, and you're off.

--
Ixis (UK) providing Drupal consultancy and Drupal theme design.