feat: PostHog analytics for openaffiliate.dev#29
Merged
Conversation
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>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
# 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>
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.
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) — initposthog-jsbefore 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/_ph→us(-assets).i.posthog.comso 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 (skipspage_view; posthog captures$pageview). Powerssearch → program_view → outbound_clickfunnels + 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
✓ Compiled successfully)./api/*module-level-Supabase local-build quirk (SUPABASE_SERVICE_ROLE_KEYnot 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).$pageviewlands in PostHog project 439973.Not included (follow-ups)
/api/events(Supabase route) if we later want backend-truth events.🤖 Generated with Claude Code