Google Analytics(分析)hitCallback事件跟踪无法正常工作

fig*_*r20 6 google-analytics

我正在尝试使用事件跟踪和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>
Run Code Online (Sandbox Code Playgroud)

我试图跟踪的链接看起来像这样....

<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>
Run Code Online (Sandbox Code Playgroud)

我从http://www.swellpath.com/2013/12/universal-analytics-using-hitcallback/跟随hitcallback示例,但它仍然无法正常工作.

我错过了什么吗?

Cra*_*ent 8

问题是您尝试使用Universal Analytics语法(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>
Run Code Online (Sandbox Code Playgroud)