1
votes

Me and a friend we are trying to get Event Tracking working since days, but we just cant make it work. It would mean the world to me if you could take a look and try to help. Thanks.

You can take a look in the code yourself, the URL is http://www.meinAuslandssemester.com . What we are trying to do is to track the outgoing Amazon links as an event (Blue buttons in sidebar, footer and one below on the landing page).

The code in the header goes like this:

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-37237070-1']);
  _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/u/ga_debug.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>

<script type="text/javascript">
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>

The first part is just the regular tracking code, while the second part is suggested by Google to track outbound links.

The links on the landing page go: <”a class="mainbutton" style="padding: 6px 60px 6px 60px;" onclick="recordOutboundLink(this, 'RekordOutbndLnks', 'ausland.com');return false;" href="http://www.amazon.de/gp/reader/1481174193/?tag=simmenfl-21">Das erste Kapitel gratis lesen"

And since all of this didnt work, we also tried a different version, currently live in the sidebar and footer: <"a class="sidebarbutton" href="http://www.amazon.de/dp/B00ARLDGD0/?tag=simmenfl-21" onclick="_gaq.push(['_trackEvent', 'ExternalLinks', 'Amazon','SidebarKindle']);return false;">Kindle Edition: 9,99€ 

Unfortunately neither version 1 or 2 are working and we just cant find the problem. Any ideas? Forget the " before the a in the final links, I just added these so the code can be displayed. Couldnt do any better sorry! :)

Thank you so much for trying to help, we eventually gave up :(

Relevant links:

http://support.google.com/analytics/bin/answer.py?hl=en&answer=1136920

1

1 Answers

0
votes

Version 2 won't work because the GA async code won't be executed before the link is followed, which is the reason for the setTimeout delay in the google example.

As for version 1, unfortunately, the google example needs a bit of tweaking before it can be used - see Why is Google Analytics not tracking any events? - i.e. try replacing

var myTracker=_gat._getTrackerByName();
_gaq.push(['myTracker._trackEvent', category , action ]);

with

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