feat: add PostHog analytics integration - #17
Draft
posthog-eu[bot] wants to merge 2 commits into
Draft
Conversation
Generated-By: PostHog Code Task-Id: 51fb10f1-b921-420e-909f-d184ae1d34c5
Generated-By: PostHog Code Task-Id: 51fb10f1-b921-420e-909f-d184ae1d34c5
Author
CI statusThree checks are red on this PR, but all three already fail on
Since these three failures predate this branch and aren't caused by the PostHog changes, I've left them as-is per this task's scope (integration + prod env vars + minimal CI fixes only). |
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 the web viewer (
packages/web, a Vite app) using theposthog-jsSDK.packages/web/src/posthog.ts— new PostHog client initialization, reading the token/host fromVITE_PUBLIC_POSTHOG_KEY/VITE_PUBLIC_POSTHOG_HOST, with browser exception autocapture enabled (capture_unhandled_errors,capture_unhandled_rejections).packages/web/src/main.ts— capturescommand_copiedwhen a copy-command button is used.packages/web/src/viewer/app.js— capturesnote_opened(withopen_mode),note_closed, andsearch_result_openedat the documentation viewer's interaction handlers.packages/web/package.json,pnpm-lock.yaml— adds theposthog-jsdependency.packages/cli/cmd/openknowledge/viewer_assets/viewer.js— regenerated bundled viewer asset reflecting the above (produced by the existingbuild:viewerscript).pnpm-workspace.yaml— minor pnpm build-approval bookkeeping picked up while installing the new dependency.The app is unauthenticated, so no persistent user identification was added — only anonymous, personless event capture.
Insights and dashboards created
How to verify
pnpm dev/pnpm build && pnpm startlocally — the env vars from the section below are already committed).command_copied,note_opened,note_closed, andsearch_result_openedevents arriving within a minute.Environment variables
Production is deployed to Railway as a Docker image (
Dockerfile+railway.json), and the build runspnpm build:web(which invokesvite build) directly inside the Docker build stage viaCOPY . .— Railway dashboard variables are not passed into that build step. Because Vite bakesVITE_*variables in at build time, the required variables were committed directly topackages/web/.env(also mirrored in.env.example) in a separate commit on this branch, so PostHog will start working automatically as soon as this branch is deployed to production. No manual action is needed.VITE_PUBLIC_POSTHOG_KEY— the project API tokenVITE_PUBLIC_POSTHOG_HOST—https://eu.i.posthog.comCreated with PostHog Code