mirror of
https://github.com/ipfs/awesome-ipfs.git
synced 2024-08-23 02:35:36 +00:00
respect dnt settings and track outbound clicks
This commit is contained in:
parent
6416172d1b
commit
2180b730a1
@ -1,10 +1,70 @@
|
||||
<!-- Google Analytics -->
|
||||
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-96910779-8"></script>
|
||||
<script>
|
||||
if (location.hostname !== 'localhost') {
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
function gtag(){dataLayer.push(arguments);}
|
||||
gtag('js', new Date());
|
||||
gtag('config', 'UA-96910779-8');
|
||||
// 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>
|
||||
|
Loading…
Reference in New Issue
Block a user