Skip to content

feat: PostHog analytics for openaffiliate.dev#29

Merged
sonpiaz merged 3 commits into
mainfrom
feat/posthog-analytics
May 26, 2026
Merged

feat: PostHog analytics for openaffiliate.dev#29
sonpiaz merged 3 commits into
mainfrom
feat/posthog-analytics

Conversation

@sonpiaz
Copy link
Copy Markdown
Member

@sonpiaz sonpiaz commented May 25, 2026

What

Wire PostHog (project 439973, separate org for the public OpenAffiliate brand) into the Next.js 16 app, mirroring the analytics patterns already shipped for kyma + affitor.

Changes (3 files + dep)

  • src/instrumentation-client.ts (new) — init posthog-js before React hydration via the Next 16 native client-instrumentation hook. defaults: '2026-01-30' → history-change $pageview + autocapture + web vitals. person_profiles: 'identified_only' (site has no login).
  • next.config.ts — reverse-proxy analytics through /_phus(-assets).i.posthog.com so ad-blockers see a first-party path (kyma pattern feat: P0+P1 infrastructure & distribution layer #1, recovers ~30% of dropped events). skipTrailingSlashRedirect: true.
  • src/lib/track.ts — dual-write existing Supabase events into PostHog (skips page_view; posthog captures $pageview). Powers search → program_view → outbound_click funnels + session-replay correlation without disturbing the Supabase analytics layer (top_search_gaps, daily_metrics).

Config

  • NEXT_PUBLIC_POSTHOG_KEY (public write-only key) set in Vercel Production only — keeps the fresh project's data clean (no preview/PR traffic).

Verification

  • Turbopack compiles clean (✓ Compiled successfully).
  • The pre-existing /api/* module-level-Supabase local-build quirk (SUPABASE_SERVICE_ROLE_KEY not propagated to Turbopack page-data workers locally) is unchanged — confirmed by building the un-patched tree, which fails identically. Vercel prod build is unaffected (all env present).
  • ⏳ Post-merge: confirm a real $pageview lands in PostHog project 439973.

Not included (follow-ups)

  • PostHog dashboards (Acquisition / Registry funnel) — provision after first real traffic.
  • Server-side capture from /api/events (Supabase route) if we later want backend-truth events.

🤖 Generated with Claude Code

Wire PostHog (project 439973) into the open-affiliate Next.js 16 app,
mirroring the kyma/affitor analytics patterns:

- instrumentation-client.ts: init posthog-js before React hydration
  (Next 16 native hook). defaults '2026-01-30' gives history-change
  $pageview + autocapture + web vitals; person_profiles 'identified_only'
  since the site has no login (keeps us on the free tier).
- next.config.ts: reverse-proxy analytics through /_ph so ad-blockers
  see a first-party path instead of *.posthog.com (recovers ~30% of
  otherwise-dropped events).
- track.ts: dual-write the existing Supabase events into PostHog (skip
  page_view; posthog already captures $pageview) so search ->
  program_view -> outbound_click funnels and session-replay correlation
  work, without disturbing the Supabase analytics layer that powers
  top_search_gaps / daily_metrics.

Key is NEXT_PUBLIC_POSTHOG_KEY (public write-only, set in Vercel
production only to keep the new project's data clean). Turbopack compiles
clean; the pre-existing /api/* module-level-supabase local-build quirk is
unchanged (verified by building the un-patched tree).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 25, 2026

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

Project Deployment Actions Updated (UTC)
open-affiliate Canceled Canceled May 26, 2026 4:32am

Request Review

sonpiaz and others added 2 commits May 25, 2026 21:15
# Conflicts:
#	package-lock.json
#	package.json
cacheComponents:true (next.config) is incompatible with the ISR route
configs (export const revalidate / dynamicParams) added in #33 to cap the
Apify cost leak. This has failed every production deploy on Vercel since
2026-04-21 (confirmed in the deploy build logs: "Route segment config
'dynamicParams'/'revalidate' is not compatible with nextConfig.cacheComponents"),
leaving openaffiliate.dev stuck on a 36-day-old build.

Nothing uses the "use cache" directive, so disabling cacheComponents is
safe and preserves the ISR cost fix. NOTE: this repo is synced from the
open-affiliate-pro SSOT — mirror this change there or the next sync will
re-break the build.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@sonpiaz sonpiaz merged commit bdd6d65 into main May 26, 2026
2 of 4 checks passed
@sonpiaz sonpiaz deleted the feat/posthog-analytics branch May 26, 2026 04:33
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