ononononon
ononononon

Reputation: 1083

Google analytics tracking event doesnt work

good people,

I have a magento eshop and now I've added google event for link click to it. This is the code that magento added automatically:

<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://' : 'http://') + 'stats.g.doubleclick.net/dc.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
    })();
//]]>
</script>

This works perfectly fine, it shows real-time data in the analytics panel so I know it works.

Now I've added an event for the link:

<a href="link to other internal page"
  onClick="_gaq.push(['_trackEvent', 'Side Banners', 'click', 'left banner', '0']);"
>
  <img src="imagesrc" />
</a>

And this doesnt track any events ( in analytics panel Behavior -> Events -> Overview ).

Ofc i've tried modifying the _gaq.push, running it in the console, nothing seems to work.

Any ideas ?

Upvotes: 2

Views: 359

Answers (1)

David Wilkinson
David Wilkinson

Reputation: 5118

The fourth optional 'value' you've assigned ('0') should be an integer and not a string:

onClick="_gaq.push(['_trackEvent', 'Side Banners', 'click', 'left banner', '0']);"

should be:

onClick="_gaq.push(['_trackEvent', 'Side Banners', 'click', 'left banner', 0]);"

Reference: https://developers.google.com/analytics/devguides/collection/gajs/methods/gaJSApiEventTracking

EDIT: As in the comments section, make sure you're viewing the Real-Time Event viewer when doing test clicks / event firing: Real-time > Events

Upvotes: 3

Related Questions