Since I last added Google Analytics to a website, Google have changed from the old urchin.js file to the shiny new ga.js file. This means that I really ought to start using ga.js now.

The University of Nottingham uses Sungard's Luminis portal system which produces some rather nasty looking URLs. Web analytics for this is rather a handful - bad URLs, multiple features per page (each of which we'd like to track) and often tracking would be nice across sub-domains.

With that in mind, and Google's Tracking Code Migration Guide close at hand, I've written jGoogleAnalytics.js to allow me to track:

  • clicks events
  • form submit events
  • cross subdomain
  • cross domain (e.g. for eCommerce payment gateways hosted externally)
  • new organic search engines
  • all the features of Jason Huck's GA jQuery integration

Download jGoogleAnalytics.js
Usage:
[source language="javascript"]// At it's simplest
$.jGoogleAnalytics( 'UA-XXXXXX-X');

// More advanced version
$.jGoogleAnalytics(
'UA-XXXXXX-X', // Your GA tracker code
{
anchorClick: false, // adds click tracking to *all* anchors
clickEvents: null, // e.g. {'.popup': '/popup/nasty'}
crossDomainSelector: false, // e.g. 'a.crossDomain'
domainName: false, // e.g. 'nottingham.ac.uk'

evalClickEvents: null, // e.g. {'#menu li a': "'/tabs/'+ $(this).text()"}
evalSubmitEvents: null, // e.g. {'#menu li a': "'/tabs/'+ $(this).text()"}

extensions: [
'pdf','doc','xls','csv','jpg','gif', 'mp3',
'swf','txt','ppt','zip','gz','dmg','xml'
], // download extensions to track

external: '/external/', // prefix to add to external links
mailto: '/mailto/', // prefix to add to email addresses
download: '/download/', // prefix to add to downloads

organicSearch: null, // e.g. {'search-engine': 'query-term', 'google.nottingham.ac.uk': 'q'}
pageViewsEnabled: true, // can be disabled e.g. if only tracking e.g. click events
sampleRate: null, // e.g. 50 - set the sample rate at 50%
submitEvents: {'#personUK': '/personsearch/uk'}
}
);[/source]

I've not added any eCommerce tracking to this release as we simply don't have the need for it.

If you use this script, pplease leave a comment!