Skip to content

Commit 2952e30

Browse files
committed
chore: Add dispose function to SDK for stopping event tracking
1 parent a156327 commit 2952e30

3 files changed

Lines changed: 22 additions & 5 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ export function Counter() {
6464
);
6565
}
6666
```
67+
To disable tracking events, you can call the `dispose` function. This will stop and deinitalize the SDK.
68+
```js
69+
import Aptabase from "@aptabase/react-native";
70+
71+
Aptabase.dispose();
72+
```
6773

6874
**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.
6975

src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export type { AptabaseOptions } from "./types";
22
export { AptabaseProvider, useAptabase } from "./context";
3-
import { init, trackEvent } from "./track";
4-
export { init, trackEvent };
3+
import { init, trackEvent, dispose } from "./track";
4+
export { init, trackEvent, dispose };
55

6-
export default { init, trackEvent };
6+
export default { init, trackEvent, dispose };

src/track.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ export function init(appKey: string, options?: AptabaseOptions) {
1616
const [ok, msg] = validate(Platform.OS, appKey, options);
1717
if (!ok) {
1818
if (_client) {
19-
_client.stopPolling();
20-
_client = undefined;
19+
dispose();
2120
}
2221
console.warn(`Aptabase: ${msg}. Tracking will be disabled.`);
2322
return;
@@ -42,6 +41,18 @@ export function init(appKey: string, options?: AptabaseOptions) {
4241
});
4342
}
4443

44+
/**
45+
* Dispose the SDK and stop tracking events
46+
*/
47+
export function dispose() {
48+
if (_client) {
49+
_client.stopPolling();
50+
_client = undefined;
51+
} else {
52+
console.warn(`Aptabase: dispose was called but SDK was not initialized.`);
53+
}
54+
}
55+
4556
/**
4657
* Track an event using given properties
4758
* @param {string} eventName - The name of the event to track

0 commit comments

Comments
 (0)