From 56ccdf8c8e5c89ca40966f0b2385ceb139fd08de Mon Sep 17 00:00:00 2001 From: Mike Cao Date: Tue, 13 Oct 2020 18:32:24 -0700 Subject: [PATCH] Allow tracker script to load even if tracking is disabled. --- tracker/index.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tracker/index.js b/tracker/index.js index df4c5216..3ad8ad3d 100644 --- a/tracker/index.js +++ b/tracker/index.js @@ -12,8 +12,10 @@ import { removeTrailingSlash } from '../lib/url'; } = window; const script = document.querySelector('script[data-website-id]'); - const attr = key => script && script.getAttribute(key); + if (!script) return; + + const attr = key => script && script.getAttribute(key); const website = attr('data-website-id'); const hostUrl = attr('data-host-url'); const autoTrack = attr('data-auto-track') !== 'false'; @@ -21,17 +23,13 @@ import { removeTrailingSlash } from '../lib/url'; const useCache = attr('data-cache'); const domains = attr('data-domains'); - if ( - !script || + const disableTracking = (dnt && doNotTrack()) || (domains && !domains .split(',') .map(n => n.trim()) - .includes(hostname)) - ) { - return; - } + .includes(hostname)); const root = hostUrl ? removeTrailingSlash(hostUrl) @@ -58,6 +56,8 @@ import { removeTrailingSlash } from '../lib/url'; }; const collect = (type, params, uuid) => { + if (disableTracking) return; + const key = 'umami.cache'; const payload = { @@ -74,7 +74,7 @@ import { removeTrailingSlash } from '../lib/url'; }); } - return post( + post( `${root}/api/collect`, { type, @@ -160,7 +160,7 @@ import { removeTrailingSlash } from '../lib/url'; /* Start */ - if (autoTrack) { + if (autoTrack && !disableTracking) { history.pushState = hook(history, 'pushState', handlePush); history.replaceState = hook(history, 'replaceState', handlePush);