fix(web): send anonymous PostHog events as personless#1367
Conversation
Unauthenticated server-side captures previously shipped with an empty distinctId, so PostHog treated each request as a brand-new person — inflating person counts and billing. Resolve identity by mirroring the client's `identified_only` contract: read `$user_state` from the PostHog cookie, fall back to the authenticated user id, and otherwise key the event to the install id with `$process_person_profile: false`. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
Walkthrough
ChangesPostHog Personless Event Handling
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Problem
In
posthog.ts, unauthenticated server-side captures shipped with an emptydistinctId. PostHog treated each such request as a new person, inflating person counts and billing.Fix
tryGetPostHogDistinctIdnow resolves identity by mirroring the client'sidentified_onlycontract:distinct_id; identified iff$user_state === 'identified'.Non-identified events are sent personless (
$process_person_profile: false), so logged-out visitors and anonymous API calls no longer create a person profile per request. Identified users are unchanged.🤖 Generated with Claude Code
Summary by CodeRabbit