Skip to content

feat(analytics): count page views and waitlist outcomes, no cookie, no person - #53

Merged
steveapo merged 6 commits into
mainfrom
feat/analytics-counts-only
Nov 21, 2026
Merged

steveapo merged 6 commits into
mainfrom
feat/analytics-counts-only

Conversation

@steveapo

@steveapo steveapo commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Merge only on the owner's word, after the owner has read the balancing record. This pull request changes reader-facing text, all of it owner-approved on 21 November 2026. The lawful basis (legitimate interest) and the retention period (one year, PostHog Free plan) are settled and are in the page.

What this does

Counts, and nothing else: page_view (a route pattern: /, /privacy, /confirmed or other) and waitlist_submit (ok, already, invalid, rate_limited, error). No cookie, no localStorage key, no person profile, no autocapture, recording, survey or feature flag.

Nothing is collected until the owner sets NEXT_PUBLIC_POSTHOG_KEY. Without the variable every function returns at once and posthog-js is never fetched.

Privacy text. The owner-approved wording of reports/texts-for-approval.md (items 1a, 1b, 1c), taken character for character, is in app/(site)/privacy/page.tsx: a "Counting visits" paragraph directly after "Where you signed up from", ending with the sentence about the network address, and the clause "a measurement service in the European Union, which receives the messages described under "Counting visits" through this site's own address;" after "the provider that hosts this site;". In "Why we may hold it", directly after "...and in knowing which posts reach people.", the owner-approved sentence "For counting visits, our legitimate interest in knowing whether the site and its form work." is added, and the paragraph's last sentence changes from "You can object to either by writing to us." to "You can object to any of these by writing to us." Nothing else in that paragraph changes. In "How long", the last sentence "The counts of visits are kept for one year and then deleted." is appended and nothing else in that paragraph changes. In the same paragraph, "Records used to stop the form being misused are short-lived and deleted automatically." becomes "Records used to stop the form or the counting being misused are short-lived and deleted automatically.", because the rate limit on /ingest keeps a visitor's network address for a minute. "Last updated" is now 21 November 2026, in the page's existing date format; it moves again if the merge falls on a later day. The cookie paragraph is untouched. lib/privacy-text.test.tsx pins the whole text, so a later edit fails it. The approved file's line references in the request were one line off (the wording sits on lines 30, 38 and 46); the wording is what matters and the test compares it. The copy linter reports nothing on the page.

How

  • lib/analytics.ts: the closed event list (the only way to capture), scrub as the before_send allowlist, every posthog-js option written out (persistence: 'memory', person_profiles: 'never', defaults: '2026-08-30'), lazy import('posthog-js') after the window load event. posthog-js is pinned at 1.453.2; each option name was checked by the type checker against the installed package.
  • lib/analytics-proxy.ts and app/ingest/[...path]/route.ts: a same-origin forward to PostHog's EU cloud (fixed in code, no host variable). It relays POST /ingest/e/ and nothing else (A1): that is the only path posthog-js 1.453.2 calls with this configuration, as lib/analytics-capture.test.ts records it, and the test fails if a library update calls anywhere else. Every other path answers 404 and every other method 405, with nothing sent upstream; the assets host is not reachable at all. It copies four request headers (content-type, content-encoding, accept, user-agent) and so forwards no Cookie, Authorization, forwarded-for or referrer; it passes back no Set-Cookie; bodies over 256 KB are refused; a PostHog outage answers 502 and is invisible to the page.
  • Per-client limit (A2): 120 posts a minute per address of origin through the existing Upstash limiter (lib/rate-limit.ts, a new ingest bucket). Over the limit: 429, nothing sent upstream. If the limiter cannot count (Upstash not configured in production, or it does not answer), the forward answers 503 and sends nothing: an unlimited relay is not acceptable, and analytics must not break a page, so the library drops the event and the page never knows. Outside production an unconfigured limiter admits, as the waitlist's does. All three outcomes are tested. Note for the privacy page (owner's text): this counts the visitor's address, as a key that expires a minute later, a shorter retention than the day the waitlist buckets keep.
  • lib/analytics.ts: the scrubbed event is built from named fields only (A3), so a top-level $set or $set_once cannot pass; disable_external_dependency_loading: true (A7), so the library loads no script from anywhere.
  • proxy.ts: /ingest is left out of the policy matcher on purpose (no gate on this site, nothing to redirect). The policy itself is unchanged: connect-src 'self'.
  • next.config.ts: skipTrailingSlashRedirect: true, because PostHog's paths end in / and a redirected POST loses its body. It also stops Next adding or removing a trailing slash on pages; /privacy and /privacy/ both answer 200 on a local production build.
  • WaitlistForm sends the outcome from the result's status. lib/waitlist.ts gains an optional limited: true on the two limit refusals so rate_limited can be told from error without reading a message.
  • .env.example names NEXT_PUBLIC_POSTHOG_KEY.
  • New dev dependency happy-dom (exact), for the storage test.

