Skip to content

feat(mobile): enable PostHog error tracking and user identification#2421

Merged
Gilbert09 merged 4 commits into
mainfrom
tom/mobile-error-tracking-identify
May 28, 2026
Merged

feat(mobile): enable PostHog error tracking and user identification#2421
Gilbert09 merged 4 commits into
mainfrom
tom/mobile-error-tracking-identify

Conversation

@Gilbert09
Copy link
Copy Markdown
Member

Problem

The mobile app captured screen views, touches, and session replays, but two gaps meant that data was hard to act on:

  • No error tracking — uncaught JS exceptions and unhandled promise rejections were never sent to PostHog, so crashes were invisible in Error Tracking.
  • No user identification — every event and session replay was anonymous, so we couldn't attribute behaviour to a person, org, or staff/non-staff.

Changes

  • Error tracking (src/lib/posthog.ts): added an errorTracking.autocapture config to POSTHOG_OPTIONS enabling uncaughtExceptions and unhandledRejections.
  • User identification (src/lib/posthog.ts): new useIdentifyUser() hook that identifies the signed-in user (uuid as distinct id, with email / name / is_staff properties and an organization group) once their profile loads, and calls posthog.reset() on logout so sessions don't bleed across accounts.
  • Wired useIdentifyUser() into RootLayoutNav in src/app/_layout.tsx alongside the existing useScreenTracking().

How did you test this?

  • tsc --noEmit — no new type errors introduced by the changed files.
  • biome check on both changed files — clean.
  • Verified the errorTracking and identify/reset/group APIs against the installed posthog-react-native v4.18.0 type definitions.

Not manually exercised on a device/simulator.

Publish to changelog?

no

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.
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 28, 2026

Prompt To Fix All With AI
Fix 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

Comment thread apps/mobile/src/lib/posthog.ts Outdated
Gilbert09 added 2 commits May 28, 2026 21:48
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
@Gilbert09 Gilbert09 added the Stamphog This will request an autostamp by stamphog on small changes label May 28, 2026
github-actions[bot]
github-actions Bot previously approved these changes May 28, 2026
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No showstoppers. The hook is well-guarded, the stale-identity concern raised by the bot was addressed in the current diff (JSON signature over the full payload), and error tracking config is a safe additive option.

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.
@github-actions github-actions Bot dismissed their stale review May 28, 2026 21:04

New commits pushed (delta classified non_trivial_delta) — stamphog approval dismissed; re-review running automatically.

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additive mobile analytics change with no showstoppers. The hook is well-guarded, the stale-identity concern raised in review was addressed in the current diff via JSON signature over the full payload, and error tracking config is a safe opt-in option.

@Gilbert09 Gilbert09 merged commit a70b77a into main May 28, 2026
17 checks passed
@Gilbert09 Gilbert09 deleted the tom/mobile-error-tracking-identify branch May 28, 2026 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Stamphog This will request an autostamp by stamphog on small changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant