Why doesn't Google Analytics track any events?

I implemented pretty much standard examples:

        <script>

            var _gaq = _gaq || [];
            _gaq.push(['_setAccount', 'UA-mycode']);
            _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>

            function recordOutboundLink(link, category, action) {
                try {
                    var myTracker=_gat._getTrackerByName();
                    _gaq.push(['myTracker._trackEvent', category ,  action ]);
                    setTimeout('document.location = "' + link.href + '"', 100)
                }catch(err){}
            }

        </script>

and links have this onclick event:

<a id="latestDownload" href="https://example.com" onClick="recordOutboundLink(this, 'newDownloads', 'latest');return false;">Download latest version</a>

Over the past 3 days, events have not been tracked, which sounds wrong. I tested the page with the GA debugging plugin for chrome, which shows that events are being sent.

Did I make any mistake here?

Edit:

Page: refreshless.com/nouislider/download/

Edit 2:

The Google GA debugging addon shows (literally, not obfuscated):

Account ID : UA-XXXXX-X

&utmac=UA-XXXXX-X

Do I need to press "_setAccount" again?

+3
source share
3 answers

tl; dr ... leave a call _getTrackerByName(), just use

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

: Async (. )

_gaq.push(['_setAccount', 'UA-XXXXX-1']);
_gaq.push(['_trackPageview']);
_gaq.push(['b._setAccount', 'UA-XXXXX-2']);
_gaq.push(['b._trackPageview']);

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

myTracker , UA-XXXXX-X accountId .

Specialized Tracking/Outbound Links , myTracker.

+4

myTracker - , . :

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

setTimeout - ​​, Google Analytics 100 .

:

function trackOutboundLink(url) {
    _gaq.push(['_trackEvent', 'outbound', 'click']);

    _gaq.push(function() {
        window.location = url;
    });
}

This pauses the redirect until the end of the asynchronous call to Google Analytics.

To connect:

<a href="#" onclick="trackOutboundLink('your-url');return false;">Link</a>
0
source

All Articles