1

I need to track a website with Universal Analytics in two different properties of the same account.

Following a guide here http://www.tjkelly.com/blog/google-analytics-two-tracking-codes-on-same-page-2014/ I put this as last solution:

(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create','UA-xxxxxxx-1','domain.co');
ga('create','UA-yyyyyyyy-2',{'name':'b'});
ga('send','pageview');
ga('b.send','pageview');

Is this correct? It seems to work but it's pretty different from the guidelines https://developers.google.com/analytics/devguides/collection/analyticsjs/advanced#multipletrackers and

  • Sorry, but it's the same code :) – jakub.kowalik Jan 8 '15 at 22:41
  • What do you see in your real time reports? Maybe that will answer your question. – nyuen Jan 9 '15 at 7:22
  • It's pretty similar, but what's the difference from setting "auto" to "domain name" in predefined tracker, and in the second tracker doesn't set it at all? – lucgenti Jan 9 '15 at 10:22
  • I see the same stuff. But maybe I'm not considering something else. – lucgenti Jan 9 '15 at 10:23
  • The 'auto' setting just says to set the cookie at the highest available domain possible, which in this case is domain.com. Leaving the cookie domain blank does the same thing and GA will again set the cookie to the highest domain availability. Defining the cookie domain sets the cookie domain to exactly that. – nyuen Jan 9 '15 at 15:12
0

The 'auto' setting just says to set the cookie at the highest available domain possible, which in this case is domain.com. Leaving the cookie domain blank does the same thing and GA will again set the cookie to the highest domain available. Defining the cookie domain sets the cookie domain to exactly that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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