aurea-tracking-sdk 1.3.4 → 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 +30 -1
- package/dist/index.d.ts +30 -1
- package/dist/index.js +179 -40
- package/dist/index.mjs +179 -40
- package/package.json +1 -1
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
|
*/
|
|
@@ -649,12 +762,15 @@ var AureaSDK = class {
|
|
|
649
762
|
} else {
|
|
650
763
|
const aspectRatio = screenWidth / screenHeight;
|
|
651
764
|
const userAgent = navigator.userAgent.toLowerCase();
|
|
652
|
-
const
|
|
653
|
-
|
|
654
|
-
userAgent.includes("chromebook");
|
|
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");
|
|
655
769
|
if (screenWidth >= 2560 || aspectRatio >= 2.2) {
|
|
656
770
|
deviceType = "Ultrawide";
|
|
657
|
-
} else if (screenWidth <=
|
|
771
|
+
} else if (screenWidth <= 1920) {
|
|
772
|
+
deviceType = "Laptop";
|
|
773
|
+
} else if (screenWidth <= 2048 && (isWindowsLaptop || isChromebook || hasLaptopKeyword)) {
|
|
658
774
|
deviceType = "Laptop";
|
|
659
775
|
} else {
|
|
660
776
|
deviceType = "Desktop";
|
|
@@ -699,6 +815,11 @@ var AureaSDK = class {
|
|
|
699
815
|
session: {
|
|
700
816
|
sessionId: this.sessionId
|
|
701
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
|
+
},
|
|
702
823
|
device: typeof navigator !== "undefined" ? this.parseDeviceInfo() : void 0
|
|
703
824
|
};
|
|
704
825
|
}
|
|
@@ -883,6 +1004,49 @@ var AureaSDK = class {
|
|
|
883
1004
|
}
|
|
884
1005
|
}
|
|
885
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
|
+
}
|
|
886
1050
|
/**
|
|
887
1051
|
* Track Core Web Vitals
|
|
888
1052
|
*/
|
|
@@ -904,61 +1068,36 @@ var AureaSDK = class {
|
|
|
904
1068
|
(0, import_web_vitals.onLCP)((metric) => {
|
|
905
1069
|
if (!this.webVitalsCollected.lcp) {
|
|
906
1070
|
this.webVitalsCollected.lcp = true;
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
value: metric.value,
|
|
910
|
-
rating: getVitalRating("LCP", metric.value),
|
|
911
|
-
delta: metric.delta,
|
|
912
|
-
id: metric.id
|
|
913
|
-
});
|
|
1071
|
+
const rating = getVitalRating("LCP", metric.value);
|
|
1072
|
+
this.sendWebVital(metric, "lcp", rating);
|
|
914
1073
|
}
|
|
915
1074
|
});
|
|
916
1075
|
(0, import_web_vitals.onINP)((metric) => {
|
|
917
1076
|
if (!this.webVitalsCollected.inp) {
|
|
918
1077
|
this.webVitalsCollected.inp = true;
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
value: metric.value,
|
|
922
|
-
rating: getVitalRating("INP", metric.value),
|
|
923
|
-
delta: metric.delta,
|
|
924
|
-
id: metric.id
|
|
925
|
-
});
|
|
1078
|
+
const rating = getVitalRating("INP", metric.value);
|
|
1079
|
+
this.sendWebVital(metric, "inp", rating);
|
|
926
1080
|
}
|
|
927
1081
|
});
|
|
928
1082
|
(0, import_web_vitals.onCLS)((metric) => {
|
|
929
1083
|
if (!this.webVitalsCollected.cls) {
|
|
930
1084
|
this.webVitalsCollected.cls = true;
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
value: metric.value,
|
|
934
|
-
rating: getVitalRating("CLS", metric.value),
|
|
935
|
-
delta: metric.delta,
|
|
936
|
-
id: metric.id
|
|
937
|
-
});
|
|
1085
|
+
const rating = getVitalRating("CLS", metric.value);
|
|
1086
|
+
this.sendWebVital(metric, "cls", rating);
|
|
938
1087
|
}
|
|
939
1088
|
});
|
|
940
1089
|
(0, import_web_vitals.onFCP)((metric) => {
|
|
941
1090
|
if (!this.webVitalsCollected.fcp) {
|
|
942
1091
|
this.webVitalsCollected.fcp = true;
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
value: metric.value,
|
|
946
|
-
rating: getVitalRating("FCP", metric.value),
|
|
947
|
-
delta: metric.delta,
|
|
948
|
-
id: metric.id
|
|
949
|
-
});
|
|
1092
|
+
const rating = getVitalRating("FCP", metric.value);
|
|
1093
|
+
this.sendWebVital(metric, "fcp", rating);
|
|
950
1094
|
}
|
|
951
1095
|
});
|
|
952
1096
|
(0, import_web_vitals.onTTFB)((metric) => {
|
|
953
1097
|
if (!this.webVitalsCollected.ttfb) {
|
|
954
1098
|
this.webVitalsCollected.ttfb = true;
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
value: metric.value,
|
|
958
|
-
rating: getVitalRating("TTFB", metric.value),
|
|
959
|
-
delta: metric.delta,
|
|
960
|
-
id: metric.id
|
|
961
|
-
});
|
|
1099
|
+
const rating = getVitalRating("TTFB", metric.value);
|
|
1100
|
+
this.sendWebVital(metric, "ttfb", rating);
|
|
962
1101
|
}
|
|
963
1102
|
});
|
|
964
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
|
*/
|
|
@@ -620,12 +733,15 @@ var AureaSDK = class {
|
|
|
620
733
|
} else {
|
|
621
734
|
const aspectRatio = screenWidth / screenHeight;
|
|
622
735
|
const userAgent = navigator.userAgent.toLowerCase();
|
|
623
|
-
const
|
|
624
|
-
|
|
625
|
-
userAgent.includes("chromebook");
|
|
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");
|
|
626
740
|
if (screenWidth >= 2560 || aspectRatio >= 2.2) {
|
|
627
741
|
deviceType = "Ultrawide";
|
|
628
|
-
} else if (screenWidth <=
|
|
742
|
+
} else if (screenWidth <= 1920) {
|
|
743
|
+
deviceType = "Laptop";
|
|
744
|
+
} else if (screenWidth <= 2048 && (isWindowsLaptop || isChromebook || hasLaptopKeyword)) {
|
|
629
745
|
deviceType = "Laptop";
|
|
630
746
|
} else {
|
|
631
747
|
deviceType = "Desktop";
|
|
@@ -670,6 +786,11 @@ var AureaSDK = class {
|
|
|
670
786
|
session: {
|
|
671
787
|
sessionId: this.sessionId
|
|
672
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
|
+
},
|
|
673
794
|
device: typeof navigator !== "undefined" ? this.parseDeviceInfo() : void 0
|
|
674
795
|
};
|
|
675
796
|
}
|
|
@@ -854,6 +975,49 @@ var AureaSDK = class {
|
|
|
854
975
|
}
|
|
855
976
|
}
|
|
856
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
|
+
}
|
|
857
1021
|
/**
|
|
858
1022
|
* Track Core Web Vitals
|
|
859
1023
|
*/
|
|
@@ -875,61 +1039,36 @@ var AureaSDK = class {
|
|
|
875
1039
|
onLCP((metric) => {
|
|
876
1040
|
if (!this.webVitalsCollected.lcp) {
|
|
877
1041
|
this.webVitalsCollected.lcp = true;
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
value: metric.value,
|
|
881
|
-
rating: getVitalRating("LCP", metric.value),
|
|
882
|
-
delta: metric.delta,
|
|
883
|
-
id: metric.id
|
|
884
|
-
});
|
|
1042
|
+
const rating = getVitalRating("LCP", metric.value);
|
|
1043
|
+
this.sendWebVital(metric, "lcp", rating);
|
|
885
1044
|
}
|
|
886
1045
|
});
|
|
887
1046
|
onINP((metric) => {
|
|
888
1047
|
if (!this.webVitalsCollected.inp) {
|
|
889
1048
|
this.webVitalsCollected.inp = true;
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
value: metric.value,
|
|
893
|
-
rating: getVitalRating("INP", metric.value),
|
|
894
|
-
delta: metric.delta,
|
|
895
|
-
id: metric.id
|
|
896
|
-
});
|
|
1049
|
+
const rating = getVitalRating("INP", metric.value);
|
|
1050
|
+
this.sendWebVital(metric, "inp", rating);
|
|
897
1051
|
}
|
|
898
1052
|
});
|
|
899
1053
|
onCLS((metric) => {
|
|
900
1054
|
if (!this.webVitalsCollected.cls) {
|
|
901
1055
|
this.webVitalsCollected.cls = true;
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
value: metric.value,
|
|
905
|
-
rating: getVitalRating("CLS", metric.value),
|
|
906
|
-
delta: metric.delta,
|
|
907
|
-
id: metric.id
|
|
908
|
-
});
|
|
1056
|
+
const rating = getVitalRating("CLS", metric.value);
|
|
1057
|
+
this.sendWebVital(metric, "cls", rating);
|
|
909
1058
|
}
|
|
910
1059
|
});
|
|
911
1060
|
onFCP((metric) => {
|
|
912
1061
|
if (!this.webVitalsCollected.fcp) {
|
|
913
1062
|
this.webVitalsCollected.fcp = true;
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
value: metric.value,
|
|
917
|
-
rating: getVitalRating("FCP", metric.value),
|
|
918
|
-
delta: metric.delta,
|
|
919
|
-
id: metric.id
|
|
920
|
-
});
|
|
1063
|
+
const rating = getVitalRating("FCP", metric.value);
|
|
1064
|
+
this.sendWebVital(metric, "fcp", rating);
|
|
921
1065
|
}
|
|
922
1066
|
});
|
|
923
1067
|
onTTFB((metric) => {
|
|
924
1068
|
if (!this.webVitalsCollected.ttfb) {
|
|
925
1069
|
this.webVitalsCollected.ttfb = true;
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
value: metric.value,
|
|
929
|
-
rating: getVitalRating("TTFB", metric.value),
|
|
930
|
-
delta: metric.delta,
|
|
931
|
-
id: metric.id
|
|
932
|
-
});
|
|
1070
|
+
const rating = getVitalRating("TTFB", metric.value);
|
|
1071
|
+
this.sendWebVital(metric, "ttfb", rating);
|
|
933
1072
|
}
|
|
934
1073
|
});
|
|
935
1074
|
if (this.config.debug) {
|