-
-
Notifications
You must be signed in to change notification settings - Fork 21
Open
Description
Problem
Zero user:logged_in events in the last 30 days. The event is never being fired, which means:
- No visibility into returning user sessions
- DAU metric is blind
- "Signup to first login" funnel returns no data
Root Cause
The frontend check in apps/web/src/features/auth/hooks/useFetchUser.ts (line 53) guards the tracking call behind:
if (accessToken || refreshToken) {
trackEvent(ANALYTICS_EVENTS.USER_LOGGED_IN, { ... });
}But the backend OAuth callback (/workos/callback in apps/api/app/api/v1/endpoints/oauth.py) redirects to /redirect with only an HttpOnly cookie set β it never passes access_token or refresh_token as URL query params. The condition is always false, so the event never fires.
Additionally, returning users who auto-login via the wos_session cookie have zero analytics visibility.
Proposed Fix
1. Backend: Track user:logged_in server-side in OAuth callback
- Add
USER_LOGGED_IN = "user:logged_in"toAnalyticsEventsinapps/api/app/services/analytics_service.py - Add a
track_login()helper (mirrors existingtrack_signup()pattern) - In
apps/api/app/services/oauth/oauth_service.py, modifystore_user_info()to return(user_id, is_new_user)β calltrack_login()in the existing-user branch
2. Frontend: Add session resumption tracking
- Remove the dead
accessToken/refreshTokenlogin tracking code fromuseFetchUser.ts - Add a
user:session_resumedevent usingsessionStorageβ fires once per browser session when a returning user is auto-authenticated via cookie - Add
USER_SESSION_RESUMEDtoANALYTICS_EVENTSinapps/web/src/lib/analytics.ts
Resulting Event Model
| Scenario | Event | Tracked Where |
|---|---|---|
| New user signs up | user:signed_up |
Backend (already works) |
| Existing user logs in via OAuth | user:logged_in |
Backend (new) |
| Returning user auto-auth via cookie | user:session_resumed |
Frontend (new) |
| User logs out | user:logged_out |
Frontend (already works) |
Key Files
apps/api/app/api/v1/endpoints/oauth.pyβ OAuth callbackapps/api/app/services/oauth/oauth_service.pyβstore_user_info()apps/api/app/services/analytics_service.pyβ PostHog tracking helpersapps/web/src/features/auth/hooks/useFetchUser.tsβ frontend auth hookapps/web/src/lib/analytics.tsβ frontend analytics events
Created by Claude
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels