web2ajax : The Blog

juin2010102 talks

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

2 commentaires

  • Fotos de Cuenca Said:

    thanks for the dowload , bye

    20 mars 2012 18:04

  • Vinay Menon Said:

    I am finding that my Google Analytics has not been reporting any activities in my query page. Can I use the free download and check my activities of my visitors.

    13 février 2011 18:39

LEAVE A COMMENT