jQuery Google Analytics Tracking API Integration (ga.js)
Jason Huck’s gaTracker jQuery plugin allows for unobtrusive integration of the Google Analytics tracker into a page as well as attaching tracking events to each external link, mailto and download. It works seamlessly but it does however currently use the old ‘urchin.js’ which has been superceeded by Google’s new Tracking API (ga.js)
ga.js has all the capabilities of urchin.js but is structured in a fully Object oriented way. The new API has some nice new functionality which among other things allows for tracking of e-commerce transactions, which is pretty exciting. If you like that sorta thing.
I’ve quickly modified gaTracker to utilise the new API and call it’s _trackPageview() method rather than using urchinTracker(). The code is available below:
jquery.gatracker.js (Tracking API version)
It works in exactly the same way as the gaTracker 1.0.1 release, and can be dropped in it’s place, but utilises the new tracking API. Feel free to grab a copy until support gets built into the official release.
Posted in Web | Tagged with: JavaScript, jQuery


August 25th, 2008 at 4:54 pm
Thanks for this. I’m about to use this for a client site, I’ll let you know how it works out.
Have you submitted this to the plug-in repository at jquery.com?
November 4th, 2008 at 2:42 am
Hi!
Tried this, but GA website don’t see the script? Says tracking isn’t installed..?
November 4th, 2008 at 10:42 am
After a night of sleep, GA seems to have caught up. Thanks for the plugin!
November 4th, 2008 at 1:52 pm
yeah, it kicks over at midnight. Glad you found the above script useful
September 3rd, 2009 at 2:00 pm
Has this been updated to use the newer ga.js script?
November 1st, 2009 at 11:17 pm
Hi Jamie,
After implementing your script on my website I noticed that if you want to log a download url that has a question mark in it, that it doesn’t work.
Example URL:
http://www.slimweb.org/mp3/Elektra2006-12Gauge.m3u?play=1
I added m3u as file extension and noticed that clicks were not logged. The script seems to think that the extension of the url is: m3u?play=1
The quickfix I made can be added after the following line:
var ext = u.split(‘.’)[u.split('.').length - 1];
The fix:
if(ext.indexOf(‘?’) > -1) { ext = ext.split(‘?’)[0]; }
I send you the comment and not the original author because you seem to have the most recent version.
Regards,
Chris