0

Event tracking is not working with my Magento 1.5.0.1 CE installation. I have updated the code app/code/local/Mage/GoogleAnalytics/Block/GA.php to:

 <!-- 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. 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!

Michael Conner
  • 103
  • 1
  • 3
  • 13

1 Answers1

0

You might not see it in Firebug because it executes so quickly. I would recommend testing via a proxy tool or the Live HTTP Headers plugin. 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. 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>
  • Getting this error: Uncaught TypeError: Cannot read property 'addEventListener' of null prototype.js line 4021 – Michael Conner May 18 '12 at 16:44
  • @MichaelConner If you can share your URL, that would allow me to look into why you are getting that error. You can also email me the URL if you don't want to post it here. joe at blastam /dot/ com – Joe Christopher May 18 '12 at 17:12