Things to know

  • already is in the type and nothing sends it: the reply never says whether an address was already on the list (lib/waitlist.ts), so the browser cannot know. Left unreachable on purpose, to keep the list the baseline named.
  • Only one variable is used. The host is not configurable.
  • skipTrailingSlashRedirect: true (A6) means /privacy and /privacy/ now both answer 200 with the same page, instead of one redirecting to the other. The existing canonicals say which counts, and routePattern trims the slash, so counts do not split. Next cannot set it per route.
  • A4 (the body is read before its second size check) is left as is: Vercel's own 4.5 MB request limit bounds it, and the limit above caps how often.

Tests

  • Rule 15a/15b/15c: no input text reaches an event; unknown events and properties are dropped; no open string property (lib/analytics.test.ts).
  • Rule 13 and 15e: no Cookie, Authorization, forwarded-for, referrer or origin goes upstream; no Set-Cookie back; bad paths refused (lib/analytics-proxy.test.ts).
  • Rule 23: with the real library running, no ph_ cookie and no ph_ key in localStorage or sessionStorage; mutation-checked (setting the SDK default persistence makes it fail).
  • Rule 24: with the real library, an address and a spam-check token offered to a capture appear in no request; the permitted event is asserted to have gone out, so an empty log cannot pass (lib/analytics-browser.test.ts).

Checked locally (CI is the gate)

pnpm typecheck, pnpm vitest run (57 tests, 8 files), pnpm lint, pnpm run check and pnpm build on the head commit; GitHub's quick run also passed on the first commit. Earlier, a local next start probed trailing slashes, 405 and path traversal.

New since the security review: lib/analytics-capture.test.ts goes through capture() (the lazy path) with the production configuration and asserts (a) the library's only request is /ingest/e/, (b) nothing is requested from /ingest/static or /ingest/array, (c) an IndexedDB stub is never opened, and no ph_ cookie or storage key appears (A5). The forward tests add: any other path 404 with no upstream and no limiter call, 429 over the limit, 503 when the limiter throws.

Not verified

  • No request has reached PostHog: no key was set and nothing was sent. The remote-config fetch and the real event path through /ingest are untested against PostHog.
  • The /ingest route has not been exercised with a browser.
  • Project-side settings (discard client IP, GeoIP transformation off, recording off) are the owner's, in the PostHog console.

🤖 Generated with Claude Code

steveapo and others added 6 commits November 21, 2026 16:01
…ie and no person

Two events only, page_view (a route pattern) and waitlist_submit (one of five outcomes), through posthog-js 1.453.2 loaded after the page has loaded. Memory persistence, no person profile, no autocapture, recording, survey or flags. The browser reports to this site's own /ingest path, which forwards to the EU cloud with a short list of headers (no Cookie, no Authorization, no address). Off until NEXT_PUBLIC_POSTHOG_KEY is set.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…nd tighten the scrub

A1: the forward relays POST /ingest/e/ only (the one path posthog-js 1.453.2 calls with this configuration, recorded by lib/analytics-capture.test.ts); any other path or method is refused and reaches no upstream, and the assets host is no longer reachable. A2: 120 a minute per client through the existing Upstash limiter; over the limit 429, and when the limiter cannot count (unconfigured in production, or Upstash silent) 503, both with nothing sent upstream. A3: the scrubbed event is built from named fields, so a top-level $set or $set_once cannot pass. A5: the lazy capture() path is tested with the production configuration, and IndexedDB is asserted never opened. A7: disable_external_dependency_loading is set.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The owner-approved wording of reports/texts-for-approval.md, items 1a, 1b and 1c: a Counting visits paragraph after Where you signed up from, and the measurement service among the providers. The cookie paragraph, the basis, the retention paragraph and the date are untouched. lib/privacy-text.test.tsx pins the whole text.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The owner-approved sentence after the legitimate-interest sentence in Why we may hold it, and the right to object now to any of these. The retention paragraph and the date are untouched. The pinning test covers both sentences, the whole paragraph, and the unchanged retention paragraph.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The owner-approved retention sentence, last in How long, and Last updated 21 November 2026. The pinning test covers the whole retention paragraph and the date.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The owner-approved wording of the How long sentence: the rate limit on the analytics path keeps a network address for a minute. The pinning test covers it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@steveapo
steveapo marked this pull request as ready for review November 21, 2026 15:39
@steveapo
steveapo merged commit 7d78684 into main Nov 21, 2026
2 checks passed
@steveapo
steveapo deleted the feat/analytics-counts-only branch November 21, 2026 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant