Google Analytics通用事件跟踪 [英] Google Analytics Universal Event Tracking
问题描述
我们正在使用新的Google Analytics通用代码,但我们的事件跟踪代码没有缝合工作。有什么不对的想法?谢谢。
We are using the new Google Analytics Universal code, but our event tracking code does not seam to be working. Any ideas on what is wrong? Thank you.
<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-XXXX-Y', 'mywebsite.com');
ga('send', 'pageview');
</script>
<a href="http://www.outbound.com" onclick="ga('send', 'event', 'link', 'click', 'label');">Click Here</a>
Google Analytics中未显示任何事件。
No events show up in Google Analytics.
推荐答案
这是因为Google Analytics跟踪代码是异步的。用户在Google Analytics(分析)Javascript代码可以ping分析服务器之前离开页面。
This is because the Google Analytics tracking code is asynchronous. The user leaves the page before Google Analytics Javascript code can ping the Analytics server.
要解决此问题,您需要在新窗口中打开出站链接,或设置回拨,这将确保Google Analytics点击发生
To fix this, you need to either open the outbound link in a new window, or set a hit callback, which will ensure the Analytics "hit" happens before the navigation.
<a onclick="ga('send', 'event', 'button', 'click', 'label', { 'hitCallback': function() { document.location = 'http://outbound.com'; }}); return false;" href="http://outbound.com">Click Here</a>
示例代码将允许您使用和不使用JavaScript浏览网站,搜索引擎将会看到链接。
The example code would allow you to navigate the site with and without javascript, and search engines will see the link.
这篇关于Google Analytics通用事件跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!