aurea-tracking-sdk 1.3.3 → 1.4.0

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 CHANGED
@@ -31,6 +31,11 @@ interface AureaConfig {
31
31
  };
32
32
  autoAdvanceStages?: boolean;
33
33
  customStages?: string[];
34
+ gdprConsent?: {
35
+ required: boolean;
36
+ onConsentRequired?: () => Promise<boolean>;
37
+ consentVersion?: string;
38
+ };
34
39
  }
35
40
  interface TrackingEvent {
36
41
  eventId: string;
@@ -132,15 +137,35 @@ declare class AureaSDK {
132
137
  private checkoutStartedAt?;
133
138
  private eventCategoryStats;
134
139
  private trackedOnceEvents;
140
+ private consentGiven;
141
+ private consentVersion;
135
142
  constructor(config: AureaConfig);
136
143
  /**
137
144
  * Initialize the SDK
138
145
  */
139
- init(): void;
146
+ init(): Promise<void>;
140
147
  /**
141
148
  * Track a custom event
142
149
  */
143
150
  track(eventName: string, properties?: Record<string, any>): void;
151
+ /**
152
+ * Grant GDPR consent
153
+ * Call this when user accepts your privacy policy/cookie banner
154
+ */
155
+ grantConsent(version?: string): void;
156
+ /**
157
+ * Revoke GDPR consent
158
+ * Call this when user revokes consent (e.g., via cookie settings)
159
+ */
160
+ revokeConsent(): void;
161
+ /**
162
+ * Check if consent has been given
163
+ */
164
+ hasConsent(): boolean;
165
+ /**
166
+ * Request data deletion (Right to be Forgotten)
167
+ */
168
+ requestDataDeletion(): Promise<void>;
144
169
  /**
145
170
  * Identify a user (links anonymous user to known user)
146
171
  */
@@ -331,6 +356,10 @@ declare class AureaSDK {
331
356
  * Check if user has completed a purchase
332
357
  */
333
358
  private checkForPurchase;
359
+ /**
360
+ * Send Web Vital to dedicated endpoint
361
+ */
362
+ private sendWebVital;
334
363
  /**
335
364
  * Track Core Web Vitals
336
365
  */
package/dist/index.d.ts CHANGED
@@ -31,6 +31,11 @@ interface AureaConfig {
31
31
  };
32
32
  autoAdvanceStages?: boolean;
33
33
  customStages?: string[];
34
+ gdprConsent?: {
35
+ required: boolean;
36
+ onConsentRequired?: () => Promise<boolean>;
37
+ consentVersion?: string;
38
+ };
34
39
  }
35
40
  interface TrackingEvent {
36
41
  eventId: string;
@@ -132,15 +137,35 @@ declare class AureaSDK {
132
137
  private checkoutStartedAt?;
133
138
  private eventCategoryStats;
134
139
  private trackedOnceEvents;
140
+ private consentGiven;
141
+ private consentVersion;
135
142
  constructor(config: AureaConfig);
136
143
  /**
137
144
  * Initialize the SDK
138
145
  */
139
- init(): void;
146
+ init(): Promise<void>;
140
147
  /**
141
148
  * Track a custom event
142
149
  */
143
150
  track(eventName: string, properties?: Record<string, any>): void;
151
+ /**
152
+ * Grant GDPR consent
153
+ * Call this when user accepts your privacy policy/cookie banner
154
+ */
155
+ grantConsent(version?: string): void;
156
+ /**
157
+ * Revoke GDPR consent
158
+ * Call this when user revokes consent (e.g., via cookie settings)
159
+ */
160
+ revokeConsent(): void;
161
+ /**
162
+ * Check if consent has been given
163
+ */
164
+ hasConsent(): boolean;
165
+ /**
166
+ * Request data deletion (Right to be Forgotten)
167
+ */
168
+ requestDataDeletion(): Promise<void>;
144
169
  /**
145
170
  * Identify a user (links anonymous user to known user)
146
171
  */
@@ -331,6 +356,10 @@ declare class AureaSDK {
331
356
  * Check if user has completed a purchase
332
357
  */
333
358
  private checkForPurchase;
359
+ /**
360
+ * Send Web Vital to dedicated endpoint
361
+ */
362
+ private sendWebVital;
334
363
  /**
335
364
  * Track Core Web Vitals
336
365
  */
package/dist/index.js CHANGED
@@ -55,6 +55,9 @@ var AureaSDK = class {
55
55
  this.eventCategoryStats = /* @__PURE__ */ new Map();
56
56
  // NEW: Track which events have been fired (for trackOnce behavior)
57
57
  this.trackedOnceEvents = /* @__PURE__ */ new Set();
58
+ // GDPR: Consent tracking
59
+ this.consentGiven = false;
60
+ this.consentVersion = "1.0";
58
61
  this.config = {
59
62
  apiUrl: "http://localhost:3000/api",
60
63
  debug: false,
@@ -77,12 +80,18 @@ var AureaSDK = class {
77
80
  if (savedUserId) {
78
81
  this.userId = savedUserId;
79
82
  }
83
+ const savedConsent = localStorage.getItem("aurea_consent");
84
+ const savedConsentVersion = localStorage.getItem("aurea_consent_version");
85
+ if (savedConsent === "granted" && savedConsentVersion) {
86
+ this.consentGiven = true;
87
+ this.consentVersion = savedConsentVersion;
88
+ }
80
89
  }
81
90
  }
82
91
  /**
83
92
  * Initialize the SDK
84
93
  */
85
- init() {
94
+ async init() {
86
95
  if (this.initialized) {
87
96
  console.warn("[Aurea SDK] Already initialized");
88
97
  return;
@@ -93,6 +102,29 @@ var AureaSDK = class {
93
102
  }
94
103
  return;
95
104
  }
105
+ if (this.config.gdprConsent?.required) {
106
+ if (!this.consentGiven) {
107
+ if (this.config.debug) {
108
+ console.log("[Aurea SDK] GDPR consent required but not given");
109
+ }
110
+ if (this.config.gdprConsent.onConsentRequired) {
111
+ const consentGranted = await this.config.gdprConsent.onConsentRequired();
112
+ if (consentGranted) {
113
+ this.grantConsent(this.config.gdprConsent.consentVersion || "1.0");
114
+ } else {
115
+ if (this.config.debug) {
116
+ console.log("[Aurea SDK] Consent not granted, tracking disabled");
117
+ }
118
+ return;
119
+ }
120
+ } else {
121
+ if (this.config.debug) {
122
+ console.log("[Aurea SDK] Waiting for manual consent via grantConsent()");
123
+ }
124
+ return;
125
+ }
126
+ }
127
+ }
96
128
  this.initialized = true;
97
129
  if (this.config.autoTrack?.pageViews) {
98
130
  this.trackPageLoad();
@@ -134,6 +166,87 @@ var AureaSDK = class {
134
166
  console.log("[Aurea SDK] Event tracked:", eventName, properties);
135
167
  }
136
168
  }
169
+ /**
170
+ * Grant GDPR consent
171
+ * Call this when user accepts your privacy policy/cookie banner
172
+ */
173
+ grantConsent(version = "1.0") {
174
+ this.consentGiven = true;
175
+ this.consentVersion = version;
176
+ if (typeof window !== "undefined") {
177
+ localStorage.setItem("aurea_consent", "granted");
178
+ localStorage.setItem("aurea_consent_version", version);
179
+ localStorage.setItem("aurea_consent_timestamp", (/* @__PURE__ */ new Date()).toISOString());
180
+ }
181
+ this.track("consent_granted", {
182
+ consentVersion: version,
183
+ timestamp: Date.now()
184
+ });
185
+ if (!this.initialized) {
186
+ this.init();
187
+ }
188
+ if (this.config.debug) {
189
+ console.log("[Aurea SDK] Consent granted:", version);
190
+ }
191
+ }
192
+ /**
193
+ * Revoke GDPR consent
194
+ * Call this when user revokes consent (e.g., via cookie settings)
195
+ */
196
+ revokeConsent() {
197
+ this.consentGiven = false;
198
+ if (typeof window !== "undefined") {
199
+ localStorage.removeItem("aurea_consent");
200
+ localStorage.removeItem("aurea_consent_version");
201
+ localStorage.removeItem("aurea_consent_timestamp");
202
+ }
203
+ this.track("consent_revoked", {
204
+ timestamp: Date.now()
205
+ });
206
+ this.initialized = false;
207
+ if (this.config.debug) {
208
+ console.log("[Aurea SDK] Consent revoked, tracking stopped");
209
+ }
210
+ }
211
+ /**
212
+ * Check if consent has been given
213
+ */
214
+ hasConsent() {
215
+ return this.consentGiven;
216
+ }
217
+ /**
218
+ * Request data deletion (Right to be Forgotten)
219
+ */
220
+ async requestDataDeletion() {
221
+ try {
222
+ await fetch(`${this.config.apiUrl}/track/delete`, {
223
+ method: "POST",
224
+ headers: {
225
+ "Content-Type": "application/json",
226
+ "X-Aurea-API-Key": this.config.apiKey,
227
+ "X-Aurea-Funnel-ID": this.config.funnelId
228
+ },
229
+ body: JSON.stringify({
230
+ anonymousId: this.anonymousId,
231
+ userId: this.userId
232
+ })
233
+ });
234
+ if (typeof window !== "undefined") {
235
+ localStorage.removeItem("aurea_anonymous_id");
236
+ localStorage.removeItem("aurea_user_id");
237
+ localStorage.removeItem("aurea_consent");
238
+ localStorage.removeItem("aurea_consent_version");
239
+ localStorage.removeItem("aurea_consent_timestamp");
240
+ sessionStorage.removeItem("aurea_session_id");
241
+ }
242
+ if (this.config.debug) {
243
+ console.log("[Aurea SDK] Data deletion requested");
244
+ }
245
+ } catch (error) {
246
+ console.error("[Aurea SDK] Failed to request data deletion:", error);
247
+ throw error;
248
+ }
249
+ }
137
250
  /**
138
251
  * Identify a user (links anonymous user to known user)
139
252
  */
@@ -648,9 +761,16 @@ var AureaSDK = class {
648
761
  }
649
762
  } else {
650
763
  const aspectRatio = screenWidth / screenHeight;
764
+ const userAgent = navigator.userAgent.toLowerCase();
765
+ const isMac = userAgent.includes("macintosh") || userAgent.includes("mac os x");
766
+ const isWindowsLaptop = userAgent.includes("windows") && userAgent.includes("touch");
767
+ const isChromebook = userAgent.includes("chromebook") || userAgent.includes("cros");
768
+ const hasLaptopKeyword = userAgent.includes("laptop");
651
769
  if (screenWidth >= 2560 || aspectRatio >= 2.2) {
652
770
  deviceType = "Ultrawide";
653
- } else if (screenWidth < 1920) {
771
+ } else if (screenWidth <= 1920) {
772
+ deviceType = "Laptop";
773
+ } else if (screenWidth <= 2048 && (isWindowsLaptop || isChromebook || hasLaptopKeyword)) {
654
774
  deviceType = "Laptop";
655
775
  } else {
656
776
  deviceType = "Desktop";
@@ -695,6 +815,11 @@ var AureaSDK = class {
695
815
  session: {
696
816
  sessionId: this.sessionId
697
817
  },
818
+ gdpr: {
819
+ consentGiven: this.consentGiven,
820
+ consentVersion: this.consentVersion,
821
+ consentTimestamp: typeof window !== "undefined" ? localStorage.getItem("aurea_consent_timestamp") || void 0 : void 0
822
+ },
698
823
  device: typeof navigator !== "undefined" ? this.parseDeviceInfo() : void 0
699
824
  };
700
825
  }
@@ -879,6 +1004,49 @@ var AureaSDK = class {
879
1004
  }
880
1005
  }
881
1006
  }
1007
+ /**
1008
+ * Send Web Vital to dedicated endpoint
1009
+ */
1010
+ async sendWebVital(metric, name, rating) {
1011
+ try {
1012
+ const deviceInfo = this.parseDeviceInfo();
1013
+ await fetch(`${this.config.apiUrl}/track/web-vitals`, {
1014
+ method: "POST",
1015
+ headers: {
1016
+ "Content-Type": "application/json",
1017
+ "X-Aurea-API-Key": this.config.apiKey,
1018
+ "X-Aurea-Funnel-ID": this.config.funnelId
1019
+ },
1020
+ body: JSON.stringify({
1021
+ funnelId: this.config.funnelId,
1022
+ sessionId: this.sessionId,
1023
+ anonymousId: this.anonymousId,
1024
+ pageUrl: window.location.href,
1025
+ pagePath: window.location.pathname,
1026
+ pageTitle: document.title,
1027
+ metric: name.toUpperCase(),
1028
+ value: metric.value,
1029
+ rating: rating.toUpperCase().replace("-", "_"),
1030
+ delta: metric.delta,
1031
+ id_metric: metric.id,
1032
+ deviceType: deviceInfo?.deviceType,
1033
+ browserName: deviceInfo?.browserName,
1034
+ browserVersion: deviceInfo?.browserVersion,
1035
+ osName: deviceInfo?.osName,
1036
+ osVersion: deviceInfo?.osVersion,
1037
+ screenWidth: deviceInfo?.screenWidth,
1038
+ screenHeight: deviceInfo?.screenHeight,
1039
+ timestamp: /* @__PURE__ */ new Date()
1040
+ }),
1041
+ keepalive: true
1042
+ });
1043
+ if (this.config.debug) {
1044
+ console.log(`[Aurea SDK] Web Vital sent: ${name}`, metric.value, rating);
1045
+ }
1046
+ } catch (error) {
1047
+ console.error(`[Aurea SDK] Failed to send ${name}:`, error);
1048
+ }
1049
+ }
882
1050
  /**
883
1051
  * Track Core Web Vitals
884
1052
  */
@@ -900,61 +1068,36 @@ var AureaSDK = class {
900
1068
  (0, import_web_vitals.onLCP)((metric) => {
901
1069
  if (!this.webVitalsCollected.lcp) {
902
1070
  this.webVitalsCollected.lcp = true;
903
- this.track("web_vital", {
904
- metric: "lcp",
905
- value: metric.value,
906
- rating: getVitalRating("LCP", metric.value),
907
- delta: metric.delta,
908
- id: metric.id
909
- });
1071
+ const rating = getVitalRating("LCP", metric.value);
1072
+ this.sendWebVital(metric, "lcp", rating);
910
1073
  }
911
1074
  });
912
1075
  (0, import_web_vitals.onINP)((metric) => {
913
1076
  if (!this.webVitalsCollected.inp) {
914
1077
  this.webVitalsCollected.inp = true;
915
- this.track("web_vital", {
916
- metric: "inp",
917
- value: metric.value,
918
- rating: getVitalRating("INP", metric.value),
919
- delta: metric.delta,
920
- id: metric.id
921
- });
1078
+ const rating = getVitalRating("INP", metric.value);
1079
+ this.sendWebVital(metric, "inp", rating);
922
1080
  }
923
1081
  });
924
1082
  (0, import_web_vitals.onCLS)((metric) => {
925
1083
  if (!this.webVitalsCollected.cls) {
926
1084
  this.webVitalsCollected.cls = true;
927
- this.track("web_vital", {
928
- metric: "cls",
929
- value: metric.value,
930
- rating: getVitalRating("CLS", metric.value),
931
- delta: metric.delta,
932
- id: metric.id
933
- });
1085
+ const rating = getVitalRating("CLS", metric.value);
1086
+ this.sendWebVital(metric, "cls", rating);
934
1087
  }
935
1088
  });
936
1089
  (0, import_web_vitals.onFCP)((metric) => {
937
1090
  if (!this.webVitalsCollected.fcp) {
938
1091
  this.webVitalsCollected.fcp = true;
939
- this.track("web_vital", {
940
- metric: "fcp",
941
- value: metric.value,
942
- rating: getVitalRating("FCP", metric.value),
943
- delta: metric.delta,
944
- id: metric.id
945
- });
1092
+ const rating = getVitalRating("FCP", metric.value);
1093
+ this.sendWebVital(metric, "fcp", rating);
946
1094
  }
947
1095
  });
948
1096
  (0, import_web_vitals.onTTFB)((metric) => {
949
1097
  if (!this.webVitalsCollected.ttfb) {
950
1098
  this.webVitalsCollected.ttfb = true;
951
- this.track("web_vital", {
952
- metric: "ttfb",
953
- value: metric.value,
954
- rating: getVitalRating("TTFB", metric.value),
955
- delta: metric.delta,
956
- id: metric.id
957
- });
1099
+ const rating = getVitalRating("TTFB", metric.value);
1100
+ this.sendWebVital(metric, "ttfb", rating);
958
1101
  }
959
1102
  });
960
1103
  if (this.config.debug) {
package/dist/index.mjs CHANGED
@@ -26,6 +26,9 @@ var AureaSDK = class {
26
26
  this.eventCategoryStats = /* @__PURE__ */ new Map();
27
27
  // NEW: Track which events have been fired (for trackOnce behavior)
28
28
  this.trackedOnceEvents = /* @__PURE__ */ new Set();
29
+ // GDPR: Consent tracking
30
+ this.consentGiven = false;
31
+ this.consentVersion = "1.0";
29
32
  this.config = {
30
33
  apiUrl: "http://localhost:3000/api",
31
34
  debug: false,
@@ -48,12 +51,18 @@ var AureaSDK = class {
48
51
  if (savedUserId) {
49
52
  this.userId = savedUserId;
50
53
  }
54
+ const savedConsent = localStorage.getItem("aurea_consent");
55
+ const savedConsentVersion = localStorage.getItem("aurea_consent_version");
56
+ if (savedConsent === "granted" && savedConsentVersion) {
57
+ this.consentGiven = true;
58
+ this.consentVersion = savedConsentVersion;
59
+ }
51
60
  }
52
61
  }
53
62
  /**
54
63
  * Initialize the SDK
55
64
  */
56
- init() {
65
+ async init() {
57
66
  if (this.initialized) {
58
67
  console.warn("[Aurea SDK] Already initialized");
59
68
  return;
@@ -64,6 +73,29 @@ var AureaSDK = class {
64
73
  }
65
74
  return;
66
75
  }
76
+ if (this.config.gdprConsent?.required) {
77
+ if (!this.consentGiven) {
78
+ if (this.config.debug) {
79
+ console.log("[Aurea SDK] GDPR consent required but not given");
80
+ }
81
+ if (this.config.gdprConsent.onConsentRequired) {
82
+ const consentGranted = await this.config.gdprConsent.onConsentRequired();
83
+ if (consentGranted) {
84
+ this.grantConsent(this.config.gdprConsent.consentVersion || "1.0");
85
+ } else {
86
+ if (this.config.debug) {
87
+ console.log("[Aurea SDK] Consent not granted, tracking disabled");
88
+ }
89
+ return;
90
+ }
91
+ } else {
92
+ if (this.config.debug) {
93
+ console.log("[Aurea SDK] Waiting for manual consent via grantConsent()");
94
+ }
95
+ return;
96
+ }
97
+ }
98
+ }
67
99
  this.initialized = true;
68
100
  if (this.config.autoTrack?.pageViews) {
69
101
  this.trackPageLoad();
@@ -105,6 +137,87 @@ var AureaSDK = class {
105
137
  console.log("[Aurea SDK] Event tracked:", eventName, properties);
106
138
  }
107
139
  }
140
+ /**
141
+ * Grant GDPR consent
142
+ * Call this when user accepts your privacy policy/cookie banner
143
+ */
144
+ grantConsent(version = "1.0") {
145
+ this.consentGiven = true;
146
+ this.consentVersion = version;
147
+ if (typeof window !== "undefined") {
148
+ localStorage.setItem("aurea_consent", "granted");
149
+ localStorage.setItem("aurea_consent_version", version);
150
+ localStorage.setItem("aurea_consent_timestamp", (/* @__PURE__ */ new Date()).toISOString());
151
+ }
152
+ this.track("consent_granted", {
153
+ consentVersion: version,
154
+ timestamp: Date.now()
155
+ });
156
+ if (!this.initialized) {
157
+ this.init();
158
+ }
159
+ if (this.config.debug) {
160
+ console.log("[Aurea SDK] Consent granted:", version);
161
+ }
162
+ }
163
+ /**
164
+ * Revoke GDPR consent
165
+ * Call this when user revokes consent (e.g., via cookie settings)
166
+ */
167
+ revokeConsent() {
168
+ this.consentGiven = false;
169
+ if (typeof window !== "undefined") {
170
+ localStorage.removeItem("aurea_consent");
171
+ localStorage.removeItem("aurea_consent_version");
172
+ localStorage.removeItem("aurea_consent_timestamp");
173
+ }
174
+ this.track("consent_revoked", {
175
+ timestamp: Date.now()
176
+ });
177
+ this.initialized = false;
178
+ if (this.config.debug) {
179
+ console.log("[Aurea SDK] Consent revoked, tracking stopped");
180
+ }
181
+ }
182
+ /**
183
+ * Check if consent has been given
184
+ */
185
+ hasConsent() {
186
+ return this.consentGiven;
187
+ }
188
+ /**
189
+ * Request data deletion (Right to be Forgotten)
190
+ */
191
+ async requestDataDeletion() {
192
+ try {
193
+ await fetch(`${this.config.apiUrl}/track/delete`, {
194
+ method: "POST",
195
+ headers: {
196
+ "Content-Type": "application/json",
197
+ "X-Aurea-API-Key": this.config.apiKey,
198
+ "X-Aurea-Funnel-ID": this.config.funnelId
199
+ },
200
+ body: JSON.stringify({
201
+ anonymousId: this.anonymousId,
202
+ userId: this.userId
203
+ })
204
+ });
205
+ if (typeof window !== "undefined") {
206
+ localStorage.removeItem("aurea_anonymous_id");
207
+ localStorage.removeItem("aurea_user_id");
208
+ localStorage.removeItem("aurea_consent");
209
+ localStorage.removeItem("aurea_consent_version");
210
+ localStorage.removeItem("aurea_consent_timestamp");
211
+ sessionStorage.removeItem("aurea_session_id");
212
+ }
213
+ if (this.config.debug) {
214
+ console.log("[Aurea SDK] Data deletion requested");
215
+ }
216
+ } catch (error) {
217
+ console.error("[Aurea SDK] Failed to request data deletion:", error);
218
+ throw error;
219
+ }
220
+ }
108
221
  /**
109
222
  * Identify a user (links anonymous user to known user)
110
223
  */
@@ -619,9 +732,16 @@ var AureaSDK = class {
619
732
  }
620
733
  } else {
621
734
  const aspectRatio = screenWidth / screenHeight;
735
+ const userAgent = navigator.userAgent.toLowerCase();
736
+ const isMac = userAgent.includes("macintosh") || userAgent.includes("mac os x");
737
+ const isWindowsLaptop = userAgent.includes("windows") && userAgent.includes("touch");
738
+ const isChromebook = userAgent.includes("chromebook") || userAgent.includes("cros");
739
+ const hasLaptopKeyword = userAgent.includes("laptop");
622
740
  if (screenWidth >= 2560 || aspectRatio >= 2.2) {
623
741
  deviceType = "Ultrawide";
624
- } else if (screenWidth < 1920) {
742
+ } else if (screenWidth <= 1920) {
743
+ deviceType = "Laptop";
744
+ } else if (screenWidth <= 2048 && (isWindowsLaptop || isChromebook || hasLaptopKeyword)) {
625
745
  deviceType = "Laptop";
626
746
  } else {
627
747
  deviceType = "Desktop";
@@ -666,6 +786,11 @@ var AureaSDK = class {
666
786
  session: {
667
787
  sessionId: this.sessionId
668
788
  },
789
+ gdpr: {
790
+ consentGiven: this.consentGiven,
791
+ consentVersion: this.consentVersion,
792
+ consentTimestamp: typeof window !== "undefined" ? localStorage.getItem("aurea_consent_timestamp") || void 0 : void 0
793
+ },
669
794
  device: typeof navigator !== "undefined" ? this.parseDeviceInfo() : void 0
670
795
  };
671
796
  }
@@ -850,6 +975,49 @@ var AureaSDK = class {
850
975
  }
851
976
  }
852
977
  }
978
+ /**
979
+ * Send Web Vital to dedicated endpoint
980
+ */
981
+ async sendWebVital(metric, name, rating) {
982
+ try {
983
+ const deviceInfo = this.parseDeviceInfo();
984
+ await fetch(`${this.config.apiUrl}/track/web-vitals`, {
985
+ method: "POST",
986
+ headers: {
987
+ "Content-Type": "application/json",
988
+ "X-Aurea-API-Key": this.config.apiKey,
989
+ "X-Aurea-Funnel-ID": this.config.funnelId
990
+ },
991
+ body: JSON.stringify({
992
+ funnelId: this.config.funnelId,
993
+ sessionId: this.sessionId,
994
+ anonymousId: this.anonymousId,
995
+ pageUrl: window.location.href,
996
+ pagePath: window.location.pathname,
997
+ pageTitle: document.title,
998
+ metric: name.toUpperCase(),
999
+ value: metric.value,
1000
+ rating: rating.toUpperCase().replace("-", "_"),
1001
+ delta: metric.delta,
1002
+ id_metric: metric.id,
1003
+ deviceType: deviceInfo?.deviceType,
1004
+ browserName: deviceInfo?.browserName,
1005
+ browserVersion: deviceInfo?.browserVersion,
1006
+ osName: deviceInfo?.osName,
1007
+ osVersion: deviceInfo?.osVersion,
1008
+ screenWidth: deviceInfo?.screenWidth,
1009
+ screenHeight: deviceInfo?.screenHeight,
1010
+ timestamp: /* @__PURE__ */ new Date()
1011
+ }),
1012
+ keepalive: true
1013
+ });
1014
+ if (this.config.debug) {
1015
+ console.log(`[Aurea SDK] Web Vital sent: ${name}`, metric.value, rating);
1016
+ }
1017
+ } catch (error) {
1018
+ console.error(`[Aurea SDK] Failed to send ${name}:`, error);
1019
+ }
1020
+ }
853
1021
  /**
854
1022
  * Track Core Web Vitals
855
1023
  */
@@ -871,61 +1039,36 @@ var AureaSDK = class {
871
1039
  onLCP((metric) => {
872
1040
  if (!this.webVitalsCollected.lcp) {
873
1041
  this.webVitalsCollected.lcp = true;
874
- this.track("web_vital", {
875
- metric: "lcp",
876
- value: metric.value,
877
- rating: getVitalRating("LCP", metric.value),
878
- delta: metric.delta,
879
- id: metric.id
880
- });
1042
+ const rating = getVitalRating("LCP", metric.value);
1043
+ this.sendWebVital(metric, "lcp", rating);
881
1044
  }
882
1045
  });
883
1046
  onINP((metric) => {
884
1047
  if (!this.webVitalsCollected.inp) {
885
1048
  this.webVitalsCollected.inp = true;
886
- this.track("web_vital", {
887
- metric: "inp",
888
- value: metric.value,
889
- rating: getVitalRating("INP", metric.value),
890
- delta: metric.delta,
891
- id: metric.id
892
- });
1049
+ const rating = getVitalRating("INP", metric.value);
1050
+ this.sendWebVital(metric, "inp", rating);
893
1051
  }
894
1052
  });
895
1053
  onCLS((metric) => {
896
1054
  if (!this.webVitalsCollected.cls) {
897
1055
  this.webVitalsCollected.cls = true;
898
- this.track("web_vital", {
899
- metric: "cls",
900
- value: metric.value,
901
- rating: getVitalRating("CLS", metric.value),
902
- delta: metric.delta,
903
- id: metric.id
904
- });
1056
+ const rating = getVitalRating("CLS", metric.value);
1057
+ this.sendWebVital(metric, "cls", rating);
905
1058
  }
906
1059
  });
907
1060
  onFCP((metric) => {
908
1061
  if (!this.webVitalsCollected.fcp) {
909
1062
  this.webVitalsCollected.fcp = true;
910
- this.track("web_vital", {
911
- metric: "fcp",
912
- value: metric.value,
913
- rating: getVitalRating("FCP", metric.value),
914
- delta: metric.delta,
915
- id: metric.id
916
- });
1063
+ const rating = getVitalRating("FCP", metric.value);
1064
+ this.sendWebVital(metric, "fcp", rating);
917
1065
  }
918
1066
  });
919
1067
  onTTFB((metric) => {
920
1068
  if (!this.webVitalsCollected.ttfb) {
921
1069
  this.webVitalsCollected.ttfb = true;
922
- this.track("web_vital", {
923
- metric: "ttfb",
924
- value: metric.value,
925
- rating: getVitalRating("TTFB", metric.value),
926
- delta: metric.delta,
927
- id: metric.id
928
- });
1070
+ const rating = getVitalRating("TTFB", metric.value);
1071
+ this.sendWebVital(metric, "ttfb", rating);
929
1072
  }
930
1073
  });
931
1074
  if (this.config.debug) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aurea-tracking-sdk",
3
- "version": "1.3.3",
3
+ "version": "1.4.0",
4
4
  "description": "Standalone tracking SDK for Aurea CRM external funnels",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",