@generazioneai/analytics-web 0.0.0-stage → 0.3.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/CHANGELOG.md +29 -0
- package/LICENSE +201 -0
- package/README.md +191 -2
- package/bin/analytics-web.cjs +76 -0
- package/dist/autocapture.d.ts +57 -0
- package/dist/browser.d.ts +3 -0
- package/dist/cmp.d.ts +7 -0
- package/dist/cmp.js +1 -0
- package/dist/consent/cookiebot.d.ts +11 -0
- package/dist/consent/gcm.d.ts +10 -0
- package/dist/consent/index.d.ts +6 -0
- package/dist/consent/iubenda.d.ts +20 -0
- package/dist/consent/onetrust.d.ts +12 -0
- package/dist/consent/tcf.d.ts +43 -0
- package/dist/consent/test-env.d.ts +13 -0
- package/dist/consent/types.d.ts +60 -0
- package/dist/core.d.ts +165 -0
- package/dist/errors.d.ts +60 -0
- package/dist/extensions.d.ts +1 -0
- package/dist/flags.d.ts +96 -0
- package/dist/frustration.d.ts +62 -0
- package/dist/index.cjs +1380 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.js +1359 -0
- package/dist/plugins.d.ts +16 -0
- package/dist/s.js +1 -0
- package/dist/scrub.d.ts +7 -0
- package/dist/snippet.d.ts +1 -0
- package/dist/vitals.d.ts +28 -0
- package/dist/x.js +3 -0
- package/package.json +45 -4
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,1380 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
21
|
+
|
|
22
|
+
// src/index.ts
|
|
23
|
+
var index_exports = {};
|
|
24
|
+
__export(index_exports, {
|
|
25
|
+
Auralytics: () => Auralytics,
|
|
26
|
+
AuralyticsFlags: () => AuralyticsFlags,
|
|
27
|
+
CMP_WAIT_MS: () => CMP_WAIT_MS,
|
|
28
|
+
CONSENT_KEYS: () => CONSENT_KEYS,
|
|
29
|
+
SDK: () => SDK,
|
|
30
|
+
assignVariant: () => assignVariant,
|
|
31
|
+
bucket: () => bucket,
|
|
32
|
+
cookiebot: () => cookiebot,
|
|
33
|
+
createFlags: () => createFlags,
|
|
34
|
+
evaluateFlag: () => evaluateFlag,
|
|
35
|
+
exceptionProps: () => exceptionProps,
|
|
36
|
+
fingerprint: () => fingerprint,
|
|
37
|
+
fnv1a: () => fnv1a,
|
|
38
|
+
fromCategories: () => fromCategories,
|
|
39
|
+
googleConsentMode: () => googleConsentMode,
|
|
40
|
+
init: () => init,
|
|
41
|
+
installAutocapture: () => installAutocapture,
|
|
42
|
+
installEnhanced: () => installEnhanced,
|
|
43
|
+
installErrors: () => installErrors,
|
|
44
|
+
installPlugins: () => installPlugins,
|
|
45
|
+
installWebVitals: () => installWebVitals,
|
|
46
|
+
iubenda: () => iubenda,
|
|
47
|
+
iubendaState: () => iubendaState,
|
|
48
|
+
normalizeStack: () => normalizeStack,
|
|
49
|
+
onetrust: () => onetrust,
|
|
50
|
+
onetrustGroups: () => onetrustGroups,
|
|
51
|
+
pickConsent: () => pickConsent,
|
|
52
|
+
rateVitals: () => rateVitals,
|
|
53
|
+
tcf: () => tcf,
|
|
54
|
+
tcfState: () => tcfState,
|
|
55
|
+
uuidv7: () => uuidv7
|
|
56
|
+
});
|
|
57
|
+
module.exports = __toCommonJS(index_exports);
|
|
58
|
+
|
|
59
|
+
// src/consent/types.ts
|
|
60
|
+
var CONSENT_KEYS = ["analytics_storage", "ad_storage", "ad_user_data", "ad_personalization"];
|
|
61
|
+
function pickConsent(raw, fill) {
|
|
62
|
+
const out = {};
|
|
63
|
+
for (const k of CONSENT_KEYS) {
|
|
64
|
+
const v = String(raw == null ? void 0 : raw[k]).toLowerCase();
|
|
65
|
+
if (v === "granted" || v === "denied") out[k] = v;
|
|
66
|
+
else if (fill) out[k] = fill;
|
|
67
|
+
}
|
|
68
|
+
return out;
|
|
69
|
+
}
|
|
70
|
+
function fromCategories(analytics, ads) {
|
|
71
|
+
const a = analytics ? "granted" : "denied";
|
|
72
|
+
const m = ads ? "granted" : "denied";
|
|
73
|
+
return { analytics_storage: a, ad_storage: m, ad_user_data: m, ad_personalization: m };
|
|
74
|
+
}
|
|
75
|
+
function consentEnv(env) {
|
|
76
|
+
var _a, _b, _c;
|
|
77
|
+
return {
|
|
78
|
+
win: (_a = env == null ? void 0 : env.win) != null ? _a : typeof window !== "undefined" ? window : globalThis,
|
|
79
|
+
setTimeout: (_b = env == null ? void 0 : env.setTimeout) != null ? _b : ((fn, ms) => globalThis.setTimeout(fn, ms)),
|
|
80
|
+
clearTimeout: (_c = env == null ? void 0 : env.clearTimeout) != null ? _c : ((id) => globalThis.clearTimeout(id))
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
var CMP_WAIT_MS = 1e4;
|
|
84
|
+
function waitFor(env, ready, then, timeoutMs = CMP_WAIT_MS) {
|
|
85
|
+
let timer;
|
|
86
|
+
let stopped = false;
|
|
87
|
+
let waited = 0;
|
|
88
|
+
const check = () => {
|
|
89
|
+
if (stopped) return;
|
|
90
|
+
let ok = false;
|
|
91
|
+
try {
|
|
92
|
+
ok = ready();
|
|
93
|
+
} catch {
|
|
94
|
+
ok = false;
|
|
95
|
+
}
|
|
96
|
+
if (ok) {
|
|
97
|
+
stopped = true;
|
|
98
|
+
try {
|
|
99
|
+
then();
|
|
100
|
+
} catch {
|
|
101
|
+
}
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (waited >= timeoutMs) return;
|
|
105
|
+
waited += 100;
|
|
106
|
+
timer = env.setTimeout(check, 100);
|
|
107
|
+
};
|
|
108
|
+
check();
|
|
109
|
+
return () => {
|
|
110
|
+
stopped = true;
|
|
111
|
+
if (timer !== void 0) env.clearTimeout(timer);
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// src/core.ts
|
|
116
|
+
var SDK = { name: "auralytics-web", version: "0.3.0" };
|
|
117
|
+
var ID_COOKIE = "_au_id";
|
|
118
|
+
var SESSION_KEY = "_au_s";
|
|
119
|
+
var QUEUE_KEY = "_au_q";
|
|
120
|
+
var MAX_COOKIE_DAYS = 395;
|
|
121
|
+
var SESSION_IDLE = 30 * 6e4;
|
|
122
|
+
var MAX_OFFLINE = 500;
|
|
123
|
+
var MAX_AGE_OFFLINE = 7 * 864e5;
|
|
124
|
+
var BATCH = 20;
|
|
125
|
+
var EVENT_NAME = /^\$?[a-z][a-z0-9_]{0,39}$/;
|
|
126
|
+
function hex(b) {
|
|
127
|
+
let s = "";
|
|
128
|
+
for (const x of b) s += (x < 16 ? "0" : "") + x.toString(16);
|
|
129
|
+
return s;
|
|
130
|
+
}
|
|
131
|
+
function uuidv7(now, random) {
|
|
132
|
+
const b = random.slice(0, 16);
|
|
133
|
+
let ms = now;
|
|
134
|
+
for (let i = 5; i >= 0; i--) {
|
|
135
|
+
b[i] = ms % 256;
|
|
136
|
+
ms = Math.floor(ms / 256);
|
|
137
|
+
}
|
|
138
|
+
b[6] = b[6] & 15 | 112;
|
|
139
|
+
b[8] = b[8] & 63 | 128;
|
|
140
|
+
const h = hex(b);
|
|
141
|
+
return `${h.slice(0, 8)}-${h.slice(8, 12)}-${h.slice(12, 16)}-${h.slice(16, 20)}-${h.slice(20, 32)}`;
|
|
142
|
+
}
|
|
143
|
+
var Auralytics = class {
|
|
144
|
+
constructor(opts, env) {
|
|
145
|
+
this.opts = opts;
|
|
146
|
+
this.env = env;
|
|
147
|
+
__publicField(this, "wt", "");
|
|
148
|
+
__publicField(this, "idt", "");
|
|
149
|
+
__publicField(this, "off", false);
|
|
150
|
+
__publicField(this, "closing", false);
|
|
151
|
+
__publicField(this, "cs");
|
|
152
|
+
/** La persona ha negato in modo esplicito (`consent('denied')`, banner): il campo `consent` dell'evento vale `denied`, non `unknown`. */
|
|
153
|
+
__publicField(this, "explicitDenial", false);
|
|
154
|
+
__publicField(this, "cookieAge");
|
|
155
|
+
__publicField(this, "unsubs", []);
|
|
156
|
+
/** Ondata 4: chi ascolta i cambi di consenso (il registratore delle sessioni si ferma alla revoca). */
|
|
157
|
+
__publicField(this, "consentListeners", /* @__PURE__ */ new Set());
|
|
158
|
+
__publicField(this, "queue", []);
|
|
159
|
+
__publicField(this, "userId", "");
|
|
160
|
+
__publicField(this, "sending", false);
|
|
161
|
+
__publicField(this, "retryAt", 0);
|
|
162
|
+
__publicField(this, "failures", 0);
|
|
163
|
+
__publicField(this, "lastUrl", "");
|
|
164
|
+
__publicField(this, "endpoint");
|
|
165
|
+
__publicField(this, "disabled");
|
|
166
|
+
var _a, _b, _c, _d, _e, _f;
|
|
167
|
+
this.endpoint = ((_a = opts.endpoint) != null ? _a : "https://api.auralytics.it").replace(/\/+$/, "") + "/c/v1/batch";
|
|
168
|
+
this.disabled = ((_b = opts.respectDnt) != null ? _b : true) && env.dnt();
|
|
169
|
+
this.cookieAge = Math.min(MAX_COOKIE_DAYS, Math.max(1, Math.round(Number(opts.cookieMaxAgeDays)) || MAX_COOKIE_DAYS)) * 86400;
|
|
170
|
+
this.cs = pickConsent(
|
|
171
|
+
{
|
|
172
|
+
...opts.consentDefaults,
|
|
173
|
+
analytics_storage: opts.consent !== "unknown" && opts.consent || ((_c = opts.consentDefaults) == null ? void 0 : _c.analytics_storage)
|
|
174
|
+
},
|
|
175
|
+
"denied"
|
|
176
|
+
);
|
|
177
|
+
this.explicitDenial = opts.consent === "denied";
|
|
178
|
+
this.identityToken((_d = opts.identityToken) != null ? _d : null);
|
|
179
|
+
if (this.granted) this.loadOffline();
|
|
180
|
+
env.onHide(() => void this.flush(true));
|
|
181
|
+
env.setInterval(() => void this.flush(false), 5e3);
|
|
182
|
+
if ((_e = opts.autoPageviews) != null ? _e : true) {
|
|
183
|
+
this.page();
|
|
184
|
+
env.onNavigate(() => this.page());
|
|
185
|
+
}
|
|
186
|
+
for (const a of [].concat((_f = opts.cmp) != null ? _f : [])) {
|
|
187
|
+
try {
|
|
188
|
+
this.unsubs.push(a.subscribe((s) => this.consentUpdate(s)));
|
|
189
|
+
} catch {
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
get granted() {
|
|
194
|
+
return this.cs.analytics_storage === "granted";
|
|
195
|
+
}
|
|
196
|
+
get none() {
|
|
197
|
+
return !this.granted && this.opts.withoutConsent === "none";
|
|
198
|
+
}
|
|
199
|
+
/** Il valore del campo `consent` degli eventi: `granted` solo con `analytics_storage` concesso. */
|
|
200
|
+
get consentValue() {
|
|
201
|
+
return this.granted ? "granted" : this.explicitDenial ? "denied" : "unknown";
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Ondata 4 (registrazioni): avvisa a ogni cambio di consenso con il nuovo valore (`granted`/`denied`/`unknown`). Restituisce la funzione
|
|
205
|
+
* che smette di ascoltare. Il registratore la usa per fermarsi SUBITO alla revoca, anche fuori campione.
|
|
206
|
+
*/
|
|
207
|
+
onConsentChange(fn) {
|
|
208
|
+
this.consentListeners.add(fn);
|
|
209
|
+
return () => this.consentListeners.delete(fn);
|
|
210
|
+
}
|
|
211
|
+
/** Ondata 4: l'id del dispositivo (`distinct_id` degli eventi), SOLO col consenso e senza crearne uno; altrimenti `null`. */
|
|
212
|
+
get distinctIdValue() {
|
|
213
|
+
if (!this.granted) return null;
|
|
214
|
+
const id = this.env.getCookie(ID_COOKIE);
|
|
215
|
+
return id && /^[A-Za-z0-9._:-]{8,64}$/.test(id) ? id : null;
|
|
216
|
+
}
|
|
217
|
+
/** Ondata 4: l'utente di `identify()`, solo col consenso; altrimenti `null`. */
|
|
218
|
+
get userIdValue() {
|
|
219
|
+
return this.granted && this.userId ? this.userId : null;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Ondata 5 (flag ed esperimenti): la chiave stabile con cui assegnare le varianti, la stessa unità dei risultati (`user_id`, altrimenti
|
|
223
|
+
* l'id del dispositivo). Solo con `analytics_storage` concesso: senza, `null` (niente id persistente; gli esperimenti mostrano il controllo).
|
|
224
|
+
*/
|
|
225
|
+
bucketingId() {
|
|
226
|
+
if (!this.granted || this.disabled || this.off) return null;
|
|
227
|
+
return this.userId || this.deviceId();
|
|
228
|
+
}
|
|
229
|
+
/** L'indirizzo del collector usato da questo SDK (per `GET /c/v1/flags`). */
|
|
230
|
+
get collectorEndpoint() {
|
|
231
|
+
return this.endpoint.replace(/\/c\/v1\/batch$/, "");
|
|
232
|
+
}
|
|
233
|
+
/** Gli stati di Consent Mode v2 e la modalità che ne viene (`full` con il consenso, altrimenti `cookieless` o `none`). */
|
|
234
|
+
consentState() {
|
|
235
|
+
return { ...this.cs, mode: this.granted ? "full" : this.none ? "none" : "cookieless" };
|
|
236
|
+
}
|
|
237
|
+
/** Stato del consenso dal banner (CMP) del cliente: vale per `analytics_storage` (`unknown` = negato, nessuna scelta). */
|
|
238
|
+
consent(state) {
|
|
239
|
+
this.applyConsent({ analytics_storage: state === "granted" ? "granted" : "denied" }, state === "denied");
|
|
240
|
+
}
|
|
241
|
+
/** Come `gtag('consent', 'update', …)`: cambia solo gli stati indicati. */
|
|
242
|
+
consentUpdate(partial) {
|
|
243
|
+
const s = pickConsent(partial);
|
|
244
|
+
this.applyConsent(s, s.analytics_storage === "denied");
|
|
245
|
+
}
|
|
246
|
+
/** Il cambio di stato: concesso = cookie e sessione; revoca = via cookie, archivio e coda offline; evento `$consent` se cambia. */
|
|
247
|
+
applyConsent(p, denial) {
|
|
248
|
+
var _a;
|
|
249
|
+
if (this.off) return;
|
|
250
|
+
const was = this.granted;
|
|
251
|
+
let changed = false;
|
|
252
|
+
for (const k of CONSENT_KEYS) {
|
|
253
|
+
const v = p[k];
|
|
254
|
+
if (v && v !== this.cs[k]) {
|
|
255
|
+
this.cs[k] = v;
|
|
256
|
+
changed = true;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
if (p.analytics_storage) this.explicitDenial = denial;
|
|
260
|
+
if (this.granted) {
|
|
261
|
+
if (!was) this.deviceId();
|
|
262
|
+
} else {
|
|
263
|
+
this.env.setCookie(ID_COOKIE, "", 0);
|
|
264
|
+
try {
|
|
265
|
+
const st = this.env.storage();
|
|
266
|
+
st == null ? void 0 : st.removeItem(SESSION_KEY);
|
|
267
|
+
st == null ? void 0 : st.removeItem(QUEUE_KEY);
|
|
268
|
+
} catch {
|
|
269
|
+
}
|
|
270
|
+
this.userId = "";
|
|
271
|
+
if (this.none) this.queue = [];
|
|
272
|
+
}
|
|
273
|
+
if (changed) this.track("$consent", { state: this.cs.analytics_storage, ...this.cs });
|
|
274
|
+
if (changed || p.analytics_storage) {
|
|
275
|
+
const c = this.consentValue;
|
|
276
|
+
for (const fn of [...this.consentListeners]) {
|
|
277
|
+
try {
|
|
278
|
+
fn(c);
|
|
279
|
+
} catch {
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
if (this.granted && !was && this.opts.withoutConsent === "none" && ((_a = this.opts.autoPageviews) != null ? _a : true)) {
|
|
284
|
+
this.lastUrl = "";
|
|
285
|
+
this.page();
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
/** La persona del cliente (pseudonimo, mai un'email: l'SDK la rifiuta). Solo con il consenso. */
|
|
289
|
+
identify(userId) {
|
|
290
|
+
if (!this.granted || !userId || userId.includes("@") || userId.length > 128) return;
|
|
291
|
+
this.userId = userId;
|
|
292
|
+
this.track("$identify");
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Identità verificata: il token `it1.<payload>.<firma>` che il backend del cliente firma per questo stream (chi è la persona, per
|
|
296
|
+
* quale gruppo, fino a quando). Resta solo in memoria e va nei lotti come `idt`; `null` lo toglie, `reset()` anche. Vale per gli
|
|
297
|
+
* eventi raccolti da qui in poi: quelli già in coda partono col token che era attivo quando sono nati. Si manda anche senza consenso:
|
|
298
|
+
* lo verifica e lo applica il collector secondo le regole della proprietà.
|
|
299
|
+
*/
|
|
300
|
+
identityToken(token) {
|
|
301
|
+
this.idt = token && token.startsWith("it1.") && token.length <= 1024 ? token : "";
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* @deprecated biglietto dei dipendenti: il collector lo accetta fino al passaggio di K3, poi si toglie. Usare `identityToken()`.
|
|
305
|
+
*
|
|
306
|
+
* ST5, solo app di lavoro (proprietà `workforce`): il biglietto firmato da `GET analytics/me/workforce/ticket` del gateway (azienda e
|
|
307
|
+
* pseudonimo della persona, mai l'id in chiaro). Resta in memoria e va nei lotti come `wt`; `null` lo toglie. Il collector lo verifica.
|
|
308
|
+
*/
|
|
309
|
+
workforceTicket(ticket) {
|
|
310
|
+
this.wt = ticket && ticket.startsWith("wt1.") && ticket.length <= 512 ? ticket : "";
|
|
311
|
+
}
|
|
312
|
+
/** Logout: la persona si scollega e il dispositivo riceve un id nuovo. */
|
|
313
|
+
reset() {
|
|
314
|
+
this.userId = "";
|
|
315
|
+
this.wt = "";
|
|
316
|
+
this.idt = "";
|
|
317
|
+
if (this.granted) {
|
|
318
|
+
this.env.setCookie(ID_COOKIE, "", 0);
|
|
319
|
+
this.deviceId();
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
page(props) {
|
|
323
|
+
const href = this.env.location().href;
|
|
324
|
+
if (href === this.lastUrl && !props) return;
|
|
325
|
+
this.lastUrl = href;
|
|
326
|
+
if (this.clean(href) === null) return;
|
|
327
|
+
this.track("page_view", props, {
|
|
328
|
+
url: href,
|
|
329
|
+
title: this.opts.pageTitle === false ? "" : this.env.title(),
|
|
330
|
+
referrer: this.env.referrer()
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
/** Fine dell'istanza (smontaggio di un provider): manda ciò che resta e da qui in poi non raccoglie né invia più niente. */
|
|
334
|
+
shutdown() {
|
|
335
|
+
this.closing = true;
|
|
336
|
+
for (const u of this.unsubs.splice(0)) {
|
|
337
|
+
try {
|
|
338
|
+
u();
|
|
339
|
+
} catch {
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
void this.flush(true).then(() => this.off = true);
|
|
343
|
+
}
|
|
344
|
+
clean(url) {
|
|
345
|
+
const s = this.opts.sanitizeUrl;
|
|
346
|
+
return s && url ? s(url) : url;
|
|
347
|
+
}
|
|
348
|
+
track(event, props, extra = {}) {
|
|
349
|
+
var _a, _b;
|
|
350
|
+
if (this.disabled || this.off || this.closing || !EVENT_NAME.test(event)) return;
|
|
351
|
+
if (this.none) return;
|
|
352
|
+
const now = this.env.now();
|
|
353
|
+
const url = (_a = this.clean(typeof extra.url === "string" ? extra.url : this.env.location().href)) != null ? _a : "";
|
|
354
|
+
const mod = typeof this.opts.module === "function" ? this.opts.module(url) : this.opts.module;
|
|
355
|
+
const granted = this.granted;
|
|
356
|
+
const screen = this.env.screen();
|
|
357
|
+
const e = {
|
|
358
|
+
event_id: uuidv7(now, this.env.random(16)),
|
|
359
|
+
event,
|
|
360
|
+
ts: now,
|
|
361
|
+
consent: this.consentValue,
|
|
362
|
+
url,
|
|
363
|
+
screen_w: screen.w,
|
|
364
|
+
screen_h: screen.h,
|
|
365
|
+
language: this.env.language(),
|
|
366
|
+
...granted ? { distinct_id: this.deviceId(), session_id: this.session(now) } : {},
|
|
367
|
+
...granted && this.userId ? { user_id: this.userId } : {},
|
|
368
|
+
...this.opts.product ? { product: this.opts.product } : {},
|
|
369
|
+
...this.opts.appName ? { app_name: this.opts.appName } : {},
|
|
370
|
+
...mod ? { module: mod } : {},
|
|
371
|
+
...this.opts.debug ? { debug: true } : {},
|
|
372
|
+
...props ? { properties: props } : {},
|
|
373
|
+
...extra
|
|
374
|
+
};
|
|
375
|
+
e.url = url;
|
|
376
|
+
if (typeof e.referrer === "string") e.referrer = (_b = this.clean(e.referrer)) != null ? _b : "";
|
|
377
|
+
this.queue.push({ e, idt: this.idt, wt: this.wt });
|
|
378
|
+
if (this.queue.length >= BATCH) void this.flush(false);
|
|
379
|
+
}
|
|
380
|
+
/** Invia la coda. `beacon`: alla chiusura della pagina, senza attendere la risposta. */
|
|
381
|
+
async flush(beacon) {
|
|
382
|
+
if (this.off || this.sending || !this.queue.length) return;
|
|
383
|
+
const now = this.env.now();
|
|
384
|
+
if (!beacon && now < this.retryAt) return;
|
|
385
|
+
this.queue = this.queue.filter((x) => now - x.e.ts < MAX_AGE_OFFLINE);
|
|
386
|
+
if (!this.queue.length) return;
|
|
387
|
+
const { idt, wt } = this.queue[0];
|
|
388
|
+
let n = 0;
|
|
389
|
+
while (n < BATCH * 2 && n < this.queue.length && this.queue[n].idt === idt && this.queue[n].wt === wt) n++;
|
|
390
|
+
const batch = this.queue.slice(0, n);
|
|
391
|
+
const body = JSON.stringify({
|
|
392
|
+
stream: this.opts.stream,
|
|
393
|
+
sent_at: now,
|
|
394
|
+
sdk: SDK,
|
|
395
|
+
...wt ? { wt } : {},
|
|
396
|
+
...idt ? { idt } : {},
|
|
397
|
+
events: batch.map((x) => x.e)
|
|
398
|
+
});
|
|
399
|
+
this.sending = true;
|
|
400
|
+
let ok = false;
|
|
401
|
+
try {
|
|
402
|
+
ok = await this.env.send(this.endpoint, body, beacon);
|
|
403
|
+
} catch {
|
|
404
|
+
ok = false;
|
|
405
|
+
}
|
|
406
|
+
this.sending = false;
|
|
407
|
+
if (ok) {
|
|
408
|
+
this.queue = this.queue.slice(batch.length);
|
|
409
|
+
this.failures = 0;
|
|
410
|
+
this.retryAt = 0;
|
|
411
|
+
} else {
|
|
412
|
+
this.failures++;
|
|
413
|
+
this.retryAt = now + Math.min(3e5, 5e3 * 2 ** Math.min(this.failures, 6));
|
|
414
|
+
if (this.queue.length > MAX_OFFLINE) this.queue = this.queue.slice(-MAX_OFFLINE);
|
|
415
|
+
}
|
|
416
|
+
if (this.granted) this.saveOffline();
|
|
417
|
+
if (ok && this.queue.length) await this.flush(beacon);
|
|
418
|
+
}
|
|
419
|
+
deviceId() {
|
|
420
|
+
let id = this.env.getCookie(ID_COOKIE);
|
|
421
|
+
if (!id || !/^[A-Za-z0-9._:-]{8,64}$/.test(id)) {
|
|
422
|
+
id = "au." + hex(this.env.random(12));
|
|
423
|
+
}
|
|
424
|
+
this.env.setCookie(ID_COOKIE, id, this.cookieAge);
|
|
425
|
+
return id;
|
|
426
|
+
}
|
|
427
|
+
session(now) {
|
|
428
|
+
var _a;
|
|
429
|
+
const st = this.env.storage();
|
|
430
|
+
let s = null;
|
|
431
|
+
try {
|
|
432
|
+
s = JSON.parse((_a = st == null ? void 0 : st.getItem(SESSION_KEY)) != null ? _a : "null");
|
|
433
|
+
} catch {
|
|
434
|
+
s = null;
|
|
435
|
+
}
|
|
436
|
+
if (!s || now - s.last > SESSION_IDLE) s = { id: uuidv7(now, this.env.random(16)), last: now };
|
|
437
|
+
s.last = now;
|
|
438
|
+
try {
|
|
439
|
+
st == null ? void 0 : st.setItem(SESSION_KEY, JSON.stringify(s));
|
|
440
|
+
} catch {
|
|
441
|
+
}
|
|
442
|
+
return s.id;
|
|
443
|
+
}
|
|
444
|
+
saveOffline() {
|
|
445
|
+
try {
|
|
446
|
+
const st = this.env.storage();
|
|
447
|
+
if (!st) return;
|
|
448
|
+
if (this.queue.length) st.setItem(QUEUE_KEY, JSON.stringify(this.queue.slice(-MAX_OFFLINE).map((x) => x.e)));
|
|
449
|
+
else st.removeItem(QUEUE_KEY);
|
|
450
|
+
} catch {
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
loadOffline() {
|
|
454
|
+
var _a, _b;
|
|
455
|
+
try {
|
|
456
|
+
const saved = JSON.parse((_b = (_a = this.env.storage()) == null ? void 0 : _a.getItem(QUEUE_KEY)) != null ? _b : "[]");
|
|
457
|
+
if (Array.isArray(saved)) this.queue = saved.slice(-MAX_OFFLINE).map((e) => ({ e, idt: "", wt: "" }));
|
|
458
|
+
} catch {
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
};
|
|
462
|
+
|
|
463
|
+
// src/browser.ts
|
|
464
|
+
function browserEnv(win = window) {
|
|
465
|
+
const doc = win.document;
|
|
466
|
+
return {
|
|
467
|
+
now: () => Date.now(),
|
|
468
|
+
random: (n) => win.crypto.getRandomValues(new Uint8Array(n)),
|
|
469
|
+
location: () => ({ href: win.location.href, host: win.location.host }),
|
|
470
|
+
referrer: () => doc.referrer,
|
|
471
|
+
title: () => doc.title,
|
|
472
|
+
screen: () => {
|
|
473
|
+
var _a, _b, _c, _d;
|
|
474
|
+
return { w: (_b = (_a = win.screen) == null ? void 0 : _a.width) != null ? _b : 0, h: (_d = (_c = win.screen) == null ? void 0 : _c.height) != null ? _d : 0 };
|
|
475
|
+
},
|
|
476
|
+
language: () => {
|
|
477
|
+
var _a;
|
|
478
|
+
return (_a = win.navigator.language) != null ? _a : "";
|
|
479
|
+
},
|
|
480
|
+
dnt: () => win.navigator.doNotTrack === "1" || win.navigator.globalPrivacyControl === true,
|
|
481
|
+
getCookie: (name) => {
|
|
482
|
+
const m = doc.cookie.match(new RegExp("(?:^|; )" + name + "=([^;]*)"));
|
|
483
|
+
return m ? decodeURIComponent(m[1]) : null;
|
|
484
|
+
},
|
|
485
|
+
setCookie: (name, value, maxAge) => {
|
|
486
|
+
const secure = win.location.protocol === "https:" ? "; Secure" : "";
|
|
487
|
+
doc.cookie = `${name}=${encodeURIComponent(value)}; Max-Age=${maxAge}; Path=/; SameSite=Lax${secure}`;
|
|
488
|
+
},
|
|
489
|
+
storage: () => {
|
|
490
|
+
try {
|
|
491
|
+
return win.localStorage;
|
|
492
|
+
} catch {
|
|
493
|
+
return null;
|
|
494
|
+
}
|
|
495
|
+
},
|
|
496
|
+
send: async (url, body, beacon) => {
|
|
497
|
+
if (beacon && win.navigator.sendBeacon)
|
|
498
|
+
return win.navigator.sendBeacon(url, new Blob([body], { type: "text/plain" }));
|
|
499
|
+
const r = await win.fetch(url, {
|
|
500
|
+
method: "POST",
|
|
501
|
+
body,
|
|
502
|
+
headers: { "content-type": "text/plain" },
|
|
503
|
+
keepalive: true,
|
|
504
|
+
credentials: "omit"
|
|
505
|
+
});
|
|
506
|
+
return r.ok || r.status >= 400 && r.status < 500 && r.status !== 429;
|
|
507
|
+
},
|
|
508
|
+
onHide: (fn) => {
|
|
509
|
+
doc.addEventListener("visibilitychange", () => doc.visibilityState === "hidden" && fn());
|
|
510
|
+
win.addEventListener("pagehide", fn);
|
|
511
|
+
},
|
|
512
|
+
onNavigate: (fn) => {
|
|
513
|
+
const h = win.history;
|
|
514
|
+
for (const k of ["pushState", "replaceState"]) {
|
|
515
|
+
const orig = h[k];
|
|
516
|
+
h[k] = function(...args) {
|
|
517
|
+
const r = orig.apply(this, args);
|
|
518
|
+
setTimeout(fn, 0);
|
|
519
|
+
return r;
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
win.addEventListener("popstate", () => setTimeout(fn, 0));
|
|
523
|
+
},
|
|
524
|
+
setInterval: (fn, ms) => win.setInterval(fn, ms)
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
// src/scrub.ts
|
|
529
|
+
function scrubText(s, max = 300) {
|
|
530
|
+
return s.replace(/(https?:\/\/[^\s?#)'"]*)[?#][^\s)'":]*/g, "$1").replace(/[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}(?![\w:/.-])/g, "<email>").replace(/\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b/gi, "<id>").replace(/\b[A-Za-z0-9_-]{32,}\b/g, "<token>").replace(/\d[\d\s.-]{4,}\d/g, "<n>").slice(0, max);
|
|
531
|
+
}
|
|
532
|
+
function originPath(href, base) {
|
|
533
|
+
try {
|
|
534
|
+
const u = new URL(href, base);
|
|
535
|
+
return u.protocol === "http:" || u.protocol === "https:" ? `${u.origin}${u.pathname}` : "";
|
|
536
|
+
} catch {
|
|
537
|
+
return "";
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
// src/autocapture.ts
|
|
542
|
+
var DOWNLOAD_EXT = /\.(pdf|zip|rar|7z|gz|tgz|docx?|xlsx?|pptx?|odt|ods|odp|csv|txt|rtf|exe|msi|dmg|pkg|apk|mp3|wav|mp4|mov|avi|mkv|epub)$/i;
|
|
543
|
+
var CLICKABLE = /* @__PURE__ */ new Set(["a", "button"]);
|
|
544
|
+
var FIELD = /* @__PURE__ */ new Set(["input", "textarea", "select", "option"]);
|
|
545
|
+
function optedOut(el) {
|
|
546
|
+
var _a;
|
|
547
|
+
for (let x = el; x; x = (_a = x.parentElement) != null ? _a : null) if (x.getAttribute("data-au-no-capture") !== null) return true;
|
|
548
|
+
return false;
|
|
549
|
+
}
|
|
550
|
+
function stableClass(c) {
|
|
551
|
+
return /^[A-Za-z][A-Za-z_-]{1,40}$/.test(c) && !/(^css-|^sc-|^jsx-|__[a-z0-9]{5,}$)/.test(c);
|
|
552
|
+
}
|
|
553
|
+
function selectorOf(el) {
|
|
554
|
+
const parts = [];
|
|
555
|
+
for (let x = el, depth = 0; x && depth < 4; x = x.parentElement, depth++) {
|
|
556
|
+
const tag = x.tagName.toLowerCase();
|
|
557
|
+
if (tag === "html" || tag === "body") break;
|
|
558
|
+
if (x.id && /^[A-Za-z][A-Za-z0-9_-]{0,40}$/.test(x.id) && !/\d{3,}/.test(x.id)) {
|
|
559
|
+
parts.unshift(`${tag}#${x.id}`);
|
|
560
|
+
break;
|
|
561
|
+
}
|
|
562
|
+
const cls = typeof x.className === "string" ? x.className.split(/\s+/).filter(stableClass).slice(0, 2) : [];
|
|
563
|
+
parts.unshift(tag + cls.map((c) => `.${c}`).join(""));
|
|
564
|
+
}
|
|
565
|
+
return parts.join(" > ").slice(0, 300);
|
|
566
|
+
}
|
|
567
|
+
function clickableOf(target) {
|
|
568
|
+
var _a, _b;
|
|
569
|
+
for (let x = target, d = 0; x && d < 5; x = (_a = x.parentElement) != null ? _a : null, d++) {
|
|
570
|
+
const tag = x.tagName.toLowerCase();
|
|
571
|
+
if (FIELD.has(tag)) {
|
|
572
|
+
const type = ((_b = x.getAttribute("type")) != null ? _b : "").toLowerCase();
|
|
573
|
+
return tag === "input" && ["submit", "button", "reset", "checkbox", "radio"].includes(type) ? x : null;
|
|
574
|
+
}
|
|
575
|
+
if (x.getAttribute("contenteditable") !== null) return null;
|
|
576
|
+
if (CLICKABLE.has(tag) || x.getAttribute("role") === "button" || x.getAttribute("data-au-capture") !== null)
|
|
577
|
+
return x;
|
|
578
|
+
}
|
|
579
|
+
return null;
|
|
580
|
+
}
|
|
581
|
+
function autocaptureProps(target, base) {
|
|
582
|
+
var _a, _b, _c;
|
|
583
|
+
const el = clickableOf(target);
|
|
584
|
+
if (!el || optedOut(el)) return null;
|
|
585
|
+
const tag = el.tagName.toLowerCase();
|
|
586
|
+
const text = tag === "input" ? "" : scrubText(((_a = el.textContent) != null ? _a : "").replace(/\s+/g, " ").trim(), 64);
|
|
587
|
+
const href = tag === "a" ? originPath((_b = el.getAttribute("href")) != null ? _b : "", base) : "";
|
|
588
|
+
return {
|
|
589
|
+
selector: selectorOf(el),
|
|
590
|
+
tag,
|
|
591
|
+
...text ? { text } : {},
|
|
592
|
+
...href ? { href } : {},
|
|
593
|
+
...el.getAttribute("data-au-name") ? { name: scrubText((_c = el.getAttribute("data-au-name")) != null ? _c : "", 64) } : {}
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
function linkEvent(href, pageHref, opts) {
|
|
597
|
+
var _a;
|
|
598
|
+
let u;
|
|
599
|
+
let page;
|
|
600
|
+
try {
|
|
601
|
+
u = new URL(href, pageHref);
|
|
602
|
+
page = new URL(pageHref);
|
|
603
|
+
} catch {
|
|
604
|
+
return null;
|
|
605
|
+
}
|
|
606
|
+
if (u.protocol !== "http:" && u.protocol !== "https:") return null;
|
|
607
|
+
const m = DOWNLOAD_EXT.exec(u.pathname);
|
|
608
|
+
if (opts.downloads && m)
|
|
609
|
+
return {
|
|
610
|
+
event: "$file_download",
|
|
611
|
+
props: {
|
|
612
|
+
file_name: scrubText(decodeURIComponent((_a = u.pathname.split("/").pop()) != null ? _a : ""), 100),
|
|
613
|
+
file_extension: m[1].toLowerCase(),
|
|
614
|
+
link_url: `${u.origin}${u.pathname}`
|
|
615
|
+
}
|
|
616
|
+
};
|
|
617
|
+
if (opts.outbound && u.hostname !== page.hostname)
|
|
618
|
+
return { event: "$outbound_click", props: { link_domain: u.hostname, link_url: `${u.origin}${u.pathname}` } };
|
|
619
|
+
return null;
|
|
620
|
+
}
|
|
621
|
+
function siteSearchTerm(href, params = ["q", "s", "search", "query"]) {
|
|
622
|
+
try {
|
|
623
|
+
const u = new URL(href);
|
|
624
|
+
for (const p of params) {
|
|
625
|
+
const v = u.searchParams.get(p);
|
|
626
|
+
if (v && v.trim()) return scrubText(v.trim(), 100);
|
|
627
|
+
}
|
|
628
|
+
} catch {
|
|
629
|
+
}
|
|
630
|
+
return null;
|
|
631
|
+
}
|
|
632
|
+
function scrollMarks(fraction, already) {
|
|
633
|
+
return [25, 50, 75, 90].filter((p) => fraction * 100 >= p && !already.has(p));
|
|
634
|
+
}
|
|
635
|
+
function asEl(t) {
|
|
636
|
+
return t && typeof t.tagName === "string" ? t : null;
|
|
637
|
+
}
|
|
638
|
+
function installEnhanced(client, win, opts = {}) {
|
|
639
|
+
const doc = win.document;
|
|
640
|
+
const on = (k) => opts[k] !== false;
|
|
641
|
+
const off = [];
|
|
642
|
+
const listen = (t, type, fn, capture = true) => {
|
|
643
|
+
t.addEventListener(type, fn, { capture, passive: true });
|
|
644
|
+
off.push(() => t.removeEventListener(type, fn, { capture }));
|
|
645
|
+
};
|
|
646
|
+
let page = win.location.href;
|
|
647
|
+
let marks = /* @__PURE__ */ new Set();
|
|
648
|
+
const forms = /* @__PURE__ */ new WeakSet();
|
|
649
|
+
const newPage = () => {
|
|
650
|
+
if (win.location.href === page) return;
|
|
651
|
+
page = win.location.href;
|
|
652
|
+
marks = /* @__PURE__ */ new Set();
|
|
653
|
+
search();
|
|
654
|
+
};
|
|
655
|
+
const search = () => {
|
|
656
|
+
if (!on("siteSearch")) return;
|
|
657
|
+
const p = typeof opts.siteSearch === "object" ? opts.siteSearch.params : void 0;
|
|
658
|
+
const term = siteSearchTerm(win.location.href, p);
|
|
659
|
+
if (term) client.track("$site_search", { search_term: term });
|
|
660
|
+
};
|
|
661
|
+
search();
|
|
662
|
+
listen(win, "popstate", () => setTimeout(newPage, 0));
|
|
663
|
+
const iv = win.setInterval(newPage, 1e3);
|
|
664
|
+
off.push(() => win.clearInterval(iv));
|
|
665
|
+
if (on("scroll"))
|
|
666
|
+
listen(win, "scroll", () => {
|
|
667
|
+
const el = doc.documentElement;
|
|
668
|
+
const total = Math.max(el.scrollHeight, 1);
|
|
669
|
+
for (const p of scrollMarks((win.scrollY + win.innerHeight) / total, marks)) {
|
|
670
|
+
marks.add(p);
|
|
671
|
+
client.track("$scroll", { percent_scrolled: p });
|
|
672
|
+
}
|
|
673
|
+
});
|
|
674
|
+
if (on("outbound") || on("downloads"))
|
|
675
|
+
listen(doc, "click", (e) => {
|
|
676
|
+
var _a, _b;
|
|
677
|
+
let a = asEl(e.target);
|
|
678
|
+
while (a && a.tagName.toLowerCase() !== "a") a = (_a = a.parentElement) != null ? _a : null;
|
|
679
|
+
if (!a || optedOut(a)) return;
|
|
680
|
+
const ev = linkEvent((_b = a.getAttribute("href")) != null ? _b : "", win.location.href, {
|
|
681
|
+
outbound: on("outbound"),
|
|
682
|
+
downloads: on("downloads")
|
|
683
|
+
});
|
|
684
|
+
if (ev) client.track(ev.event, ev.props);
|
|
685
|
+
});
|
|
686
|
+
if (on("forms")) {
|
|
687
|
+
const formProps = (f) => {
|
|
688
|
+
var _a, _b;
|
|
689
|
+
return {
|
|
690
|
+
...f.id ? { form_id: scrubText(f.id, 64) } : {},
|
|
691
|
+
...f.getAttribute("name") ? { form_name: scrubText((_a = f.getAttribute("name")) != null ? _a : "", 64) } : {},
|
|
692
|
+
form_destination: originPath((_b = f.getAttribute("action")) != null ? _b : "", win.location.href)
|
|
693
|
+
};
|
|
694
|
+
};
|
|
695
|
+
listen(doc, "focusin", (e) => {
|
|
696
|
+
var _a;
|
|
697
|
+
let f = asEl(e.target);
|
|
698
|
+
while (f && f.tagName.toLowerCase() !== "form") f = (_a = f.parentElement) != null ? _a : null;
|
|
699
|
+
if (!f || forms.has(f) || optedOut(f)) return;
|
|
700
|
+
forms.add(f);
|
|
701
|
+
client.track("$form_start", formProps(f));
|
|
702
|
+
});
|
|
703
|
+
listen(doc, "submit", (e) => {
|
|
704
|
+
const f = asEl(e.target);
|
|
705
|
+
if (f && !optedOut(f)) client.track("$form_submit", formProps(f));
|
|
706
|
+
});
|
|
707
|
+
}
|
|
708
|
+
if (on("video")) {
|
|
709
|
+
const progress = /* @__PURE__ */ new WeakMap();
|
|
710
|
+
const props = (v) => ({
|
|
711
|
+
video_url: originPath(v.currentSrc || v.src, win.location.href),
|
|
712
|
+
...v.title ? { video_title: scrubText(v.title, 100) } : {}
|
|
713
|
+
});
|
|
714
|
+
const isVideo = (t) => !!t && t.tagName === "VIDEO" && !optedOut(t);
|
|
715
|
+
listen(doc, "play", (e) => {
|
|
716
|
+
if (isVideo(e.target) && !progress.has(e.target)) {
|
|
717
|
+
progress.set(e.target, /* @__PURE__ */ new Set());
|
|
718
|
+
client.track("$video_start", props(e.target));
|
|
719
|
+
}
|
|
720
|
+
});
|
|
721
|
+
listen(doc, "timeupdate", (e) => {
|
|
722
|
+
var _a;
|
|
723
|
+
const v = e.target;
|
|
724
|
+
if (!isVideo(v) || !v.duration || !Number.isFinite(v.duration)) return;
|
|
725
|
+
const done = (_a = progress.get(v)) != null ? _a : /* @__PURE__ */ new Set();
|
|
726
|
+
progress.set(v, done);
|
|
727
|
+
for (const p of [10, 25, 50, 75])
|
|
728
|
+
if (v.currentTime / v.duration * 100 >= p && !done.has(p)) {
|
|
729
|
+
done.add(p);
|
|
730
|
+
client.track("$video_progress", { ...props(v), video_percent: p });
|
|
731
|
+
}
|
|
732
|
+
});
|
|
733
|
+
listen(doc, "ended", (e) => isVideo(e.target) && client.track("$video_complete", props(e.target)));
|
|
734
|
+
}
|
|
735
|
+
return () => off.forEach((f) => f());
|
|
736
|
+
}
|
|
737
|
+
function installAutocapture(client, win, opts = {}) {
|
|
738
|
+
const fn = (e) => {
|
|
739
|
+
var _a;
|
|
740
|
+
const t = asEl(e.target);
|
|
741
|
+
if (t && ((_a = opts.ignore) == null ? void 0 : _a.length)) {
|
|
742
|
+
const el = t;
|
|
743
|
+
if (opts.ignore.some((s) => typeof el.closest === "function" && el.closest(s))) return;
|
|
744
|
+
}
|
|
745
|
+
const props = autocaptureProps(t, win.location.href);
|
|
746
|
+
if (props) client.track("$autocapture", props);
|
|
747
|
+
};
|
|
748
|
+
win.document.addEventListener("click", fn, { capture: true, passive: true });
|
|
749
|
+
return () => win.document.removeEventListener("click", fn, { capture: true });
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
// src/errors.ts
|
|
753
|
+
var V8 = /^\s*at\s+(?:(.*?)\s+\()?(.+?):(\d+):(\d+)\)?\s*$/;
|
|
754
|
+
var GECKO = /^\s*(.*?)@(.+?):(\d+):(\d+)\s*$/;
|
|
755
|
+
function normalizeStack(stack) {
|
|
756
|
+
var _a, _b;
|
|
757
|
+
const out = [];
|
|
758
|
+
for (const raw of (stack != null ? stack : "").split("\n")) {
|
|
759
|
+
const m = (_a = V8.exec(raw)) != null ? _a : GECKO.exec(raw);
|
|
760
|
+
if (!m) continue;
|
|
761
|
+
const file = /^https?:/.test(m[2]) ? originPath(m[2]) : m[2].split(/[?#]/)[0];
|
|
762
|
+
out.push({ fn: scrubText((_b = m[1]) != null ? _b : "", 100), file: file.slice(0, 300), line: Number(m[3]), col: Number(m[4]) });
|
|
763
|
+
if (out.length >= 30) break;
|
|
764
|
+
}
|
|
765
|
+
return out;
|
|
766
|
+
}
|
|
767
|
+
function formatFrames(frames) {
|
|
768
|
+
return frames.map((f) => ` at ${f.fn || "<anonima>"} (${f.file}:${f.line}:${f.col})`).join("\n");
|
|
769
|
+
}
|
|
770
|
+
function fnv1a64(s) {
|
|
771
|
+
let a = 2166136261;
|
|
772
|
+
let b = 2671212586;
|
|
773
|
+
for (let i = 0; i < s.length; i++) {
|
|
774
|
+
const c = s.charCodeAt(i);
|
|
775
|
+
a = Math.imul(a ^ c, 16777619) >>> 0;
|
|
776
|
+
b = Math.imul(b ^ c, 16777619) >>> 0;
|
|
777
|
+
}
|
|
778
|
+
return a.toString(16).padStart(8, "0") + b.toString(16).padStart(8, "0");
|
|
779
|
+
}
|
|
780
|
+
function normalizeMessage(message) {
|
|
781
|
+
return scrubText(message, 200).replace(/(["'`]).*?\1/g, "<s>").replace(/\d+/g, "<n>").trim();
|
|
782
|
+
}
|
|
783
|
+
function fingerprint(type, message, frames) {
|
|
784
|
+
const top = frames.slice(0, 3).map(
|
|
785
|
+
(f) => {
|
|
786
|
+
var _a, _b;
|
|
787
|
+
return `${(_b = (_a = f.file.split("/").pop()) == null ? void 0 : _a.replace(/[.-][0-9a-f]{6,}(?=\.)/g, "")) != null ? _b : ""}:${f.fn}`;
|
|
788
|
+
}
|
|
789
|
+
).join("|");
|
|
790
|
+
return fnv1a64(`${type}|${normalizeMessage(message)}|${top}`);
|
|
791
|
+
}
|
|
792
|
+
function exceptionProps(err, handled, release) {
|
|
793
|
+
const e = err instanceof Error ? err : null;
|
|
794
|
+
const type = ((e == null ? void 0 : e.name) || (typeof err === "object" && err ? "Object" : typeof err) || "Error").slice(0, 100);
|
|
795
|
+
const raw = e ? e.message : typeof err === "string" ? err : (() => {
|
|
796
|
+
var _a;
|
|
797
|
+
try {
|
|
798
|
+
return (_a = JSON.stringify(err)) != null ? _a : String(err);
|
|
799
|
+
} catch {
|
|
800
|
+
return String(err);
|
|
801
|
+
}
|
|
802
|
+
})();
|
|
803
|
+
const message = scrubText(raw != null ? raw : "", 300);
|
|
804
|
+
const frames = normalizeStack(e == null ? void 0 : e.stack);
|
|
805
|
+
return {
|
|
806
|
+
type,
|
|
807
|
+
message,
|
|
808
|
+
stack: formatFrames(frames).slice(0, 4e3),
|
|
809
|
+
fingerprint: fingerprint(type, message, frames),
|
|
810
|
+
handled,
|
|
811
|
+
...release ? { release: release.slice(0, 100) } : {}
|
|
812
|
+
};
|
|
813
|
+
}
|
|
814
|
+
var ErrorGate = class {
|
|
815
|
+
constructor(opts, sampled) {
|
|
816
|
+
this.opts = opts;
|
|
817
|
+
this.sampled = sampled;
|
|
818
|
+
__publicField(this, "seen", /* @__PURE__ */ new Set());
|
|
819
|
+
__publicField(this, "count", 0);
|
|
820
|
+
}
|
|
821
|
+
/** `true` se l'errore va mandato (campionamento, tetto, una volta per impronta, messaggi ignorati). */
|
|
822
|
+
admit(props) {
|
|
823
|
+
var _a, _b, _c, _d;
|
|
824
|
+
if (!this.sampled) return false;
|
|
825
|
+
const fp = String((_a = props.fingerprint) != null ? _a : "");
|
|
826
|
+
const msg = String((_b = props.message) != null ? _b : "");
|
|
827
|
+
if (((_c = this.opts.ignore) != null ? _c : []).some((r) => r.test(msg))) return false;
|
|
828
|
+
if (this.seen.has(fp) || this.count >= ((_d = this.opts.maxPerPage) != null ? _d : 10)) return false;
|
|
829
|
+
this.seen.add(fp);
|
|
830
|
+
this.count++;
|
|
831
|
+
return true;
|
|
832
|
+
}
|
|
833
|
+
};
|
|
834
|
+
function captureException(client, gate, err, handled = true, release) {
|
|
835
|
+
const props = exceptionProps(err, handled, release);
|
|
836
|
+
if (gate.admit(props)) client.track("$exception", props);
|
|
837
|
+
}
|
|
838
|
+
function installErrors(client, win, opts = {}, random = Math.random) {
|
|
839
|
+
var _a;
|
|
840
|
+
const gate = new ErrorGate(opts, random() < ((_a = opts.sampleRate) != null ? _a : 1));
|
|
841
|
+
const onError = (ev) => {
|
|
842
|
+
var _a2, _b;
|
|
843
|
+
if (!ev.error && /^Script error\.?$/.test((_a2 = ev.message) != null ? _a2 : "")) return;
|
|
844
|
+
captureException(client, gate, (_b = ev.error) != null ? _b : ev.message, false, opts.release);
|
|
845
|
+
};
|
|
846
|
+
const onRejection = (ev) => captureException(client, gate, ev.reason, false, opts.release);
|
|
847
|
+
win.addEventListener("error", onError);
|
|
848
|
+
win.addEventListener("unhandledrejection", onRejection);
|
|
849
|
+
return {
|
|
850
|
+
capture: (err) => captureException(client, gate, err, true, opts.release),
|
|
851
|
+
uninstall: () => {
|
|
852
|
+
win.removeEventListener("error", onError);
|
|
853
|
+
win.removeEventListener("unhandledrejection", onRejection);
|
|
854
|
+
}
|
|
855
|
+
};
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
// src/vitals.ts
|
|
859
|
+
var T = { lcp: [2500, 4e3], inp: [200, 500], cls: [0.1, 0.25] };
|
|
860
|
+
function rateVitals(v) {
|
|
861
|
+
let worst = -1;
|
|
862
|
+
for (const k of ["lcp", "inp", "cls"]) {
|
|
863
|
+
const x = v[k];
|
|
864
|
+
if (x === null) continue;
|
|
865
|
+
worst = Math.max(worst, x <= T[k][0] ? 0 : x <= T[k][1] ? 1 : 2);
|
|
866
|
+
}
|
|
867
|
+
return worst < 0 ? null : ["good", "needs-improvement", "poor"][worst];
|
|
868
|
+
}
|
|
869
|
+
var ClsWindow = class {
|
|
870
|
+
constructor() {
|
|
871
|
+
__publicField(this, "current", 0);
|
|
872
|
+
__publicField(this, "first", 0);
|
|
873
|
+
__publicField(this, "last", 0);
|
|
874
|
+
__publicField(this, "value", 0);
|
|
875
|
+
}
|
|
876
|
+
add(time, shift) {
|
|
877
|
+
if (this.current && time - this.last < 1e3 && time - this.first < 5e3) this.current += shift;
|
|
878
|
+
else {
|
|
879
|
+
this.current = shift;
|
|
880
|
+
this.first = time;
|
|
881
|
+
}
|
|
882
|
+
this.last = time;
|
|
883
|
+
this.value = Math.max(this.value, this.current);
|
|
884
|
+
}
|
|
885
|
+
};
|
|
886
|
+
function inpOf(durations) {
|
|
887
|
+
if (!durations.length) return null;
|
|
888
|
+
const sorted = [...durations].sort((a, b) => b - a);
|
|
889
|
+
return sorted[Math.min(sorted.length - 1, Math.floor(durations.length / 50))];
|
|
890
|
+
}
|
|
891
|
+
function installWebVitals(client, win, opts = {}, random = Math.random) {
|
|
892
|
+
var _a, _b, _c, _d;
|
|
893
|
+
const PO = win.PerformanceObserver;
|
|
894
|
+
if (!PO || random() >= ((_a = opts.sampleRate) != null ? _a : 0.1)) return () => void 0;
|
|
895
|
+
const v = { lcp: null, inp: null, cls: null, ttfb: null };
|
|
896
|
+
const cls = new ClsWindow();
|
|
897
|
+
const interactions = /* @__PURE__ */ new Map();
|
|
898
|
+
const observers = [];
|
|
899
|
+
const observe = (type, fn, extra = {}) => {
|
|
900
|
+
try {
|
|
901
|
+
const o = new PO((list) => list.getEntries().forEach((e) => fn(e)));
|
|
902
|
+
o.observe({ type, buffered: true, ...extra });
|
|
903
|
+
observers.push(o);
|
|
904
|
+
} catch {
|
|
905
|
+
}
|
|
906
|
+
};
|
|
907
|
+
observe("largest-contentful-paint", (e) => v.lcp = Math.round(e.startTime));
|
|
908
|
+
observe("layout-shift", (e) => {
|
|
909
|
+
if (!e.hadRecentInput && typeof e.value === "number") {
|
|
910
|
+
cls.add(e.startTime, e.value);
|
|
911
|
+
v.cls = Math.round(cls.value * 1e4) / 1e4;
|
|
912
|
+
}
|
|
913
|
+
});
|
|
914
|
+
observe(
|
|
915
|
+
"event",
|
|
916
|
+
(e) => {
|
|
917
|
+
var _a2;
|
|
918
|
+
if (!e.interactionId) return;
|
|
919
|
+
interactions.set(e.interactionId, Math.max((_a2 = interactions.get(e.interactionId)) != null ? _a2 : 0, e.duration));
|
|
920
|
+
if (interactions.size > 500) interactions.delete(interactions.keys().next().value);
|
|
921
|
+
v.inp = inpOf([...interactions.values()]);
|
|
922
|
+
},
|
|
923
|
+
{ durationThreshold: 40 }
|
|
924
|
+
);
|
|
925
|
+
try {
|
|
926
|
+
const nav = (_d = (_c = (_b = win.performance) == null ? void 0 : _b.getEntriesByType) == null ? void 0 : _c.call(_b, "navigation")) == null ? void 0 : _d[0];
|
|
927
|
+
if (nav && typeof nav.responseStart === "number" && nav.responseStart > 0) v.ttfb = Math.round(nav.responseStart);
|
|
928
|
+
} catch {
|
|
929
|
+
}
|
|
930
|
+
let sent = false;
|
|
931
|
+
const report = () => {
|
|
932
|
+
if (sent || v.lcp === null && v.cls === null && v.inp === null && v.ttfb === null) return;
|
|
933
|
+
sent = true;
|
|
934
|
+
const rating = rateVitals(v);
|
|
935
|
+
client.track("$web_vitals", rating ? { vital_rating: rating } : void 0, { perf: { ...v } });
|
|
936
|
+
};
|
|
937
|
+
const onHide = () => win.document.visibilityState === "hidden" && report();
|
|
938
|
+
win.document.addEventListener("visibilitychange", onHide);
|
|
939
|
+
win.addEventListener("pagehide", report);
|
|
940
|
+
return () => {
|
|
941
|
+
observers.forEach((o) => o.disconnect());
|
|
942
|
+
win.document.removeEventListener("visibilitychange", onHide);
|
|
943
|
+
win.removeEventListener("pagehide", report);
|
|
944
|
+
};
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
// src/plugins.ts
|
|
948
|
+
function installPlugins(client, win, opts) {
|
|
949
|
+
const off = [];
|
|
950
|
+
let capture = () => void 0;
|
|
951
|
+
const conf = (v) => v ? v === true ? {} : v : null;
|
|
952
|
+
const errors = conf(opts.errors);
|
|
953
|
+
if (errors) {
|
|
954
|
+
const e = installErrors(client, win, errors);
|
|
955
|
+
capture = e.capture;
|
|
956
|
+
off.push(e.uninstall);
|
|
957
|
+
}
|
|
958
|
+
const vitals = conf(opts.webVitals);
|
|
959
|
+
if (vitals) off.push(installWebVitals(client, win, vitals));
|
|
960
|
+
const enhanced = conf(opts.enhanced);
|
|
961
|
+
if (enhanced) off.push(installEnhanced(client, win, enhanced));
|
|
962
|
+
const auto = conf(opts.autocapture);
|
|
963
|
+
if (auto) off.push(installAutocapture(client, win, auto));
|
|
964
|
+
return { captureException: (err) => capture(err), uninstall: () => off.forEach((f) => f()) };
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
// src/flags.ts
|
|
968
|
+
function fnv1a(s) {
|
|
969
|
+
let h = 2166136261;
|
|
970
|
+
for (let i = 0; i < s.length; i++) {
|
|
971
|
+
h ^= s.charCodeAt(i);
|
|
972
|
+
h = Math.imul(h, 16777619) >>> 0;
|
|
973
|
+
}
|
|
974
|
+
return h >>> 0;
|
|
975
|
+
}
|
|
976
|
+
function fmix32(h) {
|
|
977
|
+
h ^= h >>> 16;
|
|
978
|
+
h = Math.imul(h, 2246822507) >>> 0;
|
|
979
|
+
h ^= h >>> 13;
|
|
980
|
+
h = Math.imul(h, 3266489909) >>> 0;
|
|
981
|
+
h ^= h >>> 16;
|
|
982
|
+
return h >>> 0;
|
|
983
|
+
}
|
|
984
|
+
function bucket(s) {
|
|
985
|
+
return fmix32(fnv1a(s)) / 4294967296;
|
|
986
|
+
}
|
|
987
|
+
function matches(c, attrs) {
|
|
988
|
+
var _a, _b;
|
|
989
|
+
const v = (_a = attrs[c.attribute.startsWith("attr:") ? c.attribute.slice(5) : c.attribute]) != null ? _a : "";
|
|
990
|
+
switch (c.op) {
|
|
991
|
+
case "eq":
|
|
992
|
+
return v === c.values[0];
|
|
993
|
+
case "neq":
|
|
994
|
+
return v !== c.values[0];
|
|
995
|
+
case "in":
|
|
996
|
+
return c.values.includes(v);
|
|
997
|
+
case "not_in":
|
|
998
|
+
return !c.values.includes(v);
|
|
999
|
+
case "contains":
|
|
1000
|
+
return v.toLowerCase().includes(((_b = c.values[0]) != null ? _b : "").toLowerCase());
|
|
1001
|
+
default:
|
|
1002
|
+
return false;
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
function evaluateFlag(def, attrs, unit) {
|
|
1006
|
+
var _a, _b;
|
|
1007
|
+
if (!def) return void 0;
|
|
1008
|
+
if (!def.enabled) return def.defaultValue;
|
|
1009
|
+
for (const r of (_a = def.rules) != null ? _a : []) {
|
|
1010
|
+
if (!((_b = r.conditions) != null ? _b : []).every((c) => matches(c, attrs))) continue;
|
|
1011
|
+
if (r.rollout >= 100) return r.value;
|
|
1012
|
+
if (r.rollout <= 0 || !unit) continue;
|
|
1013
|
+
if (bucket(`${def.key}:${unit}`) * 100 < r.rollout) return r.value;
|
|
1014
|
+
}
|
|
1015
|
+
return def.defaultValue;
|
|
1016
|
+
}
|
|
1017
|
+
function assignVariant(def, unit) {
|
|
1018
|
+
if (!unit || !def.variants.length) return null;
|
|
1019
|
+
const total = def.variants.reduce((a, v) => a + Math.max(0, v.weight), 0);
|
|
1020
|
+
if (total <= 0) return null;
|
|
1021
|
+
let x = bucket(`${def.seed}:${unit}`) * total;
|
|
1022
|
+
for (const v of def.variants) {
|
|
1023
|
+
x -= Math.max(0, v.weight);
|
|
1024
|
+
if (x < 0) return v.key;
|
|
1025
|
+
}
|
|
1026
|
+
return def.variants[def.variants.length - 1].key;
|
|
1027
|
+
}
|
|
1028
|
+
var AuralyticsFlags = class {
|
|
1029
|
+
constructor(host, opts) {
|
|
1030
|
+
this.host = host;
|
|
1031
|
+
this.opts = opts;
|
|
1032
|
+
__publicField(this, "payload", { flags: [], experiments: [] });
|
|
1033
|
+
__publicField(this, "etag", "");
|
|
1034
|
+
__publicField(this, "exposed", /* @__PURE__ */ new Set());
|
|
1035
|
+
__publicField(this, "listeners", /* @__PURE__ */ new Set());
|
|
1036
|
+
__publicField(this, "attrs");
|
|
1037
|
+
var _a, _b, _c, _d;
|
|
1038
|
+
this.attrs = { ...(_a = opts.attributes) != null ? _a : {} };
|
|
1039
|
+
const every = (_b = opts.setInterval) != null ? _b : ((fn, ms) => setInterval(fn, ms));
|
|
1040
|
+
every(() => void this.refresh(), Math.max(15e3, (_c = opts.pollMs) != null ? _c : 6e4));
|
|
1041
|
+
(_d = opts.realtime) == null ? void 0 : _d.subscribe(() => void this.refresh());
|
|
1042
|
+
}
|
|
1043
|
+
/** Rilegge le definizioni (con `If-None-Match`). `true` se sono cambiate. */
|
|
1044
|
+
async refresh() {
|
|
1045
|
+
var _a, _b;
|
|
1046
|
+
const f = (_a = this.opts.fetch) != null ? _a : ((u, i) => fetch(u, i));
|
|
1047
|
+
try {
|
|
1048
|
+
const r = await f(`${this.host.collectorEndpoint}/c/v1/flags?k=${encodeURIComponent(this.opts.stream)}`, {
|
|
1049
|
+
headers: this.etag ? { "if-none-match": this.etag } : {}
|
|
1050
|
+
});
|
|
1051
|
+
if (r.status !== 200) return false;
|
|
1052
|
+
const body = await r.json();
|
|
1053
|
+
if (!body || !Array.isArray(body.flags) || !Array.isArray(body.experiments)) return false;
|
|
1054
|
+
this.payload = body;
|
|
1055
|
+
this.etag = (_b = r.headers.get("etag")) != null ? _b : "";
|
|
1056
|
+
this.listeners.forEach((l) => l());
|
|
1057
|
+
return true;
|
|
1058
|
+
} catch {
|
|
1059
|
+
return false;
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
setAttributes(attrs) {
|
|
1063
|
+
this.attrs = { ...attrs };
|
|
1064
|
+
}
|
|
1065
|
+
onChange(fn) {
|
|
1066
|
+
this.listeners.add(fn);
|
|
1067
|
+
return () => this.listeners.delete(fn);
|
|
1068
|
+
}
|
|
1069
|
+
unit() {
|
|
1070
|
+
var _a, _b;
|
|
1071
|
+
return (_b = (_a = this.host.bucketingId()) != null ? _a : this.opts.bucketingKey) != null ? _b : null;
|
|
1072
|
+
}
|
|
1073
|
+
value(key) {
|
|
1074
|
+
return evaluateFlag(
|
|
1075
|
+
this.payload.flags.find((f) => f.key === key),
|
|
1076
|
+
this.attrs,
|
|
1077
|
+
this.unit()
|
|
1078
|
+
);
|
|
1079
|
+
}
|
|
1080
|
+
isOn(key) {
|
|
1081
|
+
return this.value(key) === true;
|
|
1082
|
+
}
|
|
1083
|
+
/** La variante dell'esperimento in corso (`null` se non c'è o senza unità: l'app mostra il controllo). Manda l'esposizione una volta. */
|
|
1084
|
+
variant(key) {
|
|
1085
|
+
const def = this.payload.experiments.find((e) => e.key === key);
|
|
1086
|
+
if (!def) return null;
|
|
1087
|
+
const v = assignVariant(def, this.unit());
|
|
1088
|
+
if (v && !this.exposed.has(key)) {
|
|
1089
|
+
this.exposed.add(key);
|
|
1090
|
+
this.host.track("$exposure", { experiment: key, variant: v });
|
|
1091
|
+
}
|
|
1092
|
+
return v;
|
|
1093
|
+
}
|
|
1094
|
+
};
|
|
1095
|
+
|
|
1096
|
+
// src/consent/tcf.ts
|
|
1097
|
+
function tcfState(d, analyticsPurposes = [1, 8, 9], vendorId, trustGdprApplies = false) {
|
|
1098
|
+
var _a, _b, _c;
|
|
1099
|
+
const v = (b) => b ? "granted" : "denied";
|
|
1100
|
+
if (d.gdprApplies === false && trustGdprApplies)
|
|
1101
|
+
return {
|
|
1102
|
+
analytics_storage: "granted",
|
|
1103
|
+
ad_storage: "granted",
|
|
1104
|
+
ad_user_data: "granted",
|
|
1105
|
+
ad_personalization: "granted"
|
|
1106
|
+
};
|
|
1107
|
+
const pub = (_a = d.publisher) == null ? void 0 : _a.consents;
|
|
1108
|
+
const usePublisher = vendorId === void 0 && !!pub && Object.keys(pub).length > 0;
|
|
1109
|
+
const vendorOk = vendorId === void 0 || ((_c = (_b = d.vendor) == null ? void 0 : _b.consents) == null ? void 0 : _c[vendorId]) === true;
|
|
1110
|
+
const has = (...ps) => vendorOk && ps.every((p) => {
|
|
1111
|
+
var _a2, _b2;
|
|
1112
|
+
return (usePublisher ? pub == null ? void 0 : pub[p] : (_b2 = (_a2 = d.purpose) == null ? void 0 : _a2.consents) == null ? void 0 : _b2[p]) === true;
|
|
1113
|
+
});
|
|
1114
|
+
return {
|
|
1115
|
+
analytics_storage: v(analyticsPurposes.length > 0 && has(...analyticsPurposes)),
|
|
1116
|
+
ad_storage: v(has(1)),
|
|
1117
|
+
ad_user_data: v(has(1, 7)),
|
|
1118
|
+
ad_personalization: v(has(3, 4))
|
|
1119
|
+
};
|
|
1120
|
+
}
|
|
1121
|
+
function tcf(opts = {}) {
|
|
1122
|
+
var _a;
|
|
1123
|
+
const purposes = ((_a = opts.analyticsPurposes) == null ? void 0 : _a.length) ? opts.analyticsPurposes : [1, 8, 9];
|
|
1124
|
+
return {
|
|
1125
|
+
name: "tcf",
|
|
1126
|
+
subscribe(update, e) {
|
|
1127
|
+
const env = consentEnv(e);
|
|
1128
|
+
let api;
|
|
1129
|
+
let listenerId;
|
|
1130
|
+
let done = false;
|
|
1131
|
+
const cb = (d, ok) => {
|
|
1132
|
+
if (done || !ok || !d) return;
|
|
1133
|
+
if (typeof d.listenerId === "number") listenerId = d.listenerId;
|
|
1134
|
+
if (d.eventStatus !== "tcloaded" && d.eventStatus !== "useractioncomplete") return;
|
|
1135
|
+
update(tcfState(d, purposes, opts.vendorId, opts.trustGdprApplies === true));
|
|
1136
|
+
};
|
|
1137
|
+
const stop = waitFor(
|
|
1138
|
+
env,
|
|
1139
|
+
() => typeof env.win.__tcfapi === "function",
|
|
1140
|
+
() => {
|
|
1141
|
+
api = env.win.__tcfapi;
|
|
1142
|
+
api("addEventListener", 2, cb);
|
|
1143
|
+
},
|
|
1144
|
+
opts.timeoutMs
|
|
1145
|
+
);
|
|
1146
|
+
return () => {
|
|
1147
|
+
done = true;
|
|
1148
|
+
stop();
|
|
1149
|
+
if (api && listenerId !== void 0) {
|
|
1150
|
+
try {
|
|
1151
|
+
api("removeEventListener", 2, () => void 0, listenerId);
|
|
1152
|
+
} catch {
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
};
|
|
1156
|
+
}
|
|
1157
|
+
};
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
// src/consent/iubenda.ts
|
|
1161
|
+
function iubendaState(pref, analyticsPurpose = 4, adsPurpose = 5) {
|
|
1162
|
+
if (!pref || typeof pref !== "object") return null;
|
|
1163
|
+
const p = pref;
|
|
1164
|
+
if (p.purposes && typeof p.purposes === "object" && Object.keys(p.purposes).length > 0)
|
|
1165
|
+
return fromCategories(p.purposes[analyticsPurpose] === true, p.purposes[adsPurpose] === true);
|
|
1166
|
+
if (typeof p.consent === "boolean") return fromCategories(p.consent, p.consent);
|
|
1167
|
+
return null;
|
|
1168
|
+
}
|
|
1169
|
+
var CALLBACKS = ["onPreferenceExpressed", "onConsentRead", "onConsentGiven", "onConsentRejected"];
|
|
1170
|
+
function iubenda(opts = {}) {
|
|
1171
|
+
var _a, _b, _c;
|
|
1172
|
+
const a = (_a = opts.analyticsPurpose) != null ? _a : 4;
|
|
1173
|
+
const ad = (_b = opts.adsPurpose) != null ? _b : 5;
|
|
1174
|
+
const pollMs = (_c = opts.pollMs) != null ? _c : 2e3;
|
|
1175
|
+
return {
|
|
1176
|
+
name: "iubenda",
|
|
1177
|
+
subscribe(update, e) {
|
|
1178
|
+
const env = consentEnv(e);
|
|
1179
|
+
let last = "";
|
|
1180
|
+
let done = false;
|
|
1181
|
+
let timer;
|
|
1182
|
+
const apply = (s) => {
|
|
1183
|
+
if (done || !s) return;
|
|
1184
|
+
const key = JSON.stringify(s);
|
|
1185
|
+
if (key === last) return;
|
|
1186
|
+
last = key;
|
|
1187
|
+
update(s);
|
|
1188
|
+
};
|
|
1189
|
+
const current = () => {
|
|
1190
|
+
var _a2, _b2, _c2;
|
|
1191
|
+
const cs = (_a2 = env.win._iub) == null ? void 0 : _a2.cs;
|
|
1192
|
+
try {
|
|
1193
|
+
const fromApi = (_c2 = (_b2 = cs == null ? void 0 : cs.api) == null ? void 0 : _b2.getPreferences) == null ? void 0 : _c2.call(_b2);
|
|
1194
|
+
if (fromApi) return fromApi;
|
|
1195
|
+
} catch {
|
|
1196
|
+
}
|
|
1197
|
+
return cs == null ? void 0 : cs.consent;
|
|
1198
|
+
};
|
|
1199
|
+
let originals = {};
|
|
1200
|
+
let cbs;
|
|
1201
|
+
try {
|
|
1202
|
+
const iub = env.win._iub = env.win._iub || [];
|
|
1203
|
+
const conf = iub.csConfiguration = iub.csConfiguration || {};
|
|
1204
|
+
const target = cbs = conf.callback = conf.callback || {};
|
|
1205
|
+
originals = Object.fromEntries(CALLBACKS.map((k) => [k, target[k]]));
|
|
1206
|
+
for (const k of CALLBACKS) {
|
|
1207
|
+
const orig = originals[k];
|
|
1208
|
+
target[k] = function(...args) {
|
|
1209
|
+
var _a2, _b2, _c2, _d;
|
|
1210
|
+
try {
|
|
1211
|
+
if (k === "onPreferenceExpressed") apply((_a2 = iubendaState(args[0], a, ad)) != null ? _a2 : iubendaState(current(), a, ad));
|
|
1212
|
+
else if (k === "onConsentRead") apply(iubendaState(current(), a, ad));
|
|
1213
|
+
else {
|
|
1214
|
+
const perPurpose = ((_c2 = (_b2 = env.win._iub) == null ? void 0 : _b2.csConfiguration) == null ? void 0 : _c2.perPurposeConsent) === true;
|
|
1215
|
+
const given = k === "onConsentGiven" && !perPurpose;
|
|
1216
|
+
apply((_d = iubendaState(current(), a, ad)) != null ? _d : fromCategories(given, given));
|
|
1217
|
+
}
|
|
1218
|
+
} catch {
|
|
1219
|
+
}
|
|
1220
|
+
return typeof orig === "function" ? orig.apply(this, args) : void 0;
|
|
1221
|
+
};
|
|
1222
|
+
}
|
|
1223
|
+
} catch {
|
|
1224
|
+
}
|
|
1225
|
+
const poll = () => {
|
|
1226
|
+
if (done) return;
|
|
1227
|
+
try {
|
|
1228
|
+
apply(iubendaState(current(), a, ad));
|
|
1229
|
+
} catch {
|
|
1230
|
+
}
|
|
1231
|
+
if (pollMs > 0) timer = env.setTimeout(poll, pollMs);
|
|
1232
|
+
};
|
|
1233
|
+
poll();
|
|
1234
|
+
return () => {
|
|
1235
|
+
done = true;
|
|
1236
|
+
if (timer !== void 0) env.clearTimeout(timer);
|
|
1237
|
+
if (cbs) for (const k of CALLBACKS) cbs[k] = originals[k];
|
|
1238
|
+
};
|
|
1239
|
+
}
|
|
1240
|
+
};
|
|
1241
|
+
}
|
|
1242
|
+
|
|
1243
|
+
// src/consent/cookiebot.ts
|
|
1244
|
+
var EVENTS = ["CookiebotOnConsentReady", "CookiebotOnAccept", "CookiebotOnDecline", "CookiebotOnLoad"];
|
|
1245
|
+
function cookiebot(opts = {}) {
|
|
1246
|
+
var _a, _b;
|
|
1247
|
+
const a = (_a = opts.analyticsCategory) != null ? _a : "statistics";
|
|
1248
|
+
const ad = (_b = opts.adsCategory) != null ? _b : "marketing";
|
|
1249
|
+
return {
|
|
1250
|
+
name: "cookiebot",
|
|
1251
|
+
subscribe(update, e) {
|
|
1252
|
+
var _a2, _b2;
|
|
1253
|
+
const env = consentEnv(e);
|
|
1254
|
+
const read = () => {
|
|
1255
|
+
var _a3;
|
|
1256
|
+
try {
|
|
1257
|
+
const c = (_a3 = env.win.Cookiebot) == null ? void 0 : _a3.consent;
|
|
1258
|
+
if (c && typeof c === "object") update(fromCategories(c[a] === true, c[ad] === true));
|
|
1259
|
+
} catch {
|
|
1260
|
+
}
|
|
1261
|
+
};
|
|
1262
|
+
try {
|
|
1263
|
+
for (const ev of EVENTS) (_b2 = (_a2 = env.win).addEventListener) == null ? void 0 : _b2.call(_a2, ev, read);
|
|
1264
|
+
} catch {
|
|
1265
|
+
}
|
|
1266
|
+
read();
|
|
1267
|
+
return () => {
|
|
1268
|
+
var _a3, _b3;
|
|
1269
|
+
try {
|
|
1270
|
+
for (const ev of EVENTS) (_b3 = (_a3 = env.win).removeEventListener) == null ? void 0 : _b3.call(_a3, ev, read);
|
|
1271
|
+
} catch {
|
|
1272
|
+
}
|
|
1273
|
+
};
|
|
1274
|
+
}
|
|
1275
|
+
};
|
|
1276
|
+
}
|
|
1277
|
+
|
|
1278
|
+
// src/consent/onetrust.ts
|
|
1279
|
+
function onetrustGroups(raw) {
|
|
1280
|
+
if (Array.isArray(raw)) return raw.filter((x) => typeof x === "string");
|
|
1281
|
+
return typeof raw === "string" ? raw.split(",").filter(Boolean) : [];
|
|
1282
|
+
}
|
|
1283
|
+
function onetrust(opts = {}) {
|
|
1284
|
+
var _a, _b;
|
|
1285
|
+
const a = (_a = opts.analyticsGroup) != null ? _a : "C0002";
|
|
1286
|
+
const ad = (_b = opts.adsGroup) != null ? _b : "C0004";
|
|
1287
|
+
return {
|
|
1288
|
+
name: "onetrust",
|
|
1289
|
+
subscribe(update, e) {
|
|
1290
|
+
var _a2, _b2;
|
|
1291
|
+
const env = consentEnv(e);
|
|
1292
|
+
const apply = (raw) => {
|
|
1293
|
+
const groups = onetrustGroups(raw);
|
|
1294
|
+
if (groups.length) update(fromCategories(groups.includes(a), groups.includes(ad)));
|
|
1295
|
+
};
|
|
1296
|
+
const onEvent = (ev) => {
|
|
1297
|
+
try {
|
|
1298
|
+
const detail = ev.detail;
|
|
1299
|
+
apply(Array.isArray(detail) ? detail : env.win.OnetrustActiveGroups);
|
|
1300
|
+
} catch {
|
|
1301
|
+
}
|
|
1302
|
+
};
|
|
1303
|
+
try {
|
|
1304
|
+
(_b2 = (_a2 = env.win).addEventListener) == null ? void 0 : _b2.call(_a2, "OneTrustGroupsUpdated", onEvent);
|
|
1305
|
+
if (env.win.OneTrust) apply(env.win.OnetrustActiveGroups);
|
|
1306
|
+
} catch {
|
|
1307
|
+
}
|
|
1308
|
+
return () => {
|
|
1309
|
+
var _a3, _b3;
|
|
1310
|
+
try {
|
|
1311
|
+
(_b3 = (_a3 = env.win).removeEventListener) == null ? void 0 : _b3.call(_a3, "OneTrustGroupsUpdated", onEvent);
|
|
1312
|
+
} catch {
|
|
1313
|
+
}
|
|
1314
|
+
};
|
|
1315
|
+
}
|
|
1316
|
+
};
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1319
|
+
// src/consent/gcm.ts
|
|
1320
|
+
function googleConsentMode() {
|
|
1321
|
+
return {
|
|
1322
|
+
name: "gcm",
|
|
1323
|
+
subscribe(update, e) {
|
|
1324
|
+
const env = consentEnv(e);
|
|
1325
|
+
let done = false;
|
|
1326
|
+
let updated = false;
|
|
1327
|
+
const handle = (entry) => {
|
|
1328
|
+
if (done || !entry || typeof entry !== "object") return;
|
|
1329
|
+
const x = entry;
|
|
1330
|
+
if (x[0] !== "consent") return;
|
|
1331
|
+
const kind = x[1];
|
|
1332
|
+
const params = x[2];
|
|
1333
|
+
if (kind !== "default" && kind !== "update") return;
|
|
1334
|
+
if (!params || typeof params !== "object") return;
|
|
1335
|
+
if (kind === "default" && (updated || params.region !== void 0)) return;
|
|
1336
|
+
if (kind === "update") updated = true;
|
|
1337
|
+
const s = pickConsent(params);
|
|
1338
|
+
if (kind === "default") {
|
|
1339
|
+
for (const k of CONSENT_KEYS) if (s[k] === "granted") delete s[k];
|
|
1340
|
+
}
|
|
1341
|
+
if (Object.keys(s).length) update(s);
|
|
1342
|
+
};
|
|
1343
|
+
let dl;
|
|
1344
|
+
try {
|
|
1345
|
+
dl = env.win.dataLayer = Array.isArray(env.win.dataLayer) ? env.win.dataLayer : [];
|
|
1346
|
+
} catch {
|
|
1347
|
+
return () => void 0;
|
|
1348
|
+
}
|
|
1349
|
+
for (const entry of Array.from(dl)) handle(entry);
|
|
1350
|
+
const orig = dl.push;
|
|
1351
|
+
const wrapped = function(...args) {
|
|
1352
|
+
const r = orig.apply(this, args);
|
|
1353
|
+
for (const a of args) {
|
|
1354
|
+
try {
|
|
1355
|
+
handle(a);
|
|
1356
|
+
} catch {
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
return r;
|
|
1360
|
+
};
|
|
1361
|
+
dl.push = wrapped;
|
|
1362
|
+
return () => {
|
|
1363
|
+
done = true;
|
|
1364
|
+
if (dl.push === wrapped) dl.push = orig;
|
|
1365
|
+
};
|
|
1366
|
+
}
|
|
1367
|
+
};
|
|
1368
|
+
}
|
|
1369
|
+
|
|
1370
|
+
// src/index.ts
|
|
1371
|
+
function init(opts, env) {
|
|
1372
|
+
const { errors, webVitals, enhanced, autocapture, ...core } = opts;
|
|
1373
|
+
const a = new Auralytics(core, env != null ? env : browserEnv());
|
|
1374
|
+
const none = { captureException: () => void 0, uninstall: () => void 0 };
|
|
1375
|
+
a.plugins = typeof window !== "undefined" && (errors || webVitals || enhanced || autocapture) ? installPlugins(a, window, { errors, webVitals, enhanced, autocapture }) : none;
|
|
1376
|
+
return a;
|
|
1377
|
+
}
|
|
1378
|
+
function createFlags(auralytics, opts) {
|
|
1379
|
+
return new AuralyticsFlags(auralytics, opts);
|
|
1380
|
+
}
|