Event Tracking in GA not firing
Asked Answered
P

3

9

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?

Peevish answered 20/6, 2011 at 11:45 Comment(1)
Hey, whatever happened with this? Did Rimbaud's answer really solve this problem or was it something else? If the former, can you accept Rimbaud's answer with the green checkbox to the left of the answer? If the latter, can you document the solution as an answer? I'm having this same exact problem. Thanks!Discoverer
G
2

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.

Graduated answered 15/8, 2013 at 13:3 Comment(0)
S
0

As I understand it, you have the trackevent in an external .js-file, and the call to the standard script at the bottom of the <body>-tag?

The apparent solution, is to move the script:

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

Up in the <head>-tag, and the call to the external js-file below this snippet.

Like:

<html>
<head>
    <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>   
    <script type="text/javascript" src="ext.js"></script>
</head>
<body>

</body>

Sliver answered 21/6, 2011 at 10:5 Comment(2)
Moved the code into the header and the external JS file after it (in the header). Even though _gaq.push(['_trackEvent', 'category', 'action', 'label']); fires when clicking the link, I'm still not seeing any GET in fiddler and nothing in the GAPeevish
Look for images tab in NET. GA track events are fired as images.Eyler
C
0

For me, it was a pretty silly mistake. I had my own IP filtered out in GA.

Figured that might help somebody!

Cornelia answered 12/10, 2017 at 14:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.