For two years, the heaviest script on my portfolio was a tracker. It counted my readers, and in exchange it cost a network request to a third party, a consent banner I never wanted, and a permanent leak of who read what to a company that does not know my name. Today the whole analytics stack is one PHP file that answers every request with HTTP 204 No Content. It counts everything I care about and ships nothing to anyone.
What a 204 buys you
The beacon is one GET request:
/px.php?a=self-verifying-deploy-workers
There is no response body, no cookies, no redirect, no follow-up. The browser fires it from a few lines of inline JavaScript on each page and forgets about it. The server, meanwhile, has four things to do: refuse bots, hash the visitor, check the dedup log, count the read.
Bot filtering first, because robots outnumber people on a small site by an ugly margin. Empty user-agents and anything matching the usual suspects - bot, crawl, spider, curl, python, headless, monitor - get a 204 and nothing else.
Then the interesting part. The visitor's IP never touches disk. It is hashed with a salt:
$h = sha1($SALT . $ip . '|' . $slug);
The salt is a 32-character random string in a file outside any web-visible path. The hash that lands in the log is useless without it: you cannot reverse a salted SHA-1, and you cannot correlate hashes across sites because the salt never leaves my server. I can tell that "the same browser" read two articles today. I cannot tell who that browser belongs to. That is the entire bargain, and it is the bargain I want.
Dedup is a flat file. Each accepted visit appends hash|day to a daily log unless that hash is already in it, which is what makes the counter count readers rather than pageloads. The accepted ones increment one line in a JSON file. That JSON file is the whole database.
The day the beacon lied to me
A week into this setup, the counter froze at zero. No errors, no downtime. Every beacon still returned HTTP 200 and every fetch on the client still resolved fine. The file itself had been truncated to 0 bytes during an edit, and PHP, bless its heart, served those 0 bytes as a perfectly successful empty response.
That is the failure mode nobody warns you about with self-hosted anything: a silent empty 200 looks identical to success from the outside. My "monitoring" was the thing being monitored, so it could not report its own death. I found it by fetching the endpoint manually and getting nothing back - the one check that had never been automated.
The rebuilt beacon got more honest about itself. It now writes a raw log line for every accepted hit - timestamp, salted hash, slug - separate from the dedup log. That raw log is what powers the live features, and it is also the audit trail: if the counter says zero while the raw log has rows, the bug is in the counting, not the collecting.
The part where the analytics became the product
Once every hit was a log line, things I had assumed needed infrastructure fell out for free.
A live-reader counter is a count of unique hashes with a timestamp in the last 300 seconds. One endpoint, a file scan, JSON out. No websockets, no Redis, no presence server. The green "2 readers" chip on my homepage is PHP reading yesterday's and today's logs.
A Most-Read strip is the same JSON sorted descending, top five, linked. No fake numbers - which sounds like a low bar until you remember that most "popular posts" widgets on the web are editorial lies rendered by JavaScript.
And a public metrics page is the same data with the salt still applied and the hashes still hidden. It shows total reads, per-article counts, how many people are reading right now, and how many backup files my deploy workers have left behind. Every number on it is computed live from the same files this post describes. There is nothing else.
Your own test traffic is the sneakiest bug
The next problem was me. Every time I shipped a change, my verification loopback hit the beacon with a browser user-agent, got counted, and inserted a fake article into my own leaderboard. Analytics data that only you pollute is still polluted data.
The fix was a denylist in the beacon itself: any slug containing "test" gets the 204 and never touches the books. Three lines, and the measurement system finally knows the difference between traffic and quality assurance. Your monitoring will meet your own tooling eventually. Make sure it knows whose side each request is on.
The scoreboard
What it replaced: a third-party analytics script, its requests, its cookies, its consent-banner implications.
What it costs: one file of PHP, roughly two kilobytes. Zero requests leave my domain. Zero dollars.
What I gave up: funnel analysis, referrer chains, session replay, cohort anything. I miss none of it. For referrers, my host's raw access logs are still there - I just stopped needing a third party to summarize them.
What I gained: a live pulse, an honest leaderboard, a public metrics page that doubles as a portfolio piece, and a counter that cannot sell my readers to anyone, including me.
What I'd tell myself last month
A 204 is a complete response. Your beacon does not owe the browser a payload, and the less it says, the less it can leak.
Self-hosted does not mean self-monitoring. The endpoint that takes the measurements cannot measure its own death - check your checkers with something that lives outside them.
Salt the hash before you decide it is safe. An unsalted IP hash is a pseudonym, not privacy, and pseudonyms de-anonymize themselves the moment someone builds a second log.
And write the raw log even before you know what it is for. You will need it the day the summary number lies to you.
Bryan Hamilton builds and runs bryanhamilton.info solo - rack-gear portfolio, token-gated deploy workers, and now its own analytics. This post is part of the series Anatomy of a One-Man SaaS. The live version with working demos: bryanhamilton.info/writing/i-replaced-google-analytics-with-a-204/ (https://bryanhamilton.info/writing/i-replaced-google-analytics-with-a-204/) - and every number in the post is public at bryanhamilton.info/metrics.php (https://bryanhamilton.info/metrics.php).