Track AJAX Link Clicks Using Google Analytics
About a year back I created an advanced form for a customer that took in numerous user-given values and calculated some totals using JavaScript. No page refresh, just straight JavaScript and AJAX functionality. Obviously since there's no page refresh, Google Analytics doesn't track the form's usage. I changed all that a few days ago, using some simple MooTools code to control Google Analytics.
The MooTools 1.2
window.addEvent('load', function() {
if(pageTracker) {
$('submitButton').addEvent('click',function() {
pageTracker._trackPageview('/calculator-clicks/my-calulator');
});
}
});
Once someone clicks the button, I instruct the Google Analytics page tracker to add the click. If I go to the "Content Overview" page, I see "/calculator-clicks/my-calulator" in the URL list. Awesome!
Do any of you use this type of tracking?
Discussion
Be Heard!
Share your thoughts with fellow developers of all skill levels! I want to hear from you!
you want to change want to check on the parent object(here window) if it has a function called pageTracker otherwise it will break your app.
if(window.pageTracker)