feat(analytics): GPC-gated PostHog with pageviews + waitlist events#42
Merged
Conversation
Adds PostHog product analytics to being.fyi as the first analytics ever
on the site. Output of a 5-step agent review sequence (compliance →
product → architect → product priority → compliance) — see plan file.
Compliance gave conditional sign-off pending three items (all
addressed: upstream PR, Notion disclosure, /privacy/multi-state link).
# Scope (Tier B-trimmed)
Three events only:
- $pageview (PostHog default)
- waitlist_signup_submitted { source }
- waitlist_signup_failed { source, reason }
No autocapture. No session replay. No heatmaps. No surveys. No email
hash identify (deferred to PR #2). EU data residency (Frankfurt).
# GPC structural kill
AnalyticsGate (client component, useSyncExternalStore) returns null when
ANY of:
- being_gpc=1 cookie set by middleware on Sec-GPC: 1
- navigator.globalPrivacyControl === true (browsers exposing the JS API
without the HTTP header, e.g. older Brave)
- NEXT_PUBLIC_POSTHOG_KEY missing (local dev)
- SSR (getServerSnapshot=true, safe default)
Null → PosthogProvider never mounts → dynamic import('posthog-js') never
fires → posthog-js chunk never fetched → no init, no ph_* cookie, no
beacon. Structurally enforced; not "suppressed after load."
Diverged from architect's server-component design because cookies() in
next/headers would force the parent layout into dynamic rendering,
undoing force-static on legal pages and re-introducing the per-request
marked() parse that PR #33 fixed. Client-side gate preserves both
force-static AND the no-load guarantee. Confirmed by compliance
re-review.
# CI structural-regression gate
tests/analytics-gpc-gate.test.tsx test #6 is a grep gate: if any file
under app/, components/, lib/ statically imports posthog-js (outside
PosthogProvider.tsx's dynamic import), the build fails. This is the
regression vector that would bypass the gate; locking it in CI.
# CSP additions
- script-src += eu-assets.i.posthog.com
- connect-src += eu.i.posthog.com eu-assets.i.posthog.com
- img-src += eu.i.posthog.com (PostHog pixel fallback)
- worker-src 'self' blob: (PostHog web worker for batching)
# /cookies page rewrite
- Removed "No PostHog" denial (was false the moment this PR ships)
- Headline: "Two Functional Cookies + Privacy-Respecting Analytics"
- New ph_* cookie disclosure with EU residency, kill conditions, scope
- "What We Don't Use" updated: no GA/Mixpanel/Amplitude/Segment, no
autocapture, no session replay (explicit even for PostHog)
- GPC section: structurally enforced kill described accurately
# Hard dependency
This PR depends on MP2EZ/being#106 landing first (privacy policy §5.2
split into in-app vs web subsections + Notion added to §5.1 service
providers). CI sync pulls from being@development; until #106 merges,
the website ships analytics with a stale policy = FTC §5 issue.
# Out of scope (PR #2+)
- cta_clicked, crisis_resource_clicked, ab_variant_assigned events
- Email-hash identify (server-side SHA-256 + identifyByEmailHash helper)
- PostHog feature flags / experiments (we have being_ab_variant)
- Session replay / heatmaps / surveys (categorically off)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Tags every PostHog event from the marketing site with surface: 'web' so
the website's data stays distinguishable from the being-app's data in
the shared PostHog project (free tier = 1 project per account; sharing
is the right call pre-launch and a deliberate design choice).
The app mirrors this with posthog.register({ surface: 'app' }) in a
parallel change to ~/dev/being's PostHogProvider.
Co-Authored-By: Claude Opus 4.7 (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.
Summary
Adds PostHog product analytics to being.fyi — the first analytics ever on the site. Tight scope, structurally GPC-gated, EU data residency. Output of a 5-agent review sequence (compliance → product → architect → product priority → compliance).
What ships
Events (3 total):
Explicitly excluded: autocapture, session replay, heatmaps, surveys, email-hash identify (PR #2), cta_clicked / crisis_resource_clicked / ab_variant_assigned (PR #2+).
GPC structural kill
`AnalyticsGate` (client component, `useSyncExternalStore`) returns `null` when ANY of:
Null → `PosthogProvider` never mounts → dynamic `import('posthog-js')` never fires → posthog-js chunk never fetched → no init, no `ph_*` cookie, no beacon. Not "suppressed after load" — structurally never loads.
Why client-side, not server-side (deliberate divergence from architect's design)
The architect designed `AnalyticsGate` as a server component using `cookies()` from `next/headers`. I implemented client-side because the server-side approach would force the parent layout into dynamic rendering, undoing `force-static` on legal pages and re-introducing the per-request `marked()` parse PR #33 fixed.
Verified:
CI structural-regression gate
`tests/analytics-gpc-gate.test.tsx` test #6 is a grep gate: if any file under `app/`, `components/`, `lib/` statically imports `posthog-js` outside `PosthogProvider.tsx`'s dynamic import, the build fails. This is the regression vector that would bypass the gate by getting posthog-js into the page bundle. Locked in CI.
CSP additions
```
script-src += eu-assets.i.posthog.com
connect-src += eu.i.posthog.com eu-assets.i.posthog.com
img-src += eu.i.posthog.com (PostHog pixel fallback)
worker-src 'self' blob: (PostHog web worker for batching, even with replay off)
```
/cookies page rewrite
Hard dependencies — DO NOT MERGE until satisfied
If items 2 or 3 are unsatisfied, the PR can still merge — `isPosthogConfigured()` will return false, AnalyticsGate renders null, no errors, no broken pages. Set them when ready.
Verification
Manual launch-day verification (after PR + upstream both merged + secret set)
Out of scope (PR #2+)
🤖 Generated with Claude Code