Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,7 @@ function IframeSnapshot({ snapshot, onReady }: { snapshot: HeatmapSnapshot; onRe
className={`${styles.snapshotIframe} rr-block`}
src={iframeUrl}
title={iframeUrl}
name="umami.disabled"
tabIndex={-1}
loading="lazy"
scrolling="no"
Expand Down
33 changes: 33 additions & 0 deletions src/tracker/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,39 @@ test('identifies data-distinct-id before the initial page view', async () => {
});
});

const loadTracker = async (framed: boolean) => {
const script = document.createElement('script');
script.src = 'https://analytics.example.com/script.js';
script.dataset.websiteId = 'website-id';

Object.defineProperties(document, {
currentScript: { configurable: true, value: script },
readyState: { configurable: true, value: 'complete' },
});

const fetchMock = vi.fn().mockResolvedValue({ json: vi.fn().mockResolvedValue({}) });
vi.stubGlobal('fetch', fetchMock);
if (framed) vi.stubGlobal('top', {});
window.name = 'umami.disabled';

try {
await import('./index');
await window.umami.track('signup-button');
} finally {
window.name = '';
}

return fetchMock;
};

test('does not track when loaded in a frame named umami.disabled', async () => {
expect(await loadTracker(true)).not.toHaveBeenCalled();
});

test('still tracks in a top-level window named umami.disabled', async () => {
expect(await loadTracker(false)).toHaveBeenCalled();
});

test('ignores clicks dispatched on non-element targets', async () => {
const script = document.createElement('script');
script.src = 'https://analytics.example.com/script.js';
Expand Down
1 change: 1 addition & 0 deletions src/tracker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ type MetricEntry = PerformanceEntry & {
disabled ||
!website ||
localStorage?.getItem('umami.disabled') ||
(window.name === 'umami.disabled' && top !== window) ||
(domain && !domains.includes(hostname)) ||
(dnt && hasDoNotTrack());

Expand Down