title: How to track Google Analytics anchor clicks using Universal Analytics
body: <p>I'm trying to implement anchor (index.html#anchor) tracking according to this related question:
  <a href="https://stackoverflow.com/questions/1211507/how-to-track-anchor-tags-with-google-analytics">How to track anchor tags with Google Analytics</a></p>
  
  <p>I use anchors to launch javascript easter eggs upon entering the website and I would like to track all the anchors as they would be a different pages (urls). </p>
  
  <p>So I would have tracked:</p>
  
  <pre><code>link.html                 20 pageviews
  link.html#anchor1         5 pageviews
  link.html#anchor2         8 pageviews
  </code></pre>
  
  <p>The javascript easter eggs functions are currently loaded like this:</p>
  
  <pre><code>    $(function () // on page load
      {
        if(window.location.hash.slice(1) != "")
          launchEasterEgg(window.location.hash.slice(1));
      });
  
      $(window).bind('hashchange', function ()  //hash change detected
      {
        var hash = window.location.hash.slice(1);
        launchEasterEgg(hash);
        return true;
      });
  </code></pre>
  
  <p>I'm not sure whether I should launch the tracking code on:</p>
  
  <ul>
  <li>"hash change detected" + "on page load"</li>
  <li>OR add directly to the links like: <code>&lt;a href="#anchor" onclick="eventTrackingFunction()"&gt;link&lt;/a&gt;</code></li>
  <li>OR just somehow set: <code>_gaq.push(['_setAllowAnchor', true]);</code> as I did in the previous version of GA code</li>
  </ul>
  
  <p>Also I don't quite understand what type of Google Analytics Event should I track (<a href="https://developers.google.com/analytics/devguides/collection/analyticsjs/events" rel="nofollow">https://developers.google.com/analytics/devguides/collection/analyticsjs/events</a>)</p>
  
  <p>Apart from the sample question at the top, I'm using Universal Analytics so my tracking code is different:</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-XXXXXXXX-X', 'mydomain.com');
      ga('send', 'pageview');
    &lt;/script&gt;
  </code></pre>