feat(analytics): add run_id to every event and $session_id after login#661
Open
gewenyu99 wants to merge 2 commits into
Open
feat(analytics): add run_id to every event and $session_id after login#661gewenyu99 wants to merge 2 commits into
gewenyu99 wants to merge 2 commits into
Conversation
Wizard analytics events had no per-run correlation id. Before login the distinct id is a fresh anonymous uuid (unique per run), but OAuth switches the distinct id to the real user id, which is shared across all that user's runs — so two runs by the same person could not be separated. Add two identifiers, both riding on every capture/exception via the existing tag bag: - `run_id`: a per-process uuid minted in the constructor. Always present, so any two runs (even by the same logged-in user) are now distinguishable. - `$session_id`: null until OAuth completes. Set lazily on first `identifyUser`, so pre-login events carry only `run_id` and post-login events also collapse into a native PostHog Session. The two are independent uuids and will essentially never match; the test mock now returns distinct values to reflect that. Analytics-only change — no OAuth or backend plumbing touched. Generated-By: PostHog Code Task-Id: b28e6f20-7e1b-48cc-9403-d634921836e3
🧙 Wizard CIRun the Wizard CI and test your changes against wizard-workbench example apps by replying with a GitHub comment using one of the following commands: Test all apps:
Test all apps in a directory:
Test an individual app:
Show more apps
Results will be posted here when complete. |
Production builds previously carried no `build` tag at all — it was only set to 'dev' for non-prod builds, then upgraded to 'ci' in CI runs. So prod runs were indistinguishable from untagged data. Always set `build` from IS_PRODUCTION_BUILD: 'prod' for published builds, 'dev' otherwise. CI runs continue to upgrade it to 'ci' in runWizardCI, so all three run types now segment cleanly. Adds a `build tag` test block that flips IS_PRODUCTION_BUILD via a mocked @env getter to cover both the prod and dev paths. Generated-By: PostHog Code Task-Id: b28e6f20-7e1b-48cc-9403-d634921836e3
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.
Problem
Wizard analytics events had no per-run correlation id. Before login the distinct id is a fresh anonymous uuid (unique per run), but OAuth switches the distinct id to the real user id, which is shared across all of that user's runs. So two runs by the same person could not be separated, and there was no way to funnel/group the events of a single run.
Separately, production runs carried no
buildtag at all — it was only set for non-prod builds — so prod runs were indistinguishable from untagged data.Change
All analytics-only — no OAuth or backend plumbing touched. Identifiers ride on every
capture,captureException, and autocaptured exception via the existingthis.tagsbag.Per-run correlation
run_id— a per-process uuid minted in theAnalyticsconstructor. Always present, so any two runs (even by the same logged-in user) are distinguishable and filterable.$session_id—nulluntil OAuth completes. Set lazily on firstidentifyUser(), so pre-login events carry onlyrun_id; once authenticated, every event also carries$session_idand PostHog groups the run into a native Session. The two are independent uuids and will essentially never be equal.setup wizard finishedshutdown event hoistsrun_id(always) and$session_id(when a session was opened) out of the nestedtagsso the terminal event is filterable/groupable like every other capture.Build-type tagging
buildis now always set:'prod'for published builds (IS_PRODUCTION_BUILD),'dev'otherwise. CI runs continue to upgrade it to'ci'inrunWizardCI, so prod / dev / ci segment cleanly. Previously prod runs were untagged.Testing
pnpm build✅pnpm test— 896 passed ✅ (incl. new run/session-id and build-tag tests; uuid mock now returns distinct values sorun_id !== $session_idis reflected)pnpm lint✅ (exit 0; only pre-existing project-wide warnings)