aurea-tracking-sdk 1.2.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +50 -2
- package/dist/index.mjs +50 -2
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -8,6 +8,7 @@ interface EventCategoryConfig {
|
|
|
8
8
|
advanceTo?: string;
|
|
9
9
|
value?: number;
|
|
10
10
|
description?: string;
|
|
11
|
+
trackOnce?: boolean;
|
|
11
12
|
}
|
|
12
13
|
interface AureaConfig {
|
|
13
14
|
apiKey: string;
|
|
@@ -129,6 +130,7 @@ declare class AureaSDK {
|
|
|
129
130
|
private isInCheckout;
|
|
130
131
|
private checkoutStartedAt?;
|
|
131
132
|
private eventCategoryStats;
|
|
133
|
+
private trackedOnceEvents;
|
|
132
134
|
constructor(config: AureaConfig);
|
|
133
135
|
/**
|
|
134
136
|
* Initialize the SDK
|
|
@@ -256,6 +258,12 @@ declare class AureaSDK {
|
|
|
256
258
|
* Track checkout abandoned (user left without completing)
|
|
257
259
|
*/
|
|
258
260
|
checkoutAbandoned(reason?: string): void;
|
|
261
|
+
/**
|
|
262
|
+
* Manually end the current session
|
|
263
|
+
* Useful before page navigation (e.g., checkout redirect)
|
|
264
|
+
* Sends session_end event with active/idle time metrics
|
|
265
|
+
*/
|
|
266
|
+
endSession(): Promise<void>;
|
|
259
267
|
/**
|
|
260
268
|
* Get time spent in a specific stage (in seconds)
|
|
261
269
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ interface EventCategoryConfig {
|
|
|
8
8
|
advanceTo?: string;
|
|
9
9
|
value?: number;
|
|
10
10
|
description?: string;
|
|
11
|
+
trackOnce?: boolean;
|
|
11
12
|
}
|
|
12
13
|
interface AureaConfig {
|
|
13
14
|
apiKey: string;
|
|
@@ -129,6 +130,7 @@ declare class AureaSDK {
|
|
|
129
130
|
private isInCheckout;
|
|
130
131
|
private checkoutStartedAt?;
|
|
131
132
|
private eventCategoryStats;
|
|
133
|
+
private trackedOnceEvents;
|
|
132
134
|
constructor(config: AureaConfig);
|
|
133
135
|
/**
|
|
134
136
|
* Initialize the SDK
|
|
@@ -256,6 +258,12 @@ declare class AureaSDK {
|
|
|
256
258
|
* Track checkout abandoned (user left without completing)
|
|
257
259
|
*/
|
|
258
260
|
checkoutAbandoned(reason?: string): void;
|
|
261
|
+
/**
|
|
262
|
+
* Manually end the current session
|
|
263
|
+
* Useful before page navigation (e.g., checkout redirect)
|
|
264
|
+
* Sends session_end event with active/idle time metrics
|
|
265
|
+
*/
|
|
266
|
+
endSession(): Promise<void>;
|
|
259
267
|
/**
|
|
260
268
|
* Get time spent in a specific stage (in seconds)
|
|
261
269
|
*/
|
package/dist/index.js
CHANGED
|
@@ -53,6 +53,8 @@ var AureaSDK = class {
|
|
|
53
53
|
this.isInCheckout = false;
|
|
54
54
|
// NEW: Event categorization tracking
|
|
55
55
|
this.eventCategoryStats = /* @__PURE__ */ new Map();
|
|
56
|
+
// NEW: Track which events have been fired (for trackOnce behavior)
|
|
57
|
+
this.trackedOnceEvents = /* @__PURE__ */ new Set();
|
|
56
58
|
this.config = {
|
|
57
59
|
apiUrl: "http://localhost:3000/api",
|
|
58
60
|
debug: false,
|
|
@@ -250,6 +252,16 @@ var AureaSDK = class {
|
|
|
250
252
|
const value = options?.value ?? categoryConfig?.value ?? 50;
|
|
251
253
|
const advanceTo = options?.advanceTo || categoryConfig?.advanceTo;
|
|
252
254
|
const description = options?.description || categoryConfig?.description;
|
|
255
|
+
const trackOnce = categoryConfig?.trackOnce ?? false;
|
|
256
|
+
if (trackOnce) {
|
|
257
|
+
if (this.trackedOnceEvents.has(eventName)) {
|
|
258
|
+
if (this.config.debug) {
|
|
259
|
+
console.log(`[Aurea SDK] Event skipped (already tracked once): ${eventName}`);
|
|
260
|
+
}
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
this.trackedOnceEvents.add(eventName);
|
|
264
|
+
}
|
|
253
265
|
this.eventCategoryStats.set(
|
|
254
266
|
category,
|
|
255
267
|
(this.eventCategoryStats.get(category) || 0) + 1
|
|
@@ -265,10 +277,12 @@ var AureaSDK = class {
|
|
|
265
277
|
_value: value,
|
|
266
278
|
_description: description,
|
|
267
279
|
_currentStage: this.currentStage,
|
|
268
|
-
_categoryStats: Object.fromEntries(this.eventCategoryStats)
|
|
280
|
+
_categoryStats: Object.fromEntries(this.eventCategoryStats),
|
|
281
|
+
_trackedOnce: trackOnce
|
|
282
|
+
// Include for backend reference
|
|
269
283
|
});
|
|
270
284
|
if (this.config.debug) {
|
|
271
|
-
console.log(`[Aurea SDK] Event tracked: ${eventName} [${category}] (value: ${value}, stage: ${this.currentStage})`);
|
|
285
|
+
console.log(`[Aurea SDK] Event tracked: ${eventName} [${category}] (value: ${value}, stage: ${this.currentStage}${trackOnce ? ", once-only" : ""})`);
|
|
272
286
|
}
|
|
273
287
|
}
|
|
274
288
|
/**
|
|
@@ -525,6 +539,40 @@ var AureaSDK = class {
|
|
|
525
539
|
console.log("[Aurea SDK] Checkout abandoned:", reason);
|
|
526
540
|
}
|
|
527
541
|
}
|
|
542
|
+
/**
|
|
543
|
+
* Manually end the current session
|
|
544
|
+
* Useful before page navigation (e.g., checkout redirect)
|
|
545
|
+
* Sends session_end event with active/idle time metrics
|
|
546
|
+
*/
|
|
547
|
+
async endSession() {
|
|
548
|
+
if (typeof window === "undefined") return;
|
|
549
|
+
const now = Date.now();
|
|
550
|
+
if (this.isInCheckout && this.currentStage === "checkout") {
|
|
551
|
+
this.checkoutAbandoned("session_end");
|
|
552
|
+
}
|
|
553
|
+
if (this.isPageVisible) {
|
|
554
|
+
this.activeTime += now - this.lastActiveTimestamp;
|
|
555
|
+
}
|
|
556
|
+
const totalDuration = Math.floor((now - this.sessionStartTime) / 1e3);
|
|
557
|
+
const activeTimeSeconds = Math.floor(this.activeTime / 1e3);
|
|
558
|
+
const idleTimeSeconds = totalDuration - activeTimeSeconds;
|
|
559
|
+
const engagementRate = totalDuration > 0 ? activeTimeSeconds / totalDuration * 100 : 0;
|
|
560
|
+
await this.trackEvent("session_end", {
|
|
561
|
+
duration: totalDuration,
|
|
562
|
+
activeTime: activeTimeSeconds,
|
|
563
|
+
idleTime: idleTimeSeconds,
|
|
564
|
+
engagementRate
|
|
565
|
+
});
|
|
566
|
+
await this.flushEvents();
|
|
567
|
+
if (this.config.debug) {
|
|
568
|
+
console.log("[Aurea SDK] Session manually ended", {
|
|
569
|
+
duration: totalDuration,
|
|
570
|
+
activeTime: activeTimeSeconds,
|
|
571
|
+
idleTime: idleTimeSeconds,
|
|
572
|
+
engagementRate: `${engagementRate.toFixed(1)}%`
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
}
|
|
528
576
|
/**
|
|
529
577
|
* Get time spent in a specific stage (in seconds)
|
|
530
578
|
*/
|
package/dist/index.mjs
CHANGED
|
@@ -24,6 +24,8 @@ var AureaSDK = class {
|
|
|
24
24
|
this.isInCheckout = false;
|
|
25
25
|
// NEW: Event categorization tracking
|
|
26
26
|
this.eventCategoryStats = /* @__PURE__ */ new Map();
|
|
27
|
+
// NEW: Track which events have been fired (for trackOnce behavior)
|
|
28
|
+
this.trackedOnceEvents = /* @__PURE__ */ new Set();
|
|
27
29
|
this.config = {
|
|
28
30
|
apiUrl: "http://localhost:3000/api",
|
|
29
31
|
debug: false,
|
|
@@ -221,6 +223,16 @@ var AureaSDK = class {
|
|
|
221
223
|
const value = options?.value ?? categoryConfig?.value ?? 50;
|
|
222
224
|
const advanceTo = options?.advanceTo || categoryConfig?.advanceTo;
|
|
223
225
|
const description = options?.description || categoryConfig?.description;
|
|
226
|
+
const trackOnce = categoryConfig?.trackOnce ?? false;
|
|
227
|
+
if (trackOnce) {
|
|
228
|
+
if (this.trackedOnceEvents.has(eventName)) {
|
|
229
|
+
if (this.config.debug) {
|
|
230
|
+
console.log(`[Aurea SDK] Event skipped (already tracked once): ${eventName}`);
|
|
231
|
+
}
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
this.trackedOnceEvents.add(eventName);
|
|
235
|
+
}
|
|
224
236
|
this.eventCategoryStats.set(
|
|
225
237
|
category,
|
|
226
238
|
(this.eventCategoryStats.get(category) || 0) + 1
|
|
@@ -236,10 +248,12 @@ var AureaSDK = class {
|
|
|
236
248
|
_value: value,
|
|
237
249
|
_description: description,
|
|
238
250
|
_currentStage: this.currentStage,
|
|
239
|
-
_categoryStats: Object.fromEntries(this.eventCategoryStats)
|
|
251
|
+
_categoryStats: Object.fromEntries(this.eventCategoryStats),
|
|
252
|
+
_trackedOnce: trackOnce
|
|
253
|
+
// Include for backend reference
|
|
240
254
|
});
|
|
241
255
|
if (this.config.debug) {
|
|
242
|
-
console.log(`[Aurea SDK] Event tracked: ${eventName} [${category}] (value: ${value}, stage: ${this.currentStage})`);
|
|
256
|
+
console.log(`[Aurea SDK] Event tracked: ${eventName} [${category}] (value: ${value}, stage: ${this.currentStage}${trackOnce ? ", once-only" : ""})`);
|
|
243
257
|
}
|
|
244
258
|
}
|
|
245
259
|
/**
|
|
@@ -496,6 +510,40 @@ var AureaSDK = class {
|
|
|
496
510
|
console.log("[Aurea SDK] Checkout abandoned:", reason);
|
|
497
511
|
}
|
|
498
512
|
}
|
|
513
|
+
/**
|
|
514
|
+
* Manually end the current session
|
|
515
|
+
* Useful before page navigation (e.g., checkout redirect)
|
|
516
|
+
* Sends session_end event with active/idle time metrics
|
|
517
|
+
*/
|
|
518
|
+
async endSession() {
|
|
519
|
+
if (typeof window === "undefined") return;
|
|
520
|
+
const now = Date.now();
|
|
521
|
+
if (this.isInCheckout && this.currentStage === "checkout") {
|
|
522
|
+
this.checkoutAbandoned("session_end");
|
|
523
|
+
}
|
|
524
|
+
if (this.isPageVisible) {
|
|
525
|
+
this.activeTime += now - this.lastActiveTimestamp;
|
|
526
|
+
}
|
|
527
|
+
const totalDuration = Math.floor((now - this.sessionStartTime) / 1e3);
|
|
528
|
+
const activeTimeSeconds = Math.floor(this.activeTime / 1e3);
|
|
529
|
+
const idleTimeSeconds = totalDuration - activeTimeSeconds;
|
|
530
|
+
const engagementRate = totalDuration > 0 ? activeTimeSeconds / totalDuration * 100 : 0;
|
|
531
|
+
await this.trackEvent("session_end", {
|
|
532
|
+
duration: totalDuration,
|
|
533
|
+
activeTime: activeTimeSeconds,
|
|
534
|
+
idleTime: idleTimeSeconds,
|
|
535
|
+
engagementRate
|
|
536
|
+
});
|
|
537
|
+
await this.flushEvents();
|
|
538
|
+
if (this.config.debug) {
|
|
539
|
+
console.log("[Aurea SDK] Session manually ended", {
|
|
540
|
+
duration: totalDuration,
|
|
541
|
+
activeTime: activeTimeSeconds,
|
|
542
|
+
idleTime: idleTimeSeconds,
|
|
543
|
+
engagementRate: `${engagementRate.toFixed(1)}%`
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
}
|
|
499
547
|
/**
|
|
500
548
|
* Get time spent in a specific stage (in seconds)
|
|
501
549
|
*/
|