我有一个网站,它已经有以下跟踪代码:
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);
})();
现在我需要将跟踪添加到其他帐户。以下代码是对的吗? (我刚为UA-yyyyyyyy-1插入了一行而没有改变任何其他内容)
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);
})();
谢谢!
更新
点击此链接:How to track multiple accounts using NEW analytics.js?
创建类似的代码如下。看起来很有效。任何可能的问题?
<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>
答案 0 :(得分:1)
不,您的代码只会跟踪UA-yyyyyyyy-1
属性。更改如下代码:
var _gaq = _gaq || [];
_gaq.push(['_trackPageview','UA-xxxxxxxx-1']);
_gaq.push(['_trackPageview','UA-yyyyyyyy-1']);
(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);
})();
这会发送两次综合浏览量匹配,一次发送到UA-yyyyyyyy-1
,另一次发送到UA-xxxxxxxx-1
。
调试/验证
代码很容易验证。 Chrome浏览器的步骤:
UA-yyyyyyyy-1
和UA-xxxxxxxx-1
发送的两个单独请求(__ utm.gif)。