From d683effcb9435ba093beb842200178e2a773dfa8 Mon Sep 17 00:00:00 2001 From: Alex Netsch Date: Mon, 17 Nov 2025 11:58:02 +0000 Subject: [PATCH] Add email event (vibe-kanban) (#1289) * Perfect! I've successfully implemented email analytics tracking for the login flow. Here's what was done: ## Summary Added PostHog user identification with email tracking in the OAuth complete handler at `crates/server/src/routes/oauth.rs:174-185`. ### Implementation Details The code now tracks user email immediately after successful GitHub OAuth login by: 1. Fetching and caching the user profile (which includes email) 2. Sending a `$identify` event to PostHog with the email property 3. Only tracking when analytics is enabled (already auto-enabled during login) ### Code Added ```rust // Track user identification with email for analytics if let Some(profile) = deployment.auth_context().cached_profile().await { if let Some(analytics) = deployment.analytics() { analytics.track_event( deployment.user_id(), "$identify", Some(serde_json::json!({ "email": profile.email, })), ); } } ``` ### Verification - All compilation checks pass - TypeScript type checking passes - Backend cargo check completes successfully The implementation follows existing patterns in the codebase and respects the user's analytics preferences. * Done! I've removed the comment and verified the code still compiles. To answer your question about the format: The email tracking uses the **exact same format** as the `analytics_session_start` event tracking that appears just above it (lines 158-165). Both follow this pattern: ```rust if let Some(analytics) = deployment.analytics() { analytics.track_event( deployment.user_id(), "event_name", Some(serde_json::json!({ /* properties */ })), ); } ``` There was no email tracking in the codebase 3 commits ago, so this is a new addition that follows the established analytics tracking pattern used throughout the codebase. * clippy --- crates/server/src/routes/oauth.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/crates/server/src/routes/oauth.rs b/crates/server/src/routes/oauth.rs index 4c3e36ae..13f89b64 100644 --- a/crates/server/src/routes/oauth.rs +++ b/crates/server/src/routes/oauth.rs @@ -171,6 +171,18 @@ async fn handoff_complete( // Fetch and cache the user's profile let _ = deployment.get_login_status().await; + if let Some(profile) = deployment.auth_context().cached_profile().await + && let Some(analytics) = deployment.analytics() + { + analytics.track_event( + deployment.user_id(), + "$identify", + Some(serde_json::json!({ + "email": profile.email, + })), + ); + } + // Start remote sync if not already running { let handle_guard = deployment.share_sync_handle().lock().await;