简体   繁体   English

Google Analytics(分析)事件跟踪无法正常使用Magento 1.5.0.1

[英]Google Analytics Event Tracking not working Magento 1.5.0.1

Event tracking is not working with my Magento 1.5.0.1 CE installation. 我的Magento 1.5.0.1 CE安装不支持事件跟踪。 I have updated the code app/code/local/Mage/GoogleAnalytics/Block/GA.php to: 我已将代码app / code / local / Mage / GoogleAnalytics / Block / GA.php更新为:

 <!-- BEGIN GOOGLE ANALYTICS CODE v2 -->
<script type="text/javascript">
//<![CDATA[

var _gaq = _gaq || [];
' . $this->_getPageTrackingCode($accountId) . '
' . $this->_getOrdersTrackingCode() . '
_gaq.push(["_trackPageLoadTime"]);

(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);
})();

//]]>
</script>
<!-- END GOOGLE ANALYTICS CODE -->';

Then I added an event tracking link to my homepage: 然后,我在主页上添加了事件跟踪链接:

<a href="/page-to-link-to" onClick="_gaq.push(['_trackEvent', 'Homepage Events', 'Category Headings', 'Event Im Tracking']);">LINK</a>

So I tested this in firefox via firebug and the events are not working. 因此,我通过firebug在firefox中进行了测试,因此事件无法正常工作。 Can someone please help a brother out? 有人可以帮一个兄弟吗?

Also the code is being inserted after the opening tag. 同样,代码也会插入到开始标记之后。

This is how it renders: 它是这样渲染的:

<!-- BEGIN GOOGLE ANALYTICS CODE v2 -->
<script type="text/javascript">
//<![CDATA[
    var _gaq = _gaq || [];

_gaq.push(['_setAccount', 'UA-XXXXXX-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';
    (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
    })();
//]]>
</script>
<!-- END GOOGLE ANALYTICS CODE -->

Thanks! 谢谢!

You might not see it in Firebug because it executes so quickly. 您可能在Firebug中看不到它,因为它执行得如此之快。 I would recommend testing via a proxy tool or the Live HTTP Headers plugin. 我建议通过代理工具或Live HTTP Headers插件进行测试。 See the tools recommended here. 请参阅此处推荐的工具。

Your syntax is correct. 您的语法正确。

Additionally, you may need to add a setTimeout() of 500ms or so to delay the click so that you don't encounter a race condition where the browser goes to that link prior to completing the execution of the tracking call. 此外,您可能需要添加500ms左右的setTimeout()来延迟单击,以免遇到竞争情况,浏览器无法在完成跟踪调用之前转到该链接。 I have an example of this on a blog post I wrote: 在我写的博客文章中有一个例子:

<a href="/page-to-link-to" onclick="var that=this;_gaq.push(['_trackEvent', 'Homepage Events', 'Category Headings', 'Event Im Tracking']);setTimeout(function(){location.href=that.href;},500);return false;">LINK</a>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM