<!-- Google Analytics -->
<script>
  // https://github.com/schalkneethling/dnt-helper/blob/master/js/dnt-helper.js
  function _dntEnabled(dnt, userAgent) {
    "use strict";
    var dntStatus =
      dnt ||
      navigator.doNotTrack ||
      window.doNotTrack ||
      navigator.msDoNotTrack;
    var ua = userAgent || navigator.userAgent;
    var anomalousWinVersions = [
      "Windows NT 6.1",
      "Windows NT 6.2",
      "Windows NT 6.3"
    ];
    var fxMatch = ua.match(/Firefox\/(\d+)/);
    var ieRegEx = /MSIE|Trident/i;
    var isIE = ieRegEx.test(ua);
    var platform = ua.match(/Windows.+?(?=;)/g);
    if (isIE && typeof Array.prototype.indexOf !== "function") {
      return false;
    } else if (fxMatch && parseInt(fxMatch[1], 10) < 32) {
      dntStatus = "Unspecified";
    } else if (
      isIE &&
      platform &&
      anomalousWinVersions.indexOf(platform.toString()) !== -1
    ) {
      dntStatus = "Unspecified";
    } else {
      dntStatus =
        { "0": "Disabled", "1": "Enabled" }[dntStatus] || "Unspecified";
    }
    return dntStatus === "Enabled";
  }

  (function() {
    if (!_dntEnabled() && location.hostname !== "localhost") {
      !(function(n, o, d, e, j, s) {
        n.GoogleAnalyticsObject = d;
        n[d] ||
          (n[d] = function() {
            (n[d].q = n[d].q || []).push(arguments);
          });
        n[d].l = +new Date();
        j = o.createElement(e);
        s = o.getElementsByTagName(e)[0];
        j.async = 1;
        j.src = "//www.google-analytics.com/analytics.js";
        s.parentNode.insertBefore(j, s);
      })(window, document, "ga", "script");
      if (!ga) return;
      ga("create", "UA-96910779-8", "auto");
      ga("send", "pageview");

      // track outbound project clicks
      document.addEventListener(
        "click",
        function(e) {
          var href = e.target.closest("a") && e.target.closest("a").href;
          if (href && href.indexOf("http") > -1) {
            ga("send", "event", "outbound", "click", href);
          }
        },
        false
      );
    }
  })();
</script>
