From a15632762287c0061e8e321d6416e6903e93a18c Mon Sep 17 00:00:00 2001 From: Robert Eggl Date: Sun, 28 Jul 2024 00:20:02 +0200 Subject: [PATCH 1/3] adds client reset --- src/track.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/track.ts b/src/track.ts index 5e5a436..8d61120 100644 --- a/src/track.ts +++ b/src/track.ts @@ -15,6 +15,10 @@ let _client: AptabaseClient | undefined; export function init(appKey: string, options?: AptabaseOptions) { const [ok, msg] = validate(Platform.OS, appKey, options); if (!ok) { + if (_client) { + _client.stopPolling(); + _client = undefined; + } console.warn(`Aptabase: ${msg}. Tracking will be disabled.`); return; } From 2952e3070aff3ad593b1ec97fc17adda60cdabff Mon Sep 17 00:00:00 2001 From: Robert Eggl Date: Mon, 29 Jul 2024 01:29:05 +0200 Subject: [PATCH 2/3] chore: Add dispose function to SDK for stopping event tracking --- README.md | 6 ++++++ src/index.ts | 6 +++--- src/track.ts | 15 +++++++++++++-- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 5874a08..7feaea6 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,12 @@ export function Counter() { ); } ``` +To disable tracking events, you can call the `dispose` function. This will stop and deinitalize the SDK. +```js +import Aptabase from "@aptabase/react-native"; + +Aptabase.dispose(); +``` **Note for Expo apps:** Events sent during development while running on Expo Go will not have the `App Version` property because native modules are not available in Expo Go. However, when you build your app and run it on a real device, the `App Version` property will be available. Alternatively, you can also set the `appVersion` during the `init` call so that it's also available during development. diff --git a/src/index.ts b/src/index.ts index 13cae3f..bc8ac24 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,6 @@ export type { AptabaseOptions } from "./types"; export { AptabaseProvider, useAptabase } from "./context"; -import { init, trackEvent } from "./track"; -export { init, trackEvent }; +import { init, trackEvent, dispose } from "./track"; +export { init, trackEvent, dispose }; -export default { init, trackEvent }; +export default { init, trackEvent, dispose }; diff --git a/src/track.ts b/src/track.ts index 8d61120..49bd301 100644 --- a/src/track.ts +++ b/src/track.ts @@ -16,8 +16,7 @@ export function init(appKey: string, options?: AptabaseOptions) { const [ok, msg] = validate(Platform.OS, appKey, options); if (!ok) { if (_client) { - _client.stopPolling(); - _client = undefined; + dispose(); } console.warn(`Aptabase: ${msg}. Tracking will be disabled.`); return; @@ -42,6 +41,18 @@ export function init(appKey: string, options?: AptabaseOptions) { }); } +/** + * Dispose the SDK and stop tracking events + */ +export function dispose() { + if (_client) { + _client.stopPolling(); + _client = undefined; + } else { + console.warn(`Aptabase: dispose was called but SDK was not initialized.`); + } +} + /** * Track an event using given properties * @param {string} eventName - The name of the event to track From ef662ca751941acc6b5e5eb4b051c5d46ab7d485 Mon Sep 17 00:00:00 2001 From: Robert Eggl Date: Thu, 1 Aug 2024 10:46:47 +0200 Subject: [PATCH 3/3] chore: Remove unnecessary dispose function call in init --- src/track.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/track.ts b/src/track.ts index 49bd301..5d3fdbb 100644 --- a/src/track.ts +++ b/src/track.ts @@ -15,9 +15,6 @@ let _client: AptabaseClient | undefined; export function init(appKey: string, options?: AptabaseOptions) { const [ok, msg] = validate(Platform.OS, appKey, options); if (!ok) { - if (_client) { - dispose(); - } console.warn(`Aptabase: ${msg}. Tracking will be disabled.`); return; }