feat(analytics): attach app version to all custom events#2372
Merged
Conversation
Contributor
Prompt To Fix All With AIFix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
apps/code/src/main/services/posthog-analytics.ts:48-53
`app_version` is placed before `...properties`, so a caller that accidentally or intentionally includes an `app_version` key in the properties bag will silently overwrite the value returned by `getAppVersion()`. Given the explicit goal of making this field authoritative on every event, placing it after the spread ensures the system value always wins.
```suggestion
properties: {
team: "posthog-code",
...properties,
app_version: getAppVersion(),
$process_person_profile: !!currentUserId,
},
```
### Issue 2 of 2
apps/code/src/main/services/posthog-analytics.ts:97-101
Same ordering issue in `captureException`: `app_version` is set before the spread, so any `app_version` key inside `additionalProperties` will silently replace the real version in the captured exception data.
```suggestion
posthogClient.captureException(error, distinctId, {
team: "posthog-code",
...additionalProperties,
app_version: getAppVersion(),
});
```
Reviews (1): Last reviewed commit: "feat(analytics): attach app version to a..." | Re-trigger Greptile |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9519c2e583
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Address review feedback on PR #2372: - Move app_version after the properties spread in trackAppEvent and captureException so a caller-supplied app_version can never override the real runtime version. - Re-register team + app_version super properties after posthog.reset() (logout), which otherwise wipes them — events after a logout/login cycle now keep their version tag without an app restart. Adds regression tests for both behaviours.
Open
3 tasks
Member
Author
k11kirky
approved these changes
May 26, 2026
e4d0050 to
250feaa
Compare
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
We send custom events to PostHog from the Code app, but none of them carry the PostHog Code version. That makes it impossible to answer version-related questions from product analytics — e.g. "are users stuck on old versions?" or "did auto-updates stop landing?" (see the auto-update reports in Slack). The version was only available in OTel logs as
service.version, not on events.Changes
Attach the app version (
getAppVersion()/POSTHOG_CODE_VERSION, sourced fromapp.getVersion()) to every custom event:posthog-analytics.ts): mergeapp_versioninto the properties of everytrackAppEvent(...)capture and everycaptureException(...).registerAppVersion(version)that registersapp_versionas a PostHog super property (so it rides along on all subsequent events, including exceptions).App.tsxfetches the version via the existingos.getAppVersiontRPC query at startup and registers it.Kept
analytics.tsfree of anytrpcClientimport (the fetch lives inApp.tsx) to avoid a module-load-time tRPC/ipcLink dependency that would otherwise break renderer unit tests.No UI changes.
How did you test this?
posthog-analytics.test.ts(main): assertsapp_versionis on tracked events, on captured exceptions, and coexists with caller-supplied props.analytics.test.ts(renderer):registerAppVersionregisters the super property after init and no-ops before init.pnpm --filter code test→ 1516 passed.npx biome checkandtsc -p tsconfig.web.jsonclean on touched files; pre-commit typecheck hook passed.Publish to changelog?
no