Arjun Arjun - 1 year ago 107
Ajax Question

Multiple google analytics to track AJAX request

I am updating a page on my website using AJAX but for some reason Google Analytics is not registering the page visit. What I need to do so that Google Analytics update the same?

I have checked in stackoverflow for same but all of them are using single tracking ids. But I am not getting how can I use this for multiple tracking?

I have 7 tracking ids: UA-XXXXXXXX-(1-7) which I need to update depending on a value returned by my AJAX query.

I am using latest GA code:

(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
ga('create', 'UA-XXXXXXXX-X', 'auto');
ga('send', 'pageview');

What I need to do to track this properly?

Answer Source

If you are implementing multiple trackers on the same site, on the same pages, then you need to make sure that you distinguish each tracker and the functions you are calling.


// example
ga('create', 'UA-XXXXX-1', 'auto'); // main tracker
ga('send', 'pageview');

// example
ga('create', 'UA-XXXXX-2', 'auto', 'tracker2'); // secondary tracker
ga('tracker2.send', 'pageview');
ga('tracker2.set', 'page', 'some/other/page');

// example
ga('create', 'UA-XXXXX-2', 'auto', 'tracker3'); // tertiary tracker
ga('tracker3.send', 'pageview');
ga('tracker3.send','event', 'blah, 'bla');

// etc.

So for each tracker, you need to make sure you specify a name (or none for the default), and then when you call the specific method (eg. 'send', 'set', etc.), then you need to include that tracker name.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download