aurea-tracking-sdk 1.1.1 → 1.1.2

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.js CHANGED
@@ -77,9 +77,9 @@ var AureaSDK = class {
77
77
  console.warn("[Aurea SDK] Already initialized");
78
78
  return;
79
79
  }
80
- if (this.config.respectDoNotTrack && typeof navigator !== "undefined" && (navigator.doNotTrack === "1" || navigator.msDoNotTrack === "1")) {
80
+ if (this.config.respectDoNotTrack && typeof navigator !== "undefined" && (navigator.doNotTrack === "1" || navigator.msDoNotTrack === "1" || navigator.globalPrivacyControl === true)) {
81
81
  if (this.config.debug) {
82
- console.log("[Aurea SDK] Do Not Track enabled, skipping initialization");
82
+ console.log("[Aurea SDK] Do Not Track or Global Privacy Control enabled, skipping initialization");
83
83
  }
84
84
  return;
85
85
  }
@@ -586,12 +586,41 @@ var AureaSDK = class {
586
586
  }
587
587
  const totalDuration = Math.floor((now - this.sessionStartTime) / 1e3);
588
588
  const activeTimeSeconds = Math.floor(this.activeTime / 1e3);
589
- this.track("session_end", {
590
- duration: totalDuration,
591
- activeTime: activeTimeSeconds,
592
- idleTime: totalDuration - activeTimeSeconds,
593
- engagementRate: totalDuration > 0 ? activeTimeSeconds / totalDuration * 100 : 0
589
+ const sessionEndEvent = {
590
+ eventId: this.generateEventId(),
591
+ eventName: "session_end",
592
+ properties: {
593
+ duration: totalDuration,
594
+ activeTime: activeTimeSeconds,
595
+ idleTime: totalDuration - activeTimeSeconds,
596
+ engagementRate: totalDuration > 0 ? activeTimeSeconds / totalDuration * 100 : 0
597
+ },
598
+ context: this.buildContext(),
599
+ timestamp: Date.now()
600
+ };
601
+ const url = `${this.config.apiUrl}/track/events`;
602
+ const payload = JSON.stringify({
603
+ events: [sessionEndEvent],
604
+ batch: false
594
605
  });
606
+ try {
607
+ fetch(url, {
608
+ method: "POST",
609
+ headers: {
610
+ "Content-Type": "application/json",
611
+ "X-Aurea-API-Key": this.config.apiKey,
612
+ "X-Aurea-Funnel-ID": this.config.funnelId
613
+ },
614
+ body: payload,
615
+ keepalive: true
616
+ // Critical: ensures request completes even if page unloads
617
+ }).catch(() => {
618
+ });
619
+ if (this.config.debug) {
620
+ console.log("[Aurea SDK] Session end sent with keepalive");
621
+ }
622
+ } catch (error) {
623
+ }
595
624
  this.flushEvents();
596
625
  });
597
626
  if (this.config.debug) {
package/dist/index.mjs CHANGED
@@ -49,9 +49,9 @@ var AureaSDK = class {
49
49
  console.warn("[Aurea SDK] Already initialized");
50
50
  return;
51
51
  }
52
- if (this.config.respectDoNotTrack && typeof navigator !== "undefined" && (navigator.doNotTrack === "1" || navigator.msDoNotTrack === "1")) {
52
+ if (this.config.respectDoNotTrack && typeof navigator !== "undefined" && (navigator.doNotTrack === "1" || navigator.msDoNotTrack === "1" || navigator.globalPrivacyControl === true)) {
53
53
  if (this.config.debug) {
54
- console.log("[Aurea SDK] Do Not Track enabled, skipping initialization");
54
+ console.log("[Aurea SDK] Do Not Track or Global Privacy Control enabled, skipping initialization");
55
55
  }
56
56
  return;
57
57
  }
@@ -558,12 +558,41 @@ var AureaSDK = class {
558
558
  }
559
559
  const totalDuration = Math.floor((now - this.sessionStartTime) / 1e3);
560
560
  const activeTimeSeconds = Math.floor(this.activeTime / 1e3);
561
- this.track("session_end", {
562
- duration: totalDuration,
563
- activeTime: activeTimeSeconds,
564
- idleTime: totalDuration - activeTimeSeconds,
565
- engagementRate: totalDuration > 0 ? activeTimeSeconds / totalDuration * 100 : 0
561
+ const sessionEndEvent = {
562
+ eventId: this.generateEventId(),
563
+ eventName: "session_end",
564
+ properties: {
565
+ duration: totalDuration,
566
+ activeTime: activeTimeSeconds,
567
+ idleTime: totalDuration - activeTimeSeconds,
568
+ engagementRate: totalDuration > 0 ? activeTimeSeconds / totalDuration * 100 : 0
569
+ },
570
+ context: this.buildContext(),
571
+ timestamp: Date.now()
572
+ };
573
+ const url = `${this.config.apiUrl}/track/events`;
574
+ const payload = JSON.stringify({
575
+ events: [sessionEndEvent],
576
+ batch: false
566
577
  });
578
+ try {
579
+ fetch(url, {
580
+ method: "POST",
581
+ headers: {
582
+ "Content-Type": "application/json",
583
+ "X-Aurea-API-Key": this.config.apiKey,
584
+ "X-Aurea-Funnel-ID": this.config.funnelId
585
+ },
586
+ body: payload,
587
+ keepalive: true
588
+ // Critical: ensures request completes even if page unloads
589
+ }).catch(() => {
590
+ });
591
+ if (this.config.debug) {
592
+ console.log("[Aurea SDK] Session end sent with keepalive");
593
+ }
594
+ } catch (error) {
595
+ }
567
596
  this.flushEvents();
568
597
  });
569
598
  if (this.config.debug) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aurea-tracking-sdk",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "Standalone tracking SDK for Aurea CRM external funnels",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",