Skip to content

Commit a5e9fdf

Browse files
authored
Docs: Opt Out of Umami with ?stats=off (#109)
1 parent c061290 commit a5e9fdf

3 files changed

Lines changed: 24 additions & 1 deletion

File tree

‎tests/tiny-tell.spec.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,16 @@ test.describe('site pages', () => {
932932
}
933933
});
934934

935+
test('?stats=off opts the browser out of Umami, and ?stats=on puts it back', async ({ page }) => {
936+
const flag = () => page.evaluate(() => localStorage.getItem('umami.disabled'));
937+
await open(page, { path: '/docs/?stats=off#stats' });
938+
await page.waitForURL(/\/docs\/#stats$/);
939+
expect(await flag(), 'off sets the key Umami checks before every send, and drops the param').toBe('1');
940+
await open(page, { path: '/?stats=on' });
941+
await page.waitForURL(url => url.search === '');
942+
expect(await flag(), 'on clears it again').toBeNull();
943+
});
944+
935945
test('the wordmark reports the load in the state color on light, and keeps its dot in ink on dark', async ({
936946
page,
937947
}) => {

‎tools/site/docs.html‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1926,7 +1926,9 @@ <h3 id="contributing">Contributing</h3>
19261926
<h3 id="stats">Stats</h3>
19271927
<p>
19281928
The site counts visits with <a href="https://umami.is/">Umami</a>, plus which tell you pick, which install tab
1929-
you open, and which palette you try. There are no cookies, and nothing in the totals identifies you.
1929+
you open, and which palette you try. There are no cookies, and nothing in the totals identifies you. To leave
1930+
yourself out, open <a href="?stats=off#stats"><code>?stats=off</code></a> once in each browser.
1931+
<a href="?stats=on#stats"><code>?stats=on</code></a> puts you back.
19301932
</p>
19311933
</section>
19321934
<section

‎tools/site/track.js‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,14 @@ const PAGE = { '/': 'landing', '/docs/': 'docs' };
22

33
export const track = (name, data) =>
44
window.umami?.track(name, { ...data, page: PAGE[location.pathname] ?? location.pathname });
5+
6+
const url = new URL(location);
7+
const stats = url.searchParams.get('stats');
8+
if (stats === 'off' || stats === 'on') {
9+
/* Umami's own opt-out: it checks this key before every send. */
10+
try {
11+
stats === 'off' ? localStorage.setItem('umami.disabled', '1') : localStorage.removeItem('umami.disabled');
12+
} catch {}
13+
url.searchParams.delete('stats');
14+
history.replaceState(null, '', url);
15+
}

0 commit comments

Comments
 (0)