Skip to content

Commit 665871a

Browse files
committed
fix(tracker): flush track, vitals, and errors on flush() and unload
- flush() now drains batch, track, vitals, and errors queues - handlePageUnload flushes track, vitals, and errors before exit beacon - Expose __tracker in debug builds for tests - Add Playwright coverage for queued delivery and navigation
1 parent 9e8de35 commit 665871a

File tree

2 files changed

+419
-1
lines changed

2 files changed

+419
-1
lines changed

packages/tracker/src/index.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,14 @@ export class Databuddy extends BaseTracker {
4646
track: (name: string, props?: Record<string, unknown>) =>
4747
this.track(name, props),
4848
screenView: (props?: Record<string, unknown>) => this.screenView(props),
49-
flush: () => this.flushBatch(),
49+
flush: () => {
50+
Promise.all([
51+
this.flushBatch(),
52+
this.flushTrack(),
53+
this.flushVitals(),
54+
this.flushErrors(),
55+
]).catch(() => {});
56+
},
5057
clear: () => this.clear(),
5158
setGlobalProperties: (props: Record<string, unknown>) =>
5259
this.setGlobalProperties(props),
@@ -57,6 +64,9 @@ export class Databuddy extends BaseTracker {
5764
};
5865
window.databuddy = api;
5966
window.db = window.databuddy;
67+
if (isDebugMode()) {
68+
(window as any).__tracker = this;
69+
}
6070
}
6171
}
6272

@@ -204,6 +214,9 @@ export class Databuddy extends BaseTracker {
204214
}
205215

206216
private handlePageUnload() {
217+
this.flushTrack().catch(() => {});
218+
this.flushVitals().catch(() => {});
219+
this.flushErrors().catch(() => {});
207220
this.pauseEngagement();
208221
if (this.hasSentExitBeacon) {
209222
return;

0 commit comments

Comments
 (0)