我正在尝试使用事件跟踪和hitcallback来跟踪被点击的链接。我的分析代码看起来像这样......
<script type="text/javascript">//<![CDATA[
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXXX-X']);
_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);
})();
//]]></script>
我想跟踪的链接看起来像这样......
<a href='http://cool.com/' onclick="var href = this.href; ga('send','event','outbound','click', this.href, {'hitCallback': function(){document.location = href;}}); return false;">Cool</a>
我跟随http://www.swellpath.com/2013/12/universal-analytics-using-hitcallback/的hitcallback示例,但它仍无效。
我错过了什么吗?
答案 0 :(得分:8)
问题是您尝试使用通用分析语法(analytics.js)进行点击跟踪,但您使用的GA库是较早的_gaq
(ga.js)语法。
_gaq
样式确实允许您指定回调函数,尽管它没有记录。基本上,在进行_set
调用之前,您必须_trackEvent
回调函数。
您的链接应如下所示:
<a href='http://cool.com' onclick="var _this=this;_gaq.push(['_set','hitCallback',function(){document.location=_this.href;}]);_gaq.push(['_trackEvent','outbound','click',_this.href]);return false;">cool</a>