Merge pull request #62 from mikecao/do-not-track

Refactor do not track code
This commit is contained in:
Mike Cao 2020-08-23 13:45:55 -07:00 committed by GitHub
commit 8739e3624f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 24 deletions

View File

@ -48,26 +48,17 @@ export const hook = (_this, method, callback) => {
};
export const doNotTrack = () => {
if (
window.doNotTrack ||
navigator.doNotTrack ||
navigator.msDoNotTrack ||
(window.external && 'msTrackingProtectionEnabled' in window.external)
) {
if (
window.doNotTrack == '1' ||
navigator.doNotTrack == 'yes' ||
navigator.doNotTrack == '1' ||
navigator.msDoNotTrack == '1' ||
(window.external &&
window.external.msTrackingProtectionEnabled &&
window.external.msTrackingProtectionEnabled())
) {
return true;
} else {
return false;
}
} else {
return false;
}
const { doNotTrack, navigator, external } = window;
const msTracking = () => {
return (
external &&
typeof external.msTrackingProtectionEnabled === 'function' &&
external.msTrackingProtectionEnabled()
);
};
const dnt = doNotTrack || navigator.doNotTrack || navigator.msDoNotTrack || msTracking();
return dnt === true || dnt === 1 || dnt === 'yes' || dnt === '1';
};

View File

@ -1,5 +1,6 @@
import 'dotenv/config';
import buble from '@rollup/plugin-buble';
import replace from '@rollup/plugin-replace';
import resolve from '@rollup/plugin-node-resolve';
import { terser } from 'rollup-plugin-terser';
@ -9,5 +10,10 @@ export default {
file: 'public/umami.js',
format: 'iife',
},
plugins: [resolve(), buble(), terser({ compress: { evaluate: false } })],
plugins: [
replace({ __DNT__: !!process.env.ENABLE_DNT }),
resolve(),
buble(),
terser({ compress: { evaluate: false } }),
],
};

View File

@ -13,7 +13,8 @@ import { post, hook, doNotTrack } from '../lib/web';
const script = document.querySelector('script[data-website-id]');
if (!script || doNotTrack()) return;
// eslint-disable-next-line no-undef
if (!script || (__DNT__ && doNotTrack())) return;
const website = script.getAttribute('data-website-id');
const hostUrl = new URL(script.src).origin;