我已将以下代码添加到我的JS中以跟踪按钮单击:
_gaq.push(['_trackEvent', 'category', 'action', 'label']);
我使用Chrome开发人员工具在此遇到了断点,并且_gaq肯定会解析为GA对象,我什至可以进入GA.js代码中的(最小化)推送事件。但是,即使没有错误地触发,我也没有在Fiddler/firebug/Chrome中看到任何GET或POST记录,也没有在我的分析中记录任何内容。
正常的页面分析对我来说很好,下面的代码在页面的底部运行:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'XXXXXXXXX']);
_gaq.push(['_setDomainName', '.Domain.com']);
_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>
任何人都知道为什么上面的代码不起作用?
最佳答案
常见原因是参数类型错误(在这种情况下,GA会自动失败)。
对于_trackEvent,参数必须为:
string
string
string
integer
如果期望使用字符串,请不要使用整数,反之亦然。
关于google-analytics - GA中的事件跟踪未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6410613/