我似乎无法让 Google Analytics 事件跟踪与"new"样式跟踪代码配合使用。
我拼凑了这段代码,但它可能是错误的:
<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-42805759-5', 'my-domain.com');
ga('send', 'pageview');
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-42805759-5']);
_gaq.push(['_trackPageview']);
</script>
示例链接是:
<a href="my-page.aspx" onclick="_gaq.push(['_trackEvent', 'Link click', 'My page clicked', 'Something']);">View this page</a>
这应该有效吗? 另外,跟踪的事件是否应该在仪表板的“实时”>“事件”区域中可见?
谢谢。
最佳答案
您有两个问题:
_gaq
的经典样式不能与新的通用分析互换,您将使用ga('send','event', param1, param2... )
。如果您使用经典样式代码跟踪点击事件,则在卸载页面之前不太可能报告该事件。如果您使用通用代码正确设置,它将正常工作。
关于google-analytics - Google 事件跟踪无法使用新样式的跟踪代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18488150/