Skip to content

Commit e672584

Browse files
authored
Merge pull request #9 from Robert27/fork/init
Add dispose function for proper disabling of tracking
2 parents b28a231 + ef662ca commit e672584

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

Diff for: README.md

+6
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

Diff for: src/index.ts

+3-3
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 };

Diff for: src/track.ts

+12
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ export function init(appKey: string, options?: AptabaseOptions) {
3838
});
3939
}
4040

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

0 commit comments

Comments
 (0)