web2ajax : The Blog

juin201010No talk

jQuery.gaTracker.js adds 2 features to standard Google Analytics script :
- Asynchronous Tracking ( tracking start once page load is complete )
- Allow to track dynamic pages on full ajax websites

Implementation

Load the last version of jQuery.

To init your UA-ID and track the current page, you can use it like this :

<script type="text/javascript" src="/ASSETS_JS/jquery.gatracker-v1.0-min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function($) {
	$.gaTracker.init("YOUR-UA-ID");
}) ;
</script>

Firstly, this will init the goggle analytics tracker with your Google Analytics Account ID.
Secondly, it will track the current page after ga.js load.

Track with jQuery binds

If you use dynamic navigation in Ajax, you normally already bind clicks on links in order to override standard navigator implementations.
To track those clicks with analytics, simply call $.gaTracker, passing the url in parameter, like this :

jQuery(document).ready(function($) {
	$('a').bind('click', function(e) {
		e.preventDefault() ;
		$.gaTracker.track($(this).attr('href')) ;
	}) ;
}) ;

Download

Download jQuery.gatracker.js v1.0 : source code & minified version

Pas de commentaire

Pas encore de commentaire.

LEAVE A COMMENT