feat: add PostHog analytics integration - #45
Draft
posthog[bot] wants to merge 1 commit into
Draft
Conversation
Generated-By: PostHog Code Task-Id: 07400ff5-cd8a-40f0-8c44-58ebc3b076b0
|
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 analytics to Hypersnap.org using the
posthog-jsSDK, installed via npm and initialized through Next.js's client instrumentation hook.instrumentation-client.ts(new) - initializes the PostHog client (posthog.init) withcapture_exceptions: truefor automatic error capture, guarded so nothing runs if the required env vars are unsetsrc/components/copy-command.tsx- captures acommand_copiedevent when a visitor copies an install commandsrc/components/node-info-checker.tsx- captures anode_info_analyzedevent when a visitor runs the node info checker tool.env.example- documents the two new PostHog env varspackage.json/package-lock.json- addsposthog-js@^1.410.6No user-identification flow was wired up: the wizard inspected the app and found no authenticated user/session state to attach identity to, since this is an anonymous, static portal. All events are anonymous.
Insights and dashboards created
How to verify
.env, or in Vercel for production) and runnpm run dev.$pageview,command_copied, andnode_info_analyzedevents arriving within a minute.Environment variables (action needed before PostHog works)
This app deploys to Vercel (see
README.md), which keeps environment variables in the Vercel dashboard rather than in a file committed to this repository, so they could not be set up automatically as part of this PR.Environment variables are named settings your hosting provider passes to the app when it runs — they let the app know configuration values (like the PostHog project token below) without hardcoding them in the source code. PostHog will not receive any data in production until both of these are set:
NEXT_PUBLIC_POSTHOG_PROJECT_TOKENphc_kBAAn9krNLUuCAudS9aZQJtwGuFXzqNXDAynEwVnLWeBNEXT_PUBLIC_POSTHOG_HOSThttps://us.i.posthog.comTo set them via the Vercel dashboard:
Setting environment variables via a local CLI
Alternatively, run these locally (requires the Vercel CLI to be linked to this project):
Created with PostHog Code