I have a website, and it already has the following tracking code:
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxxxx-1']);
_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);
})();
Now I need to add tracking to another account. Is the following code right? (I just inserted a line for UA-yyyyyyyy-1 without changing anything else)
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxxxx-1']);
_gaq.push(['_setAccount', 'UA-yyyyyyyy-1']);
_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);
})();
Update
Followed this link: How to track multiple accounts using NEW analytics.js?
Created similar code as follows. It seems working. Any possible issue?
<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','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-xxxxxxxxx-1', 'auto');
ga('create', 'UA-yyyyyyyyy-1', {'name':'b'});
ga('send', 'pageview');
ga('b.send', 'pageview');
</script>
No, your code will track only for
UA-yyyyyyyy-1
property. Change the code like below:This will send the two pageview hits, one to
UA-yyyyyyyy-1
and other toUA-xxxxxxxx-1
.Debug / Validate
The code is very easy to validate. Steps for Chrome browser:
UA-yyyyyyyy-1
andUA-xxxxxxxx-1
.