From 2e6675f0acd8bf108abde144e4cda13520973d64 Mon Sep 17 00:00:00 2001 From: goenning Date: Fri, 13 Oct 2023 13:04:59 +0100 Subject: [PATCH] Changes the way we flush events when app state changes. --- CHANGELOG.md | 4 ++++ package.json | 2 +- src/track.ts | 14 +++++--------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3eed62b..eba9286 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.3.3 + +- Changes the way we flush events when app state changes. + ## 0.3.2 - Added a warning log when trackEvent is called with invalid parameters diff --git a/package.json b/package.json index 6ea49cc..0712507 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@aptabase/react-native", - "version": "0.3.2", + "version": "0.3.3", "private": false, "description": "React Native SDK for Aptabase: Open Source, Privacy-First and Simple Analytics for Mobile, Desktop and Web Apps", "sideEffects": false, diff --git a/src/track.ts b/src/track.ts index 1f7e1d1..5e5a436 100644 --- a/src/track.ts +++ b/src/track.ts @@ -28,16 +28,12 @@ export function init(appKey: string, options?: AptabaseOptions) { if (!AppState.isAvailable) return; AppState.addEventListener("change", (next) => { - _client?.stopPolling(); + _client?.flush(); - switch (next) { - case "active": - _client?.startPolling(flushInterval); - break; - - case "background": - _client?.flush(); - break; + if (next === "active") { + _client?.startPolling(flushInterval); + } else { + _client?.stopPolling(); } }); }