Google Analytics Event Tracking - Not Working

Viewed 16708

I'm trying to track outbound link clicks using Google Analytics tracking. So far, I've been unsuccessful in getting Analytics to register anything, despite using their code from this page.

Here's a sample page I'm trying to track a link (at the bottom: "Buy Who was Ghandi?"): http://ourhomeschoolforum.com/reviews/history-geography/who-was-ghandi/

Here's the code on the page:

<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-{ID redacted}', 'auto');
  ga('send', 'pageview');

</script>

<script>
/**
* Function that tracks a click on an outbound link in Analytics
* This function takes a valid URL string as an argument, and uses that URL string
* as the event label. Setting the transport method to 'beacon' lets the hit be sent
* using 'navigator.sendBeacon' in browser that support it.
*/
var trackOutboundLink = function(url) {
   ga('send', 'event', 'outbound', 'click', url, {
     'transport': 'beacon',
     'hitCallback': function(){document.location = url;}
   });
}
</script>

And here's the href I'm using:

<h2 style="text-align: center;"><a href="http://www.rainbowresource.com/product/sku/059929" target="_blank" onclick="trackOutboundLink(‘Who was Ghandi?’); return false;">Buy <em>Who Was Ghandi?</em></a></h2>

What am I doing wrong? Nothing shows in the event tracking section of Analytics Real-Time or Behavior > Events. Do I need to setup a Goal to go with it?

2 Answers
Related