-
Notifications
You must be signed in to change notification settings - Fork 0
Implement application-wide PostHog user identification #9
Description
Description
PostHog user identification is not implemented consistently across the application. Currently, user identification only occurs in specific authentication flows (email/password signup), while other parts of the application do not identify users at all.
Current State
Limited identification in email/password flows only:
In apps/web/app/(auth)/sign-up/page.tsx and apps/web/app/(auth)/sign-in/page.tsx:
// Only happens for email/password auth
posthog.identify(data.email, {
email: data.email,
name: data.name,
});Missing identification in:
- Google OAuth sign-up/sign-in flows
- Application routes after authentication
- User session restoration on page reload
- Profile updates or user data changes
Expected Behavior
PostHog should identify authenticated users consistently across the entire application:
- After any authentication method (email/password, Google OAuth, etc.)
- When the application loads and a session exists
- When user data changes (profile updates)
- Throughout the user journey regardless of entry point
Proposed Solution
Implement a centralized user identification strategy:
-
Client-side approach: Add a useEffect in a root layout component (e.g.,
app/layout.tsx) that:- Checks authentication state on mount
- Calls
posthog.identify()when a user session is detected - Re-identifies on authentication state changes
-
Server-side approach: Implement user identification in middleware or a root server component that:
- Runs after authentication is confirmed
- Ensures identification happens before rendering
-
Event-driven approach: Listen for authentication events and trigger identification automatically
Impact
Without proper user identification:
- User analytics are incomplete and inaccurate
- Cannot track user journeys across sessions
- Event attribution to users is missing
- Product analytics and funnel analysis are unreliable
References
- Related PR: feat: added posthog integration #7
- Discussion: feat: added posthog integration #7 (comment)
- Reported by: @eswaldots