Skip to content

[DATA-8187] fix(analytics): avoid redundant browser identity and flag calls - #6731

Merged
pedroheyerdahl merged 2 commits into
mainfrom
codex/posthog-identify-dedup
Sep 28, 2026
Merged

pedroheyerdahl merged 2 commits into
mainfrom
codex/posthog-identify-dedup

Conversation

@pedroheyerdahl

@pedroheyerdahl pedroheyerdahl commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

When NextAuth refreshes a login session, it can create a new session object even though the user has not changed. The PostHog effect depends on that object, so it repeats identification and feature-flag requests.

Make the effect depend on the user's email, name and login status instead. Remove the separate alias and reloadFeatureFlags calls because identify already links the anonymous user and refreshes flags when the identity changes. This behavior was checked in the installed posthog-js version, 1.360.2.

Verification

Checked on September 25 at 57575371:

  • Started the local development stack and tested login, profile loading, page refresh and logout in Chrome.
  • A temporary panel counted actual PostHog SDK calls while triggering NextAuth's background session refresh three times. All three responses contained the same authenticated user. No additional identify, alias or flag-reload calls occurred. The panel was removed afterward. Development mode disables event capture, so delivery to PostHog was not tested.
  • Web typecheck, lint, formatting and git diff --check passed.
  • Full web suite: 17,758 passed, 3 skipped, 1 failed. A test for concurrent pending uploads exceeded its 5-second timeout. All 10 tests in that suite passed when rerun alone with the same timeout. The full run was not entirely passing.
  • Local-development tests: 399 passed, 1 skipped. Environment-variable checks: 17 passed. Mobile-artifact checks: 8 passed.

Local verification screenshots

The temporary panel on the running local app shows the counts before and after three session refreshes: identify 1 → 1, alias 0 → 0, flag reload 1 → 1.

Chrome: three session refreshes with no additional identity or flag calls

Reviewer Notes

The profile's auto-routing settings failed to load in the local environment. The login and session checks above completed.

@pedroheyerdahl
pedroheyerdahl marked this pull request as ready for review September 25, 2026 18:38
@kilo-code-bot

kilo-code-bot Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Executive Summary

Reviewed the single changed file (PostHogProvider.tsx), and the dependency narrowing plus removal of the redundant alias/reloadFeatureFlags calls is consistent with the pinned posthog-js identify behavior; no high-confidence defects found in the changed lines.

Files Reviewed (1 file)
  • apps/web/src/components/PostHogProvider.tsx

Reviewed by deepseek-v4.1-flash · Input: 0 · Output: 0 · Cached: 0

Review guidance: REVIEW.md from base branch main

@pedroheyerdahl
pedroheyerdahl merged commit e158953 into main Sep 28, 2026
26 checks passed
@pedroheyerdahl
pedroheyerdahl deleted the codex/posthog-identify-dedup branch September 28, 2026 12:41
@pedroheyerdahl pedroheyerdahl changed the title fix(analytics): avoid redundant browser identity and flag calls [DATA-8187] fix(analytics): avoid redundant browser identity and flag calls Sep 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants