Skip to content

armgit / umami

Public Imported from GitHub
0

Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.

proper cross browser dnt support

joshinat0raebf3c7022d9
diff --git a/lib/web.js b/lib/web.js
index b75a6ba7c..4b703894e 100644
--- a/lib/web.js
+++ b/lib/web.js
@@ -46,3 +46,15 @@ export const hook = (_this, method, callback) => {
return orig.apply(_this, args);
};
};
+
+export const doNotTrack = () => {
+ if (window.doNotTrack || navigator.doNotTrack || navigator.msDoNotTrack || 'msTrackingProtectionEnabled' in window.external) {
+ if (window.doNotTrack == "1" || navigator.doNotTrack == "yes" || navigator.doNotTrack == "1" || navigator.msDoNotTrack == "1" || window.external.msTrackingProtectionEnabled()) {
+ return true
+ } else {
+ return false
+ }
+ } else {
+ return false
+ }
+}
diff --git a/tracker/index.js b/tracker/index.js
index 48dcc487e..708a9b375 100644
--- a/tracker/index.js
+++ b/tracker/index.js
@@ -1,6 +1,6 @@
import 'promise-polyfill/src/polyfill';
import 'unfetch/polyfill';
-import { post, hook } from '../lib/web';
+import { post, hook, doNotTrack } from '../lib/web';
(window => {
const {
@@ -13,7 +13,7 @@ import { post, hook } from '../lib/web';
const script = document.querySelector('script[data-website-id]');
- if (!script || navigator.doNotTrack === "1") return;
+ if (!script || doNotTrack()) return;
const website = script.getAttribute('data-website-id');
const hostUrl = new URL(script.src).origin;