Add PostHog analytics integration - #14
Draft
posthog[bot] wants to merge 1 commit into
Draft
Conversation
Generated-By: PostHog Code Task-Id: 7fcf2c2a-a820-4058-94ff-10572bf4fd88
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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
This PR adds PostHog product analytics to Which AI Made This? using the
posthog-jsSDK (installed via npm). PostHog is initialized viainstrumentation-client.ts— the recommended approach for Next.js 15.3+ — and a reverse proxy is configured innext.config.tsto route capture requests through/ingest, which avoids ad-blocker interference. Twelve custom events are captured across four client components covering the game, compare, gallery, and theme features.Files changed by the setup wizard:
instrumentation-client.ts— new PostHog client initializationnext.config.ts— adds/ingestreverse-proxy rewrites tous.i.posthog.com/us-assets.i.posthog.comsrc/components/game/model-lab-wordle.tsx— game events:game_started,guess_submitted,game_completed,game_replayed,score_shared,score_image_sharedsrc/components/compare/compare-page.tsx— compare events:compare_selection_changed,compare_sides_swapped,compare_link_copied,compare_iteration_changedsrc/components/gallery/gallery-iteration-view.tsx+src/components/gallery/gallery-iteration-view-tracker.tsx—iteration_viewedvia a client-component wrappersrc/components/gallery/gallery-theme-toggle.tsx—theme_toggledpackage.json/package-lock.json— addsposthog-js@^1.404.1.gitignore— ignores.env.localInsights and dashboards created
How to verify
npm run dev).$pageview,game_started, andtheme_toggledarriving within a minute.Environment variables (action needed before PostHog works)
This app is a Next.js site deployed (based on its setup) on a hosting provider that keeps its settings in its dashboard rather than in a file committed to this repository, so I could not set these up automatically. No environment file is read in production, so they must be configured in the hosting dashboard.
Environment variables are named settings your hosting provider passes to the app when it runs — they let the app know things (like the PostHog token below) without hardcoding them into the code. PostHog will not receive any data until these two are set:
NEXT_PUBLIC_POSTHOG_PROJECT_TOKENphc_r7HtYgdoT5Lb9FSdsLXXXjiLFkChDYpcTQPRYBxHmHdoNEXT_PUBLIC_POSTHOG_HOSThttps://us.i.posthog.comSetting them via the hosting dashboard
If the site is on Vercel (the default for Next.js):
Setting environment variables via a local CLI
You can run these commands locally instead of using the dashboard. The value is piped in on stdin, and
productionis the target environment (adjustpreview/developmentas needed). Double-check the exact CLI syntax for your provider.For Vercel:
After setting them, redeploy so the new values take effect.
Created with PostHog Code