From 9b8f226618369d93d5f665c164bf04a05db6bdd7 Mon Sep 17 00:00:00 2001 From: Charles Vien Date: Wed, 7 Jan 2026 17:57:20 -0800 Subject: [PATCH] Flush before stopping event queue --- com.posthog.unity/Runtime/PostHogSDK.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/com.posthog.unity/Runtime/PostHogSDK.cs b/com.posthog.unity/Runtime/PostHogSDK.cs index 7782b73..9310376 100644 --- a/com.posthog.unity/Runtime/PostHogSDK.cs +++ b/com.posthog.unity/Runtime/PostHogSDK.cs @@ -203,8 +203,9 @@ void ShutdownInternal() // Stop exception tracking _exceptionManager?.Stop(); - _eventQueue?.Stop(); + // Flush before stopping to ensure final events are sent _eventQueue?.Flush(); + _eventQueue?.Stop(); // Wait for any pending file writes to complete if (_storage is FileStorageProvider fileStorage) @@ -952,8 +953,9 @@ void OnAppBackground() void OnAppQuit() { - _eventQueue.Stop(); + // Flush before stopping to ensure final events are sent _eventQueue.Flush(); + _eventQueue.Stop(); // Synchronously flush pending file writes before quitting if (_storage is FileStorageProvider fileStorage)