Repository navigation
feat(analytics): count page views and waitlist outcomes, no cookie, no person - #53
Merged
Merged
Conversation
…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>
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.
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,/confirmedorother) andwaitlist_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 andposthog-jsis never fetched.Privacy text. The owner-approved wording of
reports/texts-for-approval.md(items 1a, 1b, 1c), taken character for character, is inapp/(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/ingestkeeps 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.tsxpins 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),scrubas thebefore_sendallowlist, everyposthog-jsoption written out (persistence: 'memory',person_profiles: 'never',defaults: '2026-08-30'), lazyimport('posthog-js')after the windowloadevent.posthog-jsis pinned at 1.453.2; each option name was checked by the type checker against the installed package.lib/analytics-proxy.tsandapp/ingest/[...path]/route.ts: a same-origin forward to PostHog's EU cloud (fixed in code, no host variable). It relaysPOST /ingest/e/and nothing else (A1): that is the only pathposthog-js1.453.2 calls with this configuration, aslib/analytics-capture.test.tsrecords 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 noCookie,Authorization, forwarded-for or referrer; it passes back noSet-Cookie; bodies over 256 KB are refused; a PostHog outage answers 502 and is invisible to the page.lib/rate-limit.ts, a newingestbucket). 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$setor$set_oncecannot pass;disable_external_dependency_loading: true(A7), so the library loads no script from anywhere.proxy.ts:/ingestis 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;/privacyand/privacy/both answer 200 on a local production build.WaitlistFormsends the outcome from the result's status.lib/waitlist.tsgains an optionallimited: trueon the two limit refusals sorate_limitedcan be told fromerrorwithout reading a message..env.examplenamesNEXT_PUBLIC_POSTHOG_KEY.happy-dom(exact), for the storage test.Things to know
alreadyis 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.skipTrailingSlashRedirect: true(A6) means/privacyand/privacy/now both answer 200 with the same page, instead of one redirecting to the other. The existing canonicals say which counts, androutePatterntrims the slash, so counts do not split. Next cannot set it per route.Tests
stringproperty (lib/analytics.test.ts).Cookie,Authorization, forwarded-for, referrer or origin goes upstream; noSet-Cookieback; bad paths refused (lib/analytics-proxy.test.ts).ph_cookie and noph_key in localStorage or sessionStorage; mutation-checked (setting the SDK default persistence makes it fail).lib/analytics-browser.test.ts).Checked locally (CI is the gate)
pnpm typecheck,pnpm vitest run(57 tests, 8 files),pnpm lint,pnpm run checkandpnpm buildon the head commit; GitHub's quick run also passed on the first commit. Earlier, a localnext startprobed trailing slashes, 405 and path traversal.New since the security review:
lib/analytics-capture.test.tsgoes throughcapture()(the lazy path) with the production configuration and asserts (a) the library's only request is/ingest/e/, (b) nothing is requested from/ingest/staticor/ingest/array, (c) an IndexedDB stub is never opened, and noph_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
/ingestare untested against PostHog./ingestroute has not been exercised with a browser.🤖 Generated with Claude Code