Skip to content

Integrate PostHog across the Next.js website and calculator#920

Draft
anth-volk wants to merge 5 commits intomainfrom
feat/posthog-pathways
Draft

Integrate PostHog across the Next.js website and calculator#920
anth-volk wants to merge 5 commits intomainfrom
feat/posthog-pathways

Conversation

@anth-volk
Copy link
Copy Markdown
Collaborator

Fixes #919

Summary

This branch integrates PostHog into the new Next.js website and calculator-app surfaces and adds the shared calculator analytics layer those apps consume from app/src.

At a high level, it:

  • bootstraps PostHog in both Next apps using Next.js integration points
  • adds typed calculator analytics helpers, event schemas, and snapshot builders
  • instruments key calculator flows across report building, household creation, calculations, and report output
  • instruments key website interactions such as entering the calculator, newsletter signup, research interactions, and country switching
  • adds stronger client, boundary, and server-side error capture
  • proxies PostHog traffic through the Next apps instead of sending browser traffic directly to PostHog ingestion hosts
  • adds release-aware env/config scaffolding and pins the repo to the supported Node version via .nvmrc / .node-version

Included

Next app bootstrap and monitoring

  • website/instrumentation-client.ts
  • website/instrumentation.ts
  • website/src/app/error.tsx
  • website/src/app/global-error.tsx
  • website/src/lib/posthog-server.ts
  • website/src/lib/posthogProxy.ts
  • calculator-app/instrumentation-client.ts
  • calculator-app/instrumentation.ts
  • calculator-app/src/app/error.tsx
  • calculator-app/src/app/[countryId]/error.tsx
  • calculator-app/src/app/global-error.tsx
  • calculator-app/src/lib/posthog-server.ts
  • calculator-app/src/lib/posthogProxy.ts

Shared calculator analytics

  • typed event payloads in app/src/utils/analyticsSchemas.ts
  • snapshot builders in app/src/utils/analyticsSnapshots.ts
  • shared capture helpers in app/src/utils/analytics.ts
  • shared browser/client access in app/src/utils/posthogClient.ts
  • shared error helpers in app/src/utils/errorTracking.ts

Calculator instrumentation

  • report builder opened / started / created
  • report-builder year, policy, and population selection events
  • household builder opened / variable add-remove / save
  • calculation started / completed / failed
  • report output viewed / subpage viewed
  • output actions like chart export and Python reproduction copy

Website instrumentation

  • enter-calculator CTA
  • newsletter signup started / succeeded / failed
  • research article viewed
  • research filters changed
  • country switched

Validation

  • app: bun run typecheck
  • website: bun run typecheck and bun run build
  • calculator-app: bun run typecheck and bun run build

These were validated under nvm use with the repo pinned to Node 24.

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 6, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
policyengine-app-v2 Building Building Preview Apr 6, 2026 2:52pm
policyengine-calculator Ready Ready Preview, Comment Apr 6, 2026 2:52pm
policyengine-calculator-next Error Error Apr 6, 2026 2:52pm
policyengine-website Ready Ready Preview, Comment Apr 6, 2026 2:52pm

Request Review

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.

Integrate PostHog analytics and monitoring across Next apps

1 participant