Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Event Tracking in GA not firing

I've added the folowing code into my JS to track a button click:

_gaq.push(['_trackEvent', 'category', 'action', 'label']);

I've hit a breakpoint on it using teh Chrome dev tools and _gaq definitely resolves to the GA object and I can even step into the (minified) push event in the GA.js code. However, even though this fires with no errors, I dont see any GET or POST logged in Fiddler/firebug/Chrome, nor is anything logged on my analytics. Normal page analytics are working fine for me, with the followin running at the foot of the page:

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

Anyone have any ideas why the above code isn't working?

like image 635
LDJ Avatar asked Jun 20 '11 11:06

LDJ


1 Answers

A common cause are wrong parameter types (GA fails silently in this case).

For _trackEvent, parameters have to be:

  • Category = string
  • Action = string
  • Label (optional) = string
  • Value (optional) = integer

Don't use integers when a string is expected or vice versa.

like image 120
smhg Avatar answered Oct 24 '22 08:10

smhg