Skip to content

Commit

Permalink
Added check for do not track to tracker.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecao committed Mar 2, 2025
1 parent 925c756 commit cb7eef2
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/tracker/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
(window => {
const {
screen: { width, height },
navigator: { language },
navigator: { language, doNotTrack: ndnt, msDoNotTrack: msdnt },
location,
document,
history,
top,
doNotTrack,
} = window;
const { hostname, href, origin } = location;
const { currentScript, referrer } = document;
Expand All @@ -21,6 +22,7 @@
const hostUrl = attr(_data + 'host-url');
const tag = attr(_data + 'tag');
const autoTrack = attr(_data + 'auto-track') !== _false;
const dnt = attr(_data + 'do-not-track') === _true;
const excludeSearch = attr(_data + 'exclude-search') === _true;
const excludeHash = attr(_data + 'exclude-hash') === _true;
const domain = attr(_data + 'domains') || '';
Expand All @@ -46,6 +48,11 @@
tag: tag ? tag : undefined,
});

const hasDoNotTrack = () => {
const dnt = doNotTrack || ndnt || msdnt;
return dnt === 1 || dnt === '1' || dnt === 'yes';
};

/* Event handlers */

const handlePush = (state, title, url) => {
Expand Down Expand Up @@ -182,7 +189,8 @@
disabled ||
!website ||
(localStorage && localStorage.getItem('umami.disabled')) ||
(domain && !domains.includes(hostname));
(domain && !domains.includes(hostname)) ||
(dnt && hasDoNotTrack());

const send = async (payload, type = 'event') => {
if (trackingDisabled()) return;
Expand Down

1 comment on commit cb7eef2

@CodeAlDente
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🫣 You should consider reverting this.

  • DNT is losing relevance. The W3C standard never gained widespread adoption, and modern browsers continue to move away from (or never fully implement) DNT in favor of more advanced tracking prevention methods. See MDN’s Do Not Track documentation for more details.
  • Umami is already privacy-friendly (cookie-free and no IP storage), which addresses the core intent of DNT. Excluding users based on a near-defunct header can significantly reduce the accuracy of analytics while offering little additional privacy benefit.

Please sign in to comment.