Skip to content

Commit 4903197

Browse files
Robert27cursoragent
andcommitted
fix: harden web tracking and skip native polling on web
Prevent unhandled rejections from fire-and-forget web sends, only run batch flush polling for the native dispatcher, and document appVersion for React Native Web in the README. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 8f9b271 commit 4903197

3 files changed

Lines changed: 15 additions & 4 deletions

File tree

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ This SDK also supports React Native Web!
2828
> This feature is disabled by default. To enable it, you need to pass the `enableWeb` option when initializing the SDK.
2929
3030
```js
31-
Aptabase.init("<YOUR_APP_KEY>", { enableWeb: true });
31+
Aptabase.init("<YOUR_APP_KEY>", {
32+
enableWeb: true,
33+
appVersion: "1.0.0", // required on web — no native module provides it
34+
});
3235
```
3336

3437
When enabled, the SDK will track events in web environments using the same behavior as the web SDKs. Which means that events will be sent immediately to the `/event` endpoint instead of grouped to the `/events` endpoint.
@@ -78,7 +81,7 @@ export function Counter() {
7881
}
7982
```
8083

81-
To disable tracking events, you can call the `dispose` function. This will stop and deinitalize the SDK.
84+
To disable tracking events, you can call the `dispose` function. This will stop and deinitialize the SDK.
8285

8386
```js
8487
import Aptabase from "@aptabase/react-native";

src/client.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ export class AptabaseClient {
6262
}
6363

6464
public startPolling(flushInterval: number) {
65+
if (!(this._dispatcher instanceof NativeEventDispatcher)) {
66+
return;
67+
}
68+
6569
this.stopPolling();
6670

6771
this._flushTimer = setInterval(this.flush.bind(this), flushInterval);

src/dispatcher.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,15 @@ export class WebEventDispatcher extends EventDispatcher {
110110

111111
public enqueue(evt: Event | Event[]): void {
112112
if (Array.isArray(evt)) {
113-
evt.forEach((event) => this._sendEvent(event));
113+
evt.forEach((event) => this.dispatchEvent(event));
114114
} else {
115-
this._sendEvent(evt);
115+
this.dispatchEvent(evt);
116116
}
117117
}
118+
119+
private dispatchEvent(event: Event): void {
120+
void this._sendEvent(event).catch(() => undefined);
121+
}
118122
}
119123

120124
export class NativeEventDispatcher extends EventDispatcher {

0 commit comments

Comments
 (0)