jQuery Google Analytics


/ Published in: JavaScript
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.