Thomas
Thomas

Reputation: 523

Send events to two separate google analytics accounts?

Is it possible to send a tracking event to two separate google analytics accounts?

Upvotes: 3

Views: 3480

Answers (2)

jstats
jstats

Reputation: 606

Just to elaborate on Stephen's answer.

  • Yes, in most cases you certainly can set up multiple Google Analytics trackers and then send whatever hits you want to either or both of them.
  • Cases that might cause you issues - are when you are not strictly using the analytics.js code. (you've got some lingering ga.js)

With analytics.js, things should work as you would like it to, but with ga.js, there are some precautions to take / be aware of.

Not all configurations are supported. You can, for example, install multiple instances of the Universal Analytics tracking code (analytics.js) on your web pages but only one instance of the Classic Analytics code (ga.js). Multiple instances of ga.js might result in inaccurate data collection, processing, or reporting. You can, however, install one or more instances of analytics.js on web pages that also have a single instance of ga.js.

When you create multiple trackers, it is important that, as demonstrated in Stephen's response, you make sure to set a 'name' for the additional trackers. You can use Stephen's method like so:

ga('create', trackingId2, 'auto', {'name': 'secondAccount'});

or set the name by providing it as the fourth parameter in your 'create' like so:

ga('create', 'UA-XXXXX-Y', 'auto', 'myTracker');

Short explanation of the important parts of Stephen's code:

When sending commands for a certain tracker, you prefix the command name with the tracker name, followed by a dot. If you don't specify a tracker name, your command is run on the default tracker.

If you want more information outside of the scope of your specific question, here is the link to the analytics.js documentation on Creating Multiple Trackers.

Upvotes: 1

Stephen Thomas
Stephen Thomas

Reputation: 14053

Sure. Just be sure each account has it's own tracking ID. Then, something like the following (after including the analytics code, of course):

ga('create', trackingId1, window.location.hostname);
ga('send', 'pageview');

ga('create', trackingId2, 'auto', {'name': 'secondAccount'});
ga('secondAccount.send', 'pageview');

I'm sure there is documentation for this on Google, but the Analytics docs are a bit of a nightmare.

Upvotes: 2

Related Questions