feat(mobile): enable PostHog error tracking and user identification#2421
Merged
Conversation
Turn on uncaught-exception and unhandled-rejection autocapture so JS crashes surface in Error Tracking, and identify the signed-in user (uuid as distinct id, email/name/staff props + organization group) so events and session replays are attributed to a person. Resets on logout to keep sessions from bleeding across accounts.
Contributor
Prompt To Fix All With AIFix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
apps/mobile/src/lib/posthog.ts:79-93
**Stale user properties and missing group after initial identification**
The `identifiedUuid.current === user.uuid` guard correctly prevents spamming `posthog.identify()` on every render, but it also means that any mid-session property changes — a user gaining staff access, updating their email, or being assigned to an organization for the first time — are never forwarded to PostHog until the user logs out and back in. The `posthog.group()` call is particularly affected: if `user.organization` is `null` at identification time and the user joins an org later in the same session, the group association is never sent.
Reviews (1): Last reviewed commit: "feat(mobile): enable PostHog error track..." | Re-trigger Greptile |
Dedup on a signature of the full identify payload (email, name, staff, organization) instead of just the uuid, so mid-session property and group updates are forwarded to PostHog rather than being suppressed until the next login.
…king-identify # Conflicts: # apps/mobile/src/app/_layout.tsx
posthog.ts now imports the auth store and user query directly from source instead of the feature barrel, and posthog.test.ts mocks those two modules so the app-version tests don't transitively load native expo modules (expo-secure-store, expo-auth-session) that can't run in the node test environment.
New commits pushed (delta classified non_trivial_delta) — stamphog approval dismissed; re-review running automatically.
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
The mobile app captured screen views, touches, and session replays, but two gaps meant that data was hard to act on:
Changes
src/lib/posthog.ts): added anerrorTracking.autocaptureconfig toPOSTHOG_OPTIONSenablinguncaughtExceptionsandunhandledRejections.src/lib/posthog.ts): newuseIdentifyUser()hook that identifies the signed-in user (uuid as distinct id, withemail/name/is_staffproperties and anorganizationgroup) once their profile loads, and callsposthog.reset()on logout so sessions don't bleed across accounts.useIdentifyUser()intoRootLayoutNavinsrc/app/_layout.tsxalongside the existinguseScreenTracking().How did you test this?
tsc --noEmit— no new type errors introduced by the changed files.biome checkon both changed files — clean.errorTrackingandidentify/reset/groupAPIs against the installedposthog-react-nativev4.18.0 type definitions.Not manually exercised on a device/simulator.
Publish to changelog?
no