Friday, November 16, 2012

Add AJAX Request to Google Analytics

If you use jQuery you can bind to the global AjaxComplete event to fire a Pageview everytime an Ajax call completes:
jQuery(document).ajaxComplete(function(e, xhr, settings){
  var d = document.location.pathname + document.location.search + document.location.hash;
  _gaq.push(['_trackPageview', d]);
});
Source: http://stackoverflow.com/questions/7737549/google-analytics-and-loading-a-page-using-ajax-get-request

No comments:

Post a Comment