Posted By

garside on 02/26/09


Tagged

google jquery Analytics googleanalytics urchinjs gajs


Versions (?)

Who likes this?

7 people have marked this snippet as a favorite

LeeRJohnson
xtheonex
jamesming
chrisjlee
loric
masondixon
seanpowell


jQuery Google Analytics


 / Published in: JavaScript
 

Simple jQuery snippet for cleanly and automatically setting up your google analytics

  1. $.ga = function( ua, cb ){
  2. $.ajax({type:'get',dataType:'script',cache:true,
  3. url:'http'+(/s:/.test(document.location.protocol)?'s://ssl':'://www')+'.google-analytics.com/ga.js',
  4. success:function(){var g=_gat._getTracker(ua);g._trackPageview();if($.isFunction(cb))cb.apply(g,[]);$.ga=g}
  5. });
  6. }
  7.  
  8. /* Usage
  9.  ----------------- */
  10. $(function(){
  11. $.ga( 'UA-0000000-1', function(){
  12. this; // GoogleAnalytics Tracker
  13. });
  14. $.ga; // Now overwritten to be the GoogleAnalytics Tracker
  15. })

Report this snippet  

You need to login to post a comment.