chore: add google analytics

This commit is contained in:
Oli Evans 2019-05-01 10:02:08 +01:00 committed by GitHub
commit 229e0bd853
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 71 additions and 1 deletions

View File

@ -2,8 +2,8 @@
<html lang="{{ .Site.LanguageCode }}">
<head>
{{ partial "head" . }}
{{ partial "analytics" . }}
</head>
<body>
<div class="charcoal sans-serif w-90 mw8 center">
<nav class="mh2 montserrat mv4 fw6 flex-wrap ttu tracked sans-serif flex flex-between">

View File

@ -0,0 +1,70 @@
<!-- 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>