Igor Pavelek
Igor Pavelek

Reputation: 1444

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.

Upvotes: 10

Views: 4424

Answers (4)

techstunts
techstunts

Reputation: 92

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

Upvotes: 3

Migo Kedem
Migo Kedem

Reputation: 11

Note that the Async Snippet syntax was changed

From this OLD format:

    _gaq.push(['_setAccount', 'UA-12345-1']);
    _gaq.push(['_trackPageview']);
    _gaq.push(['_trackPageLoadTime']);

You should use this:

Overriding Default Values: https://developers.google.com/analytics/devguides/collection/analyticsjs/pages

ga('send', 'pageview', {
  'page': '/my-overridden-page?id=1',
  'title': 'my overridden page'
});

Or for tracking events:

ga('send', 'event', 'button', 'click', 'nav buttons', 4);

Where:

button is the category

click is the action

nav buttons is the label

4 is the value

https://developers.google.com/analytics/devguides/collection/analyticsjs/events

Upvotes: 1

Igor Pavelek
Igor Pavelek

Reputation: 1444

After rechecking whether the code was properly installed it turned out that it was not. Sorry for my mistake, hopefully this snippet will be useful for somebody who is looking for a way of tracking Ajax requests using ExtJS.

Upvotes: 0

robjmills
robjmills

Reputation: 18598

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); 
});

Upvotes: 2

Related Questions