feat(docs): cookieless first-party docs-site analytics (no 3rd party) - #40
Open
ProjectBay wants to merge 1 commit into
Open
feat(docs): cookieless first-party docs-site analytics (no 3rd party)#40ProjectBay wants to merge 1 commit into
ProjectBay wants to merge 1 commit into
Conversation
Add a self-hosted, cookieless pageview analytics stack for the docs site: - apps/docs-analytics/: a small standalone Node/TS collector (better-sqlite3), with POST /collect, GET /stats (HTML dashboard) + /stats.json + /health, and a Dockerfile/compose/README for a one-command VPS deploy. Privacy-first — client IP+UA hashed with a per-day rotating salt (raw IP never stored), no cookies, no PII, DNT-respecting, bounded retention. - apps/docs: a cookieless clientModule beacon + config wiring; a complete no-op unless built with DOCS_ANALYTICS_URL, so dev/PR builds never phone home. - deploy-docs.yml: pass DOCS_ANALYTICS_URL from a repo variable (unset ⇒ no-op). Verified locally: collector build clean + every endpoint exercised (ingest, aggregation, bot-filter, size limit, auth); docs build succeeds with the global injected only when DOCS_ANALYTICS_URL is set. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds cookieless, first-party traffic analytics for the docs site — no
third-party services. The Docusaurus site sends an anonymous beacon on each
pageview to a tiny collector you run on your VPS; it stores aggregate counts
in SQLite and serves a small stats dashboard.
Two pieces:
apps/docs-analytics/— a small standalone Node/TypeScript service (onedependency:
better-sqlite3). Endpoints:POST /collect,GET /stats(HTMLdashboard),
GET /stats.json,GET /health. Ships with aDockerfile+docker-compose.yml+ README for a one-command VPS deploy.apps/docs— a cookielessclientModulebeacon + config wiring. It's acomplete no-op unless the docs are built with
DOCS_ANALYTICS_URLset, solocal dev and PR/preview builds never phone home.
deploy-docs.ymlpasses itfrom a
DOCS_ANALYTICS_URLrepo variable (unset ⇒ nothing changes).Privacy
No cookies, no
localStorage, no fingerprinting, no PII at rest, honorsnavigator.doNotTrack. The client IP + User-Agent are combined with a per-dayrotating salt and SHA-256 hashed into a visitor id used only for daily
de-duplication — the raw IP is never stored, and the daily salt rotation means
a visitor can't be correlated across days. GDPR-friendly with no cookie banner.
Footprint: one small Node process + a SQLite file (no Postgres/ClickHouse).
Verified locally
npm install+tscbuild clean (0 vulns). Ran it and exercisedevery path —
/collect→204, real beacons aggregate correctly(
views=3, uniques=2), query strings stripped from paths, referrer hostsextracted, bot UA dropped from stats, oversized body →
413,/statswithout token →
401, with token → HTML + JSON.npm run buildsucceeds with the beacon wired in; the runtime globalis injected into the built HTML only when
DOCS_ANALYTICS_URLis set.To turn it on
apps/docs-analytics/README.md), behind yourTLS reverse proxy, with a
STATS_TOKEN.DOCS_ANALYTICS_URLrepository variable to the collector's/collectURL. The next docs deploy activates the beacon.https://<collector-host>/stats?token=<STATS_TOKEN>.Until step 2, this changes nothing user-facing — the beacon stays dormant.
🤖 Generated with Claude Code