feat(stats): first-party visit statistics in the admin console #2

Closed
opened 2026-11-16 10:27:12 +00:00 by dsh · 1 comment
Member

A small, privacy-first analytics module for the boilerplate — no Google, no cookies, no third-party JS.

Scope

  • record one row per navigational GET (path, UTC time, status, referrer host, client class, daily-salted IP hash); skip /static, /admin, /api, /healthz, robots.txt/sitemap.xml, non-200s
  • never store the raw IP or the full user agent: HMAC(SECRET_KEY, "<utc-date>:<ip>"), daily rotation, configurable retention + flask stats prune
  • separate crawler bucket (fun: which agents read AGENTS.md), excluded from the human headline numbers
  • Flask-Admin view /admin/stats/: today/7d/30d views + unique visitors, top pages, top referrers, daily series, crawler hits; server-rendered, no charts library
  • tests for recording rules, hashing, uniques, admin gating, prune; migration; README/AGENTS/AGENTS.d docs

Acceptance

An anonymous request is not counted; a page view is counted once per request; two requests from the same hashed IP on one day count as one unique; the admin view shows the numbers; raw IPs are never persisted.

A small, privacy-first analytics module for the boilerplate — no Google, no cookies, no third-party JS. **Scope** - record one row per navigational GET (path, UTC time, status, referrer host, client class, daily-salted IP hash); skip `/static`, `/admin`, `/api`, `/healthz`, `robots.txt`/`sitemap.xml`, non-200s - never store the raw IP or the full user agent: `HMAC(SECRET_KEY, "<utc-date>:<ip>")`, daily rotation, configurable retention + `flask stats prune` - separate crawler bucket (fun: which agents read `AGENTS.md`), excluded from the human headline numbers - Flask-Admin view `/admin/stats/`: today/7d/30d views + unique visitors, top pages, top referrers, daily series, crawler hits; server-rendered, no charts library - tests for recording rules, hashing, uniques, admin gating, prune; migration; README/AGENTS/AGENTS.d docs **Acceptance** An anonymous request is not counted; a page view is counted once per request; two requests from the same hashed IP on one day count as one unique; the admin view shows the numbers; raw IPs are never persisted.
Author
Member

Implemented in 15c5467; CI run #1190 is green (38 tests).

  • stats/: Visit model (daily HMAC of the IP, referrer host, client class — no raw IP/UA), recorder hook, dashboard queries, flask stats prune CLI, admin StatsView at /admin/stats/
  • migration 6b4f68cb1683; exclusions for static/api/admin/healthz/robots/sitemap, POSTs and non-200s; crawler bucket separate from human numbers
  • STATS_ENABLED / STATS_RETENTION_DAYS; README + AGENTS/AGENTS.d docs; container rebuilt and smoke-tested (migration applies, page view recorded, prune runs)

One deliberate deviation from the request: the IP is not stored raw, only the daily HMAC. Same counting intent, no long-lived personal identifier. Closing.

Implemented in `15c5467`; CI run [#1190](https://git.pvlb.dev/web/flango/actions/runs/2) is green (38 tests). - `stats/`: `Visit` model (daily HMAC of the IP, referrer host, client class — no raw IP/UA), recorder hook, dashboard queries, `flask stats prune` CLI, admin `StatsView` at `/admin/stats/` - migration `6b4f68cb1683`; exclusions for static/api/admin/healthz/robots/sitemap, POSTs and non-200s; crawler bucket separate from human numbers - `STATS_ENABLED` / `STATS_RETENTION_DAYS`; README + AGENTS/AGENTS.d docs; container rebuilt and smoke-tested (migration applies, page view recorded, prune runs) One deliberate deviation from the request: the IP is not stored raw, only the daily HMAC. Same counting intent, no long-lived personal identifier. Closing.
dsh closed this issue 2026-11-16 10:33:11 +00:00
Sign in to join this conversation.
No description provided.