2

Suppose you have two distinct Google Analytic accounts. How are you able to send request data to both accounts on a single page load? For example, on a normal account you'd include code such as:

var _gaq = _gaq || ["UA-12345678-1"];
_gaq.push(['_setAccount', '']);
_gaq.push(['_setDomainName', 'none']);
_gaq.push(['_trackPageview']);

(function() {
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

Could I simply include another snippet with a different UA ID? Can I pass several UA IDs in one request? Is this even possible to accomplish? Any help would be greatly appreciated!

1 Answer 1

5

You can use one GA snippet to send data to two different trackers. Follow the syntax below from the [Asynchronous Tracking Usage Guide][1:

_gaq.push(
  ['_setAccount', 'UA-XXXXX-1'],   //default tracker, unnamed
  ['_trackPageview'],
  ['b._setAccount', 'UA-XXXXX-2'], //second tracker, named 'b'
  ['b._trackPageview']
);

http://code.google.com/apis/analytics/docs/tracking/asyncUsageGuide.html#MultipleCommands

Additional trackers are created by giving them names and prepending the tracker name (along with a dot) in front of the method name. The example above uses the aribrary name 'b'. If a function name is qualified with the name of a tracker, it is executed on that tracker. Otherwise it is executed on the default tracker.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.