Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to track Ajax requests using Google Analytics?

I'm trying to use Google Analytics to track any Ajax request made by my web application (in my case built on ExtJS, but it doesn't matter right now).

I wrote few lines of code to track all Ajax requests:

Ext.Ajax.on('requestcomplete', function(connection, options) {
    pageTracker._trackPageview('/'+options.url);
});

but it doesn't work (it kind of works, but it doesn't track all the request). The numbers I'm getting are much lower than the number of my requests.

like image 844
Igor Pavelek Avatar asked Nov 23 '09 18:11

Igor Pavelek


2 Answers

In the latest (Async) version of ga code, use:-

_gaq.push(['_trackPageview', '/home/landingPage']);

http://code.google.com/apis/analytics/docs/gaJS/gaJSApiBasicConfiguration.html#_gat.GA_Tracker_._trackPageview

like image 178
techstunts Avatar answered Oct 03 '22 09:10

techstunts


it could be that you're using the old tracking code, if so your code should look like:

Ext.Ajax.on('requestcomplete', function(connection, options) {
    urchinTracker('/'+options.url); 
});
like image 32
robjmills Avatar answered Oct 03 '22 08:10

robjmills