Return to Snippet

Revision: 11991
at February 26, 2009 12:16 by garside


Updated Code
$.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
})

Revision: 11990
at February 26, 2009 11:19 by garside


Initial Code
$.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,[])}
	});
}

/* Usage
 ----------------- */
$(function(){
	$.ga( 'UA-0000000-1', function(){
		this; // GoogleAnalytics Tracker
	});
})

Initial URL

                                

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

Initial Title
jQuery Google Analytics

Initial Tags
google, jquery

Initial Language
JavaScript