Skip to content

Commit

Permalink
Merge pull request #9 from Robert27/fork/init
Browse files Browse the repository at this point in the history
Add dispose function for proper disabling of tracking
  • Loading branch information
ivnbogdan authored Aug 1, 2024
2 parents b28a231 + ef662ca commit e672584
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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 };
12 changes: 12 additions & 0 deletions src/track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,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
Expand Down

0 comments on commit e672584

Please sign in to comment.