Skip to content

Implement application-wide PostHog user identification #9

@coderabbitai

Description

@coderabbitai

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:

  1. 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
  2. Server-side approach: Implement user identification in middleware or a root server component that:

    • Runs after authentication is confirmed
    • Ensures identification happens before rendering
  3. 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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions