feat: add PostHog name properties to identify call#2857
Conversation
Exposes firstName, lastName, and fullName from the Keycloak userinfo response on /v1/auth/session and forwards them as PostHog person properties (first_name, last_name, name) on identify, alongside email. Empty/undefined values are skipped so no "undefined undefined" leaks into PostHog. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.
Tip: disable this comment in your organization's Code Review settings.
WalkthroughUser name fields (firstName, lastName, fullName) from Keycloak are added to the ChangesUser Identity Enrichment in Analytics
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 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
Warning Review ran into problems🔥 ProblemsTimed out fetching pipeline failures after 30000ms Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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 |
Codecov Report❌ Patch coverage is ❌ Your patch check has failed because the patch coverage (0.00%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #2857 +/- ##
===========================================
- Coverage 65.01% 33.23% -31.78%
===========================================
Files 573 632 +59
Lines 71938 89149 +17211
Branches 4862 5313 +451
===========================================
- Hits 46767 29627 -17140
- Misses 23724 59193 +35469
+ Partials 1447 329 -1118
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
studio/src/lib/track.ts (1)
60-67: Consider existing user data consistency.Users who were already identified with email as their distinct_id (before this PR) will hit this branch and won't receive the new name person properties until their session resets. This appears intentional to avoid redundant
identifycalls, but means existing users won't immediately benefit from the enhanced tracking data.You may want to document this behavior or consider whether a one-time re-identification would be valuable for data completeness in PostHog.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@studio/src/lib/track.ts` around lines 60 - 67, The branch that checks distinctId === email only syncs the organization via posthog.group('cosmo_organization', organizationId, {...}) and therefore leaves person properties (like name) out of sync for already-identified sessions; to fix, in that branch also update the PostHog person properties for the current user (e.g., call posthog.identify(email, { name: <userName> }) or posthog.people.set({ name: <userName> })) using the existing symbols (distinctId, email, organizationId, organizationName, organizationSlug, plan) so existing sessions immediately receive the new name/person properties, or alternatively add a short code comment documenting that existing sessions won’t be re-identified if you prefer to keep the current behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@studio/src/lib/track.ts`:
- Around line 60-67: The branch that checks distinctId === email only syncs the
organization via posthog.group('cosmo_organization', organizationId, {...}) and
therefore leaves person properties (like name) out of sync for
already-identified sessions; to fix, in that branch also update the PostHog
person properties for the current user (e.g., call posthog.identify(email, {
name: <userName> }) or posthog.people.set({ name: <userName> })) using the
existing symbols (distinctId, email, organizationId, organizationName,
organizationSlug, plan) so existing sessions immediately receive the new
name/person properties, or alternatively add a short code comment documenting
that existing sessions won’t be re-identified if you prefer to keep the current
behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 57df11c0-25fe-4b6c-913d-f28ee031238f
📒 Files selected for processing (3)
controlplane/src/core/controllers/auth.tsstudio/src/components/app-provider.tsxstudio/src/lib/track.ts
Adds available user name fields to the session response and passes them as PostHog person properties during identify.
Changes:
🤖 Generated with Claude Code
Summary by CodeRabbit