将商品添加到购物车后,我的产品页面中有此代码:
<script type="text/javascript>
//<![CDATA[
(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';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
})();
var _gaq = _gaq || [];
_gaq.push(['_setCustomVar', 1, 'Page Type', 'Product', 3])
_gaq.push(['_setCustomVar', 2, 'Product Name', 'Gold Bracelet', 3]);
_gaq.push(['_trackEvent', 'Product Page', 'Added To Basket', 'Gold Bracelet', , 0]); // this is the line that isn't working.
_gaq.push(['_setAccount', 'UA-XXXXXXX-1']);
_gaq.push(['_trackPageview']);
//]]>
</script>
似乎跟踪了综合浏览量,这两个自定义变量,但不是 _trackEvent。就像我在标题中所说的那样,如果我将此代码复制并粘贴到 Chrome Dev Console 中,事件就会正常显示。我在返回 _trackPageview 的代码中添加了一个 alert() 并且它起作用了,所以 JS 肯定会被解析。
知道我做错了什么吗?
谢谢