🐇 Burrow 14 · Nov 11 · 2 min read

Counting Every Page Open Without Tracking Anyone

Climb out

I just wanted a number

Google shows you clicks and I wanted something like that for my own pages without tracking anyone, no data or anything, just hey this page got opened. That way I know which tools people actually use.

Every open counts

Every open counts, even me opening something 1000 times lol, so if a page gets loaded a million times that's a million on the counter.

assets/offline.jsThe page side
if (navigator.webdriver || /bot|crawl|spider|slurp|lighthouse|headless|pagespeed|preview|inspection/i.test(navigator.userAgent)) return;
navigator.sendBeacon('/api/hit', location.pathname);

When a page opens it sends one tiny message with just its own address like /tools/tip-calculator, and sendBeacon sends it without slowing the page down. Search engines and speed testers get skipped so they don't mess up the numbers.

functions/api/hit.jsThe server side
const day = new Date().toISOString().slice(0, 10);
env.DB.prepare('INSERT INTO opens (day, path, n) VALUES (?1, ?2, 1) ON CONFLICT(day, path) DO UPDATE SET n = n + 1')
  .bind(day, path).run();

On Cloudflare's side it's one database row per page per day and every open just adds 1 to it. The day, the page and a number is all that gets saved, no IP or cookie or anything about you, so there's nothing to leak even if someone wanted it.

What doesn't count

It skips stuff that isn't really someone visiting, like a page you saved to your computer, my own test previews, Google Translate and the Wayback Machine. It figures that out from the address alone so it still works offline.

The Popular shelf

The Popular shelf on the homepage is just whatever tools got opened the most in the last 30 days, and it updates about once an hour.

I turned the other analytics off

Once I had this I turned off Cloudflare's own analytics, this already tells me what I wanted to know and it's way less than what they collect.

The burrow ends hereClimb back up to the surface