Repository navigation
Count visitors only when the cookie comes back - #72
Conversation
Since e7d9475 a page request without a cookie logged a freshly minted ID, so a client that never keeps cookies counted as a new visitor on every request. One such client, reloading a stop page every 20 seconds around the clock, has inflated daily visitors from about 1.4k to 5.7k since 26 October while page hits stayed flat. Log the visitor when any request sends the cookie back; a new browser does so at once for the page's stylesheet, script and icon, so first visits still count. Add visitor_cookie to the response log so cookieless traffic stays visible, and count daily visitors exactly rather than with the approximate countDistinct. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Claude Code review — 2 findings on commit 32fc3b9 🟡 Nit —
|
Review feedback: a separate "return visitor" event for every request with a cookie duplicated that request's response event, and browsers fetch the manifest without cookies unless the link asks for them, so ordinary browsers looked cookieless. Record unique on the response line instead and drop visitor_cookie, since no unique already means no cookie. visitors.sh and the README filter on ispresent(unique), which also matches the older "return visitor" lines, so past counts are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Why
visitors.shjumped from ~1.3k to ~5.5k daily visitors on 26 Oct, while page hits stayed flat (~19–22k a day).Since e7d9475, a page request without a cookie logs a freshly minted ID. So a client that never keeps cookies counts as a new visitor on every request. Since 26 Oct, one client has been reloading a stop page every 20 seconds (the page's own auto-refresh), 24/7, without cookies. That adds ~4,300 one-request IDs a day. Excluding that client, exact distinct IDs were ~1.4–1.5k a day both before and after.
Change
uniqueon that request'sresponseline. A new browser does that straight away for the page's stylesheet, script, icon and manifest, so first visits still count. Bots and cookie-blocking clients don't count, and theirresponselines have nounique.crossorigin="use-credentials", because browsers fetch manifests without cookies otherwise, even from the same origin.visitors.shand the README filter onispresent(unique), which also matches the olderreturn visitorlines, so past figures are unchanged.visitors.shdaily counts are exact (twostatssteps).countDistinctis approximate at this cardinality: it undercounted ~1.5k-a-day days by 12–14%, which exaggerated the jump.Considered instead
Counting daily uniques as HMAC(secret, date + IP + User-Agent). In the logs, ~46% of returning cookies use more than one IP within a day, and ~360 share ~137 IPs. A hash like that would track mobile-network behaviour more than people, still count bots once per IP, and add a second "visitor" identity alongside the cookie used for weekly retention.
After merge
return visitorline.Testing
go vet ./...andgo test ./...pass.unique, and the stylesheet request that follows logs the new cookie on itsresponseline. The rendered page hascrossorigin="use-credentials"on the manifest link.visitors.shmodes were run against the live log group; daily figures match the previous filter exactly.🤖 Generated with Claude Code