/ Published in: JavaScript

Simple jQuery snippet for cleanly and automatically setting up your google analytics
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
$.ga = function( ua, cb ){ $.ajax({type:'get',dataType:'script',cache:true, url:'http'+(/s:/.test(document.location.protocol)?'s://ssl':'://www')+'.google-analytics.com/ga.js', success:function(){var g=_gat._getTracker(ua);g._trackPageview();if($.isFunction(cb))cb.apply(g,[]);$.ga=g} }); } /* Usage ----------------- */ $(function(){ $.ga( 'UA-0000000-1', function(){ this; // GoogleAnalytics Tracker }); $.ga; // Now overwritten to be the GoogleAnalytics Tracker })
Comments
