title: Google Analytics Event Tracking - Not Working
body: <p>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 <a href="https://support.google.com/analytics/answer/1136920?hl=en" rel="noreferrer">their code from this page</a>.</p>
  
  <p>Here's a sample page I'm trying to track a link (at the bottom: "Buy Who was Ghandi?"): <a href="http://ourhomeschoolforum.com/reviews/history-geography/who-was-ghandi/" rel="noreferrer">http://ourhomeschoolforum.com/reviews/history-geography/who-was-ghandi/</a></p>
  
  <p>Here's the code on the page:</p>
  
  <pre><code>&lt;script&gt;
    (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');
  
  &lt;/script&gt;
  
  &lt;script&gt;
  /**
  * 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;}
     });
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>And here's the href I'm using:</p>
  
  <pre><code>&lt;h2 style="text-align: center;"&gt;&lt;a href="http://www.rainbowresource.com/product/sku/059929" target="_blank" onclick="trackOutboundLink(‘Who was Ghandi?’); return false;"&gt;Buy &lt;em&gt;Who Was Ghandi?&lt;/em&gt;&lt;/a&gt;&lt;/h2&gt;
  </code></pre>
  
  <p>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?</p>