Perfect! The fix is now implemented. Here's what the change does: (#618)
## What the fix accomplishes: 1. **Captures the current state** before updating the config 2. **Detects when analytics is newly enabled** - when it changes from `None` (first-time) or `false` (previously disabled) to `true` 3. **Immediately sends `session_start`** for that current session when analytics is enabled ## Now the flow works correctly: **First-time user:** - App starts (no session_start - analytics not enabled yet) - User sees privacy dialog, clicks "Yes" - Config updated with `analytics_enabled: true` - **session_start event fires immediately** ✓ - All subsequent events in that session have proper session context **Returning user (already opted in):** - App starts → session_start fires from main.rs ✓ - Normal session tracking continues **User re-enabling analytics:** - User toggles analytics back on in Settings - **session_start event fires immediately** ✓ - Session tracking resumes This ensures every analytics session has a `session_start` event without sending any events before user consent!
This commit is contained in:
@@ -88,12 +88,25 @@ async fn update_config(
|
||||
) -> ResponseJson<ApiResponse<Config>> {
|
||||
let config_path = config_path();
|
||||
|
||||
// Get the current analytics_enabled state before updating
|
||||
let old_analytics_enabled = {
|
||||
let config = deployment.config().read().await;
|
||||
config.analytics_enabled
|
||||
};
|
||||
|
||||
match save_config_to_file(&new_config, &config_path).await {
|
||||
Ok(_) => {
|
||||
let mut config = deployment.config().write().await;
|
||||
*config = new_config.clone();
|
||||
drop(config);
|
||||
|
||||
// If analytics was just enabled (changed from None/false to true), track session_start
|
||||
if new_config.analytics_enabled == Some(true) && old_analytics_enabled != Some(true) {
|
||||
deployment
|
||||
.track_if_analytics_allowed("session_start", serde_json::json!({}))
|
||||
.await;
|
||||
}
|
||||
|
||||
ResponseJson(ApiResponse::success(new_config))
|
||||
}
|
||||
Err(e) => ResponseJson(ApiResponse::error(&format!("Failed to save config: {}", e))),
|
||||
|
||||
Reference in New Issue
Block a user