Reputation: 529
Long story short, i have two website url's
www.somewebsiteA.com www.somewebsiteB.com
Both domains point to the same server.
I created a google analytics account, and setup the two urls and have individual analytics keys for them.
Is this how i should paste the google code into the pages?
<script>
(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-12345678-1', 'somewebsiteA.com');
ga('send', 'pageview');
ga('create', 'UA-12345678-2', 'somewebsiteB.com');
ga('send', 'pageview');
</script>
I'm not entirely certain. It seems like somewebsiteB.com isnt working.
Thanks!
Upvotes: 0
Views: 105
Reputation: 32532
You need to give each one their own namespace:
<script>
(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-12345678-1', {'cookieDomain':'somewebsiteA.com', 'name':'siteA'});
ga('siteA.send', 'pageview');
ga('create', 'UA-12345678-2', {'cookieDomain':'somewebsiteB.com','name':'siteB'});
ga('siteB.send', 'pageview');
</script>
Upvotes: 2