我正在尝试使用Google Analytics跟踪出站链接点击情况。到目前为止,尽管使用了他们这个页面上的代码,但Analytics仍未注册任何内容。
我做错了什么?在Analytics实时或行为->事件部分没有显示任何内容。我需要设置一个目标吗?
以下是我要跟踪链接的示例页面(在底部:“购买《甘地是谁?》”):http://ourhomeschoolforum.com/reviews/history-geography/who-was-ghandi/
以下是页面上的代码:
<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-{ID redacted}', 'auto');
ga('send', 'pageview');
</script>
<script>
/**
* Function that tracks a click on an outbound link in Analytics
* This function takes a valid URL string as an argument, and uses that URL string
* as the event label. Setting the transport method to 'beacon' lets the hit be sent
* using 'navigator.sendBeacon' in browser that support it.
*/
var trackOutboundLink = function(url) {
ga('send', 'event', 'outbound', 'click', url, {
'transport': 'beacon',
'hitCallback': function(){document.location = url;}
});
}
</script>
这是我使用的href:
<h2 style="text-align: center;"><a href="http://www.rainbowresource.com/product/sku/059929" target="_blank" onclick="trackOutboundLink(‘Who was Ghandi?’); return false;">Buy <em>Who Was Ghandi?</em></a></h2>
我做错了什么?在Analytics实时或行为->事件部分没有显示任何内容。我需要设置一个目标吗?