通过history.state/pushing
跟踪我的网站时遇到问题。我有以下Google Analytics(分析)代码:
<script type="text/javascript">
(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-XXXXXXXX-X', 'auto');
ga('send', 'pageview');
</script>
现在,我有了事件监听器来检查
history.pushState
何时发生:<script>
(function(history){
var pushState = history.pushState;
history.pushState = function(state) {
if (typeof history.onpushstate == "function") {
history.onpushstate({state: state});
}
// ... whatever else you want to do
// maybe call onhashchange e.handler
return pushState.apply(history, arguments);
}
})(window.history);
function __inArray(needle, haystack) {
var length = haystack.length;
for(var i = 0; i < length; i++) {
if(haystack[i] == needle) return true;
}
return false;
}
window.onpopstate = history.onpushstate = function(e) {
setTimeout(function() {
var path = document.location.pathname;
ga('set', path);
ga('send', 'pageview');
}, 650);
}
</script>
跟踪良好,它将适当的URL发送到了应该发送的URL,但是Chrome扩展程序Tag Assistant(由Google提供)向我报告:
相同的网站资源ID被跟踪两次。
我的Google Analytics(分析)跟踪代码的第二个实例出现在列表中的Tag Assistant中。
我的实施和/或方法有什么问题?
编辑:
我有四个网址:
/home
/home/personal-info
/home/employment-info
/home/privacy-settings
/home/documents
而且我不想跟踪
/home
。 最佳答案
如果该标签页在短时间内发送了超过一次的综合浏览量,则Tag Assistant Recordings报告警告,该页面被跟踪两次。
(Tag Assistant记录当前不考虑综合浏览量的参数,在Tag Assistant中可能应该对此进行更改)
在这种情况下,您在页面的初始化中有一个综合浏览量,在事件处理程序中有一个。