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.

Allow tracker script to load even if tracking is disabled.

Mike Cao56ccdf8c8e5c
diff --git a/tracker/index.js b/tracker/index.js
index df4c52161..3ad8ad3de 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);