@crelora/mark 0.3.0 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,31 +1,31 @@
1
- const N = "https://ingest.onelence.com";
2
- class p extends Error {
1
+ const H = "https://ingest.onelence.com";
2
+ class g extends Error {
3
3
  status;
4
4
  retryAfterMs;
5
- constructor(t, e = {}) {
6
- super(t), this.name = "TransportError", this.status = e.status, this.retryAfterMs = e.retryAfterMs;
5
+ constructor(e, t = {}) {
6
+ super(e), this.name = "TransportError", this.status = t.status, this.retryAfterMs = t.retryAfterMs;
7
7
  }
8
8
  }
9
- function V(r) {
9
+ function z(r) {
10
10
  return !(typeof r != "number" || r < 400 || r >= 500 || r === 408 || r === 429);
11
11
  }
12
- function z(r) {
12
+ function M(r) {
13
13
  if (!r) return;
14
- const t = r.trim();
15
- if (!t) return;
16
- const e = Number(t);
17
- if (Number.isFinite(e) && e >= 0)
18
- return Math.floor(e * 1e3);
19
- const i = Date.parse(t);
14
+ const e = r.trim();
15
+ if (!e) return;
16
+ const t = Number(e);
17
+ if (Number.isFinite(t) && t >= 0)
18
+ return Math.floor(t * 1e3);
19
+ const i = Date.parse(e);
20
20
  if (Number.isFinite(i)) {
21
21
  const n = i - Date.now();
22
22
  return n > 0 ? n : 0;
23
23
  }
24
24
  }
25
- const M = 5, $ = 300, j = 15e3, Y = 2880 * 60 * 1e3;
26
- class Q {
27
- constructor(t, e = {}) {
28
- this.transport = t, this.maxAttempts = e.maxAttempts ?? M, this.baseBackoffMs = e.baseBackoffMs ?? $, this.maxBackoffMs = e.maxBackoffMs ?? j, this.maxItemAgeMs = e.maxItemAgeMs ?? Y, this.debug = e.debug ?? !1, this.loadPersisted = e.loadPersisted, this.savePersisted = e.savePersisted, this.onError = e.onError;
25
+ const $ = 5, Y = 300, j = 15e3, Q = 2880 * 60 * 1e3;
26
+ class W {
27
+ constructor(e, t = {}) {
28
+ this.transport = e, this.maxAttempts = t.maxAttempts ?? $, this.baseBackoffMs = t.baseBackoffMs ?? Y, this.maxBackoffMs = t.maxBackoffMs ?? j, this.maxItemAgeMs = t.maxItemAgeMs ?? Q, this.debug = t.debug ?? !1, this.loadPersisted = t.loadPersisted, this.savePersisted = t.savePersisted, this.onError = t.onError;
29
29
  const i = this.loadPersisted?.() ?? [];
30
30
  if (i.length > 0) {
31
31
  const n = Date.now();
@@ -53,10 +53,10 @@ class Q {
53
53
  loadPersisted;
54
54
  savePersisted;
55
55
  onError;
56
- enqueue(t, e) {
56
+ enqueue(e, t) {
57
57
  this.queue.push({
58
- path: t,
59
- data: e,
58
+ path: e,
59
+ data: t,
60
60
  attempts: 0,
61
61
  nextAttemptAt: Date.now(),
62
62
  enqueuedAt: Date.now()
@@ -66,18 +66,18 @@ class Q {
66
66
  await this.process(!0), await this.transport.flush?.();
67
67
  }
68
68
  /**
69
- * Best-effort synchronous drain using sendBeacon. Intended for page unload;
70
- * errors are swallowed because the tab is going away.
69
+ * Best-effort synchronous drain on page unload. Uses fetch keepalive (via
70
+ * preferBeacon) so auth headers are included.
71
71
  */
72
72
  drainViaBeacon() {
73
73
  if (this.queue.length === 0) return;
74
- const t = this.queue.splice(0, this.queue.length);
74
+ const e = this.queue.splice(0, this.queue.length);
75
75
  this.persist();
76
- for (const e of t) {
77
- const i = { ...e.data };
76
+ for (const t of e) {
77
+ const i = { ...t.data };
78
78
  delete i.__prefer_beacon;
79
79
  try {
80
- this.transport.send(e.path, i, { preferBeacon: !0 });
80
+ this.transport.send(t.path, i, { preferBeacon: !0 });
81
81
  } catch {
82
82
  }
83
83
  }
@@ -98,35 +98,35 @@ class Q {
98
98
  }
99
99
  evictExpired() {
100
100
  if (this.queue.length === 0) return;
101
- const e = Date.now() - this.maxItemAgeMs;
101
+ const t = Date.now() - this.maxItemAgeMs;
102
102
  let i = 0;
103
103
  for (let n = this.queue.length - 1; n >= 0; n -= 1)
104
- this.queue[n].enqueuedAt <= e && (this.queue.splice(n, 1), this.dropped += 1, i += 1);
104
+ this.queue[n].enqueuedAt <= t && (this.queue.splice(n, 1), this.dropped += 1, i += 1);
105
105
  i > 0 && this.persist();
106
106
  }
107
- async process(t = !1) {
107
+ async process(e = !1) {
108
108
  if (!this.flushing) {
109
109
  this.flushing = !0;
110
110
  try {
111
111
  for (this.evictExpired(); this.queue.length > 0; ) {
112
- const e = this.queue[0];
113
- if (!t && e.nextAttemptAt > Date.now())
112
+ const t = this.queue[0];
113
+ if (!e && t.nextAttemptAt > Date.now())
114
114
  break;
115
115
  try {
116
- const i = { ...e.data }, n = i.__prefer_beacon === !0;
117
- delete i.__prefer_beacon, await this.transport.send(e.path, i, { preferBeacon: n }), this.queue.shift(), this.sent += 1, this.persist();
116
+ const i = { ...t.data }, n = i.__prefer_beacon === !0;
117
+ delete i.__prefer_beacon, await this.transport.send(t.path, i, { preferBeacon: n }), this.queue.shift(), this.sent += 1, this.persist();
118
118
  } catch (i) {
119
- this.failed += 1, this.onError?.(i, e.data);
120
- const n = i instanceof p ? i.status : void 0;
121
- if (V(n)) {
122
- this.queue.shift(), this.dropped += 1, this.persist(), this.debug && console.error("[Mark] Dropping event after non-retriable status", n, e.path);
119
+ this.failed += 1, this.onError?.(i, t.data);
120
+ const n = i instanceof g ? i.status : void 0;
121
+ if (z(n)) {
122
+ this.queue.shift(), this.dropped += 1, this.persist(), this.debug && console.error("[Mark] Dropping event after non-retriable status", n, t.path);
123
123
  continue;
124
124
  }
125
- if (e.attempts += 1, e.attempts >= this.maxAttempts) {
126
- this.queue.shift(), this.dropped += 1, this.persist(), this.debug && console.error("[Mark] Dropping event after max retries", e.path, i);
125
+ if (t.attempts += 1, t.attempts >= this.maxAttempts) {
126
+ this.queue.shift(), this.dropped += 1, this.persist(), this.debug && console.error("[Mark] Dropping event after max retries", t.path, i);
127
127
  continue;
128
128
  }
129
- const o = i instanceof p ? i.retryAfterMs : void 0;
129
+ const o = i instanceof g ? i.retryAfterMs : void 0;
130
130
  let a;
131
131
  if (typeof o == "number")
132
132
  a = Math.min(this.maxBackoffMs, Math.max(0, o));
@@ -134,10 +134,10 @@ class Q {
134
134
  const c = Math.random() * this.baseBackoffMs;
135
135
  a = Math.min(
136
136
  this.maxBackoffMs,
137
- this.baseBackoffMs * 2 ** (e.attempts - 1) + c
137
+ this.baseBackoffMs * 2 ** (t.attempts - 1) + c
138
138
  );
139
139
  }
140
- e.nextAttemptAt = Date.now() + a, this.persist();
140
+ t.nextAttemptAt = Date.now() + a, this.persist();
141
141
  break;
142
142
  }
143
143
  }
@@ -147,15 +147,15 @@ class Q {
147
147
  }
148
148
  }
149
149
  }
150
- const W = 256;
151
- function E(r) {
150
+ const G = 256;
151
+ function T(r) {
152
152
  if (typeof r != "string")
153
153
  return;
154
- const t = r.trim();
155
- if (!(!t || t.length > W) && !t.includes("@") && !/\s/.test(t))
156
- return t;
154
+ const e = r.trim();
155
+ if (!(!e || e.length > G) && !e.includes("@") && !/\s/.test(e))
156
+ return e;
157
157
  }
158
- const G = /* @__PURE__ */ new Set(["event_name", "user_id", "consent_state", "source", "is_conversion"]), X = /* @__PURE__ */ new Set([
158
+ const X = /* @__PURE__ */ new Set(["event_name", "user_id", "consent_state", "source", "is_conversion"]), J = /* @__PURE__ */ new Set([
159
159
  "user_id",
160
160
  "visitor_id",
161
161
  "click_id",
@@ -164,13 +164,13 @@ const G = /* @__PURE__ */ new Set(["event_name", "user_id", "consent_state", "so
164
164
  "consent_state",
165
165
  "source"
166
166
  ]);
167
- class J {
168
- constructor(t, e) {
169
- this.deps = e, this.validateConfig(t), this.config = {
170
- endpoint: t.endpoint ?? N,
171
- ...t,
172
- include_page_context: t.include_page_context ?? !0
173
- }, this.consentRequirement = t.require_consent ?? !1, this.siteId = t.site_id, this.siteHost = t.site_host, this.sessionTimeoutMs = t.session_timeout_ms ?? 1800 * 1e3, this.queue = new Q(this.deps.transport, {
167
+ class Z {
168
+ constructor(e, t) {
169
+ this.deps = t, this.validateConfig(e), this.config = {
170
+ endpoint: e.endpoint ?? H,
171
+ ...e,
172
+ include_page_context: e.include_page_context ?? !0
173
+ }, this.consentRequirement = e.require_consent ?? !1, this.siteId = e.site_id, this.siteHost = e.site_host, this.sessionTimeoutMs = e.session_timeout_ms ?? 1800 * 1e3, this.queue = new W(this.deps.transport, {
174
174
  debug: this.config.debug,
175
175
  loadPersisted: () => this.deps.storage.getOutbox?.() ?? [],
176
176
  savePersisted: (i) => this.deps.storage.setOutbox?.(i),
@@ -188,7 +188,7 @@ class J {
188
188
  tcfCachedAllowed = !1;
189
189
  /**
190
190
  * Best-effort synchronous drain that dispatches all queued events via
191
- * sendBeacon. Intended for use on page unload (visibilitychange=hidden,
191
+ * fetch keepalive. Intended for use on page unload (visibilitychange=hidden,
192
192
  * pagehide) where async fetch may be cancelled by the browser.
193
193
  */
194
194
  drainViaBeacon() {
@@ -202,32 +202,32 @@ class J {
202
202
  kickQueue() {
203
203
  this.queue.flush();
204
204
  }
205
- track(t, e = {}) {
206
- return this.trackInternal(t, e, !1);
205
+ track(e, t = {}) {
206
+ return this.trackInternal(e, t, !1);
207
207
  }
208
- trackInternal(t, e = {}, i = !1, n) {
209
- if (!t)
208
+ trackInternal(e, t = {}, i = !1, n) {
209
+ if (!e)
210
210
  return this.config.debug && console.warn("[Mark] track called without event name"), !1;
211
211
  if (!this.hasConsent() || this.isDntBlocked())
212
212
  return this.config.debug && console.warn("[Mark] Tracking blocked due to consent requirement."), !1;
213
213
  if (!i && !this.shouldSampleTrack())
214
214
  return !0;
215
- const o = this.sanitizeTrackData(e), a = { ...o };
215
+ const o = this.sanitizeTrackData(t), a = { ...o };
216
216
  "query" in a && delete a.query, "site_id" in a && delete a.site_id, "site_host" in a && delete a.site_host;
217
217
  const c = {
218
- event_name: t,
218
+ event_name: e,
219
219
  message_id: this.createMessageId(),
220
220
  ...this.getIdentityFields(o),
221
221
  ...a
222
222
  };
223
223
  i && (c.is_conversion = !0);
224
- const f = o.site_id ?? this.siteId, l = o.site_host ?? this.siteHost;
225
- f && (c.site_id = f), l && (c.site_host = l), this.config.include_page_context && typeof window < "u" && (this.applyPageContext(c), !l && c.site && (c.site_host = c.site)), this.applyInternalFlag(c, o.is_internal);
224
+ const f = o.site_id ?? this.siteId, u = o.site_host ?? this.siteHost;
225
+ f && (c.site_id = f), u && (c.site_host = u), this.config.include_page_context && typeof window < "u" && (this.applyPageContext(c), !u && c.site && (c.site_host = c.site)), this.applyInternalFlag(c, o.is_internal);
226
226
  const d = this.config.before_send ? this.config.before_send(c) : c;
227
227
  return d ? (this.ensureSession(), this.applySessionFields(d), this.config.batching?.enabled && !i && !n?.preferBeacon ? (this.enqueueBatch(d), !0) : (this.queue.enqueue("/event", { ...d, __prefer_beacon: n?.preferBeacon === !0 }), !0)) : !0;
228
228
  }
229
- identify(t, e = {}) {
230
- if (!t) {
229
+ identify(e, t = {}) {
230
+ if (!e) {
231
231
  this.config.debug && console.warn("[Mark] identify called without userId");
232
232
  return;
233
233
  }
@@ -235,22 +235,22 @@ class J {
235
235
  this.config.debug && console.warn("[Mark] Identify blocked due to consent requirement.");
236
236
  return;
237
237
  }
238
- this.deps.storage.update({ user_id: t });
238
+ this.deps.storage.update({ user_id: e });
239
239
  const i = {
240
- user_id: t,
240
+ user_id: e,
241
241
  message_id: this.createMessageId(),
242
- ...this.sanitizeIdentifyTraits(e),
242
+ ...this.sanitizeIdentifyTraits(t),
243
243
  ...this.getIdentityFields()
244
244
  };
245
245
  this.siteId && (i.site_id = this.siteId), this.siteHost && (i.site_host = this.siteHost), this.applyInternalFlag(i);
246
246
  const n = this.config.before_send ? this.config.before_send(i) : i;
247
247
  n && (this.ensureSession(), this.applySessionFields(n), this.queue.enqueue("/identify", n));
248
248
  }
249
- conversion(t, e = {}) {
250
- return this.trackInternal(t, e, !0);
249
+ conversion(e, t = {}) {
250
+ return this.trackInternal(e, t, !0);
251
251
  }
252
- trackWithOptions(t, e = {}, i) {
253
- return this.trackInternal(t, e, !1, i);
252
+ trackWithOptions(e, t = {}, i) {
253
+ return this.trackInternal(e, t, !1, i);
254
254
  }
255
255
  /**
256
256
  * Returns the current visitor ID from storage, if any.
@@ -264,16 +264,16 @@ class J {
264
264
  * Use when an external anonymous id (for example a platform client id) arrives
265
265
  * after init. Returns false when the id is invalid.
266
266
  */
267
- setVisitorId(t) {
268
- const e = E(t);
269
- return e ? this.deps.storage.setVisitorId ? this.deps.storage.setVisitorId(e) : (this.deps.storage.getVisitorId() === e || this.deps.storage.update({ visitor_id: e }), !0) : (this.config.debug && console.warn("[Mark] setVisitorId called with an invalid visitor id."), !1);
267
+ setVisitorId(e) {
268
+ const t = T(e);
269
+ return t ? this.deps.storage.setVisitorId ? this.deps.storage.setVisitorId(t) : (this.deps.storage.getVisitorId() === t || this.deps.storage.update({ visitor_id: t }), !0) : (this.config.debug && console.warn("[Mark] setVisitorId called with an invalid visitor id."), !1);
270
270
  }
271
- setConsent(t) {
272
- const e = this.deps.storage.getConsentStatus();
273
- this.deps.storage.setConsentStatus(t), t === "denied" ? (this.deps.storage.clearAttribution?.(), this.deps.storage.clearCookieVisitorId?.(), this.deps.storage.setInternal?.(!1)) : t === "granted" && e === "denied" && this.config.rotate_visitor_on_consent_change && this.deps.storage.rotateVisitorId?.();
271
+ setConsent(e) {
272
+ const t = this.deps.storage.getConsentStatus();
273
+ this.deps.storage.setConsentStatus(e), e === "denied" ? (this.deps.storage.clearAttribution?.(), this.deps.storage.clearCookieVisitorId?.(), this.deps.storage.setInternal?.(!1)) : e === "granted" && t === "denied" && this.config.rotate_visitor_on_consent_change && this.deps.storage.rotateVisitorId?.();
274
274
  const i = {
275
275
  visitor_id: this.deps.storage.getVisitorId(),
276
- consent_state: t,
276
+ consent_state: e,
277
277
  source: "sdk",
278
278
  message_id: this.createMessageId()
279
279
  };
@@ -303,8 +303,8 @@ class J {
303
303
  * it survives reloads, and is cleared by `reset()` and by
304
304
  * `setConsent('denied')`.
305
305
  */
306
- setInternal(t) {
307
- this.deps.storage.setInternal?.(!!t);
306
+ setInternal(e) {
307
+ this.deps.storage.setInternal?.(!!e);
308
308
  }
309
309
  /**
310
310
  * Returns the currently persisted internal-traffic flag, if any.
@@ -326,75 +326,75 @@ class J {
326
326
  * Explicit `is_internal: false` on a single event wins over the visitor flag
327
327
  * so individual calls can opt out.
328
328
  */
329
- applyInternalFlag(t, e) {
330
- if (e === !1) {
331
- delete t.is_internal;
329
+ applyInternalFlag(e, t) {
330
+ if (t === !1) {
331
+ delete e.is_internal;
332
332
  return;
333
333
  }
334
334
  const i = this.deps.storage.getInternal?.() === !0;
335
- e === !0 || i ? t.is_internal = !0 : delete t.is_internal;
335
+ t === !0 || i ? e.is_internal = !0 : delete e.is_internal;
336
336
  }
337
- getIdentityFields(t) {
338
- const e = t?.visitor_id ?? this.deps.storage.getVisitorId(), i = t?.user_id ?? this.deps.storage.getUserId?.(), n = t?.click_id ?? this.deps.storage.getLastClickId(), o = t?.campaign_id ?? this.deps.storage.getCampaignId(), a = t?.session_id ?? this.deps.storage.getSessionId?.(), c = this.deps.storage.getQueryParams() ?? {}, f = t?.query ?? {}, l = { ...c, ...f }, d = {};
339
- e && (d.visitor_id = e), i && (d.user_id = i), n && (d.click_id = n), o && (d.campaign_id = o), a && (d.session_id = a);
337
+ getIdentityFields(e) {
338
+ const t = e?.visitor_id ?? this.deps.storage.getVisitorId(), i = e?.user_id ?? this.deps.storage.getUserId?.(), n = e?.click_id ?? this.deps.storage.getLastClickId(), o = e?.campaign_id ?? this.deps.storage.getCampaignId(), a = e?.session_id ?? this.deps.storage.getSessionId?.(), c = this.deps.storage.getQueryParams() ?? {}, f = e?.query ?? {}, u = { ...c, ...f }, d = {};
339
+ t && (d.visitor_id = t), i && (d.user_id = i), n && (d.click_id = n), o && (d.campaign_id = o), a && (d.session_id = a);
340
340
  const h = this.deps.storage.getSessionStartedAt?.();
341
- return a && h && (d.session_started_at = h, d.session_elapsed_ms = Date.now() - Date.parse(h)), Object.keys(l).length > 0 && (d.query = l), d;
341
+ return a && h && (d.session_started_at = h, d.session_elapsed_ms = Date.now() - Date.parse(h)), Object.keys(u).length > 0 && (d.query = u), d;
342
342
  }
343
343
  /**
344
344
  * Patches session fields after ensureSession when the first event in a session was built
345
345
  * before rotation created an id. Rotation events keep the previous session_id from identity.
346
346
  */
347
- applySessionFields(t) {
348
- if (!t.session_id) {
347
+ applySessionFields(e) {
348
+ if (!e.session_id) {
349
349
  const i = this.deps.storage.getSessionId?.(), n = this.deps.storage.getSessionStartedAt?.();
350
- i && (t.session_id = i), n && (t.session_started_at = n);
350
+ i && (e.session_id = i), n && (e.session_started_at = n);
351
351
  }
352
- const e = t.session_started_at;
353
- t.session_id && typeof e == "string" && (t.session_elapsed_ms = Date.now() - Date.parse(e));
352
+ const t = e.session_started_at;
353
+ e.session_id && typeof t == "string" && (e.session_elapsed_ms = Date.now() - Date.parse(t));
354
354
  }
355
355
  hasConsent() {
356
356
  if (this.config.consent_source?.type === "tcf" && typeof window < "u" && !this.tcfCachedAllowed)
357
357
  return !1;
358
358
  if (!this.consentRequirement)
359
359
  return !0;
360
- const e = this.deps.storage.getConsentStatus();
361
- return this.consentRequirement === "auto", e === "granted";
360
+ const t = this.deps.storage.getConsentStatus();
361
+ return this.consentRequirement === "auto", t === "granted";
362
362
  }
363
- sanitizeTrackData(t) {
364
- const e = {};
365
- for (const [i, n] of Object.entries(t))
366
- G.has(i) || (e[i] = n);
367
- return e;
363
+ sanitizeTrackData(e) {
364
+ const t = {};
365
+ for (const [i, n] of Object.entries(e))
366
+ X.has(i) || (t[i] = n);
367
+ return t;
368
368
  }
369
- sanitizeIdentifyTraits(t) {
370
- const e = {};
371
- for (const [i, n] of Object.entries(t))
372
- X.has(i) || (e[i] = n);
373
- return e;
369
+ sanitizeIdentifyTraits(e) {
370
+ const t = {};
371
+ for (const [i, n] of Object.entries(e))
372
+ J.has(i) || (t[i] = n);
373
+ return t;
374
374
  }
375
- validateConfig(t) {
376
- if (!t.key || !t.key.trim())
375
+ validateConfig(e) {
376
+ if (!e.key || !e.key.trim())
377
377
  throw new Error("[Mark] `key` must be a non-empty string.");
378
- if (t.endpoint)
378
+ if (e.endpoint)
379
379
  try {
380
- new URL(t.endpoint);
380
+ new URL(e.endpoint);
381
381
  } catch {
382
382
  throw new Error("[Mark] `endpoint` must be a valid absolute URL.");
383
383
  }
384
- if (typeof t.site_id == "string" && !t.site_id.trim())
384
+ if (typeof e.site_id == "string" && !e.site_id.trim())
385
385
  throw new Error("[Mark] `site_id` cannot be an empty string.");
386
- if (typeof t.site_host == "string" && !t.site_host.trim())
386
+ if (typeof e.site_host == "string" && !e.site_host.trim())
387
387
  throw new Error("[Mark] `site_host` cannot be an empty string.");
388
- if (t.visitor_id !== void 0 && !E(t.visitor_id))
388
+ if (e.visitor_id !== void 0 && !T(e.visitor_id))
389
389
  throw new Error("[Mark] `visitor_id` must be a non-empty string (max 256 characters).");
390
390
  }
391
- applyPageContext(t) {
392
- typeof document > "u" || (t.site || (t.site = window.location.host), t.page || (t.page = window.location.pathname), t.title || (t.title = document.title), !t.referrer && document.referrer && (t.referrer = this.scrubReferrer(document.referrer)));
391
+ applyPageContext(e) {
392
+ typeof document > "u" || (e.site || (e.site = window.location.host), e.page || (e.page = window.location.pathname), e.title || (e.title = document.title), !e.referrer && document.referrer && (e.referrer = this.scrubReferrer(document.referrer)));
393
393
  }
394
- enqueueBatch(t) {
395
- this.batchedEvents.push(t);
396
- const e = this.config.batching?.max_size ?? 20;
397
- if (this.batchedEvents.length >= e) {
394
+ enqueueBatch(e) {
395
+ this.batchedEvents.push(e);
396
+ const t = this.config.batching?.max_size ?? 20;
397
+ if (this.batchedEvents.length >= t) {
398
398
  this.flushBatch();
399
399
  return;
400
400
  }
@@ -407,16 +407,16 @@ class J {
407
407
  }
408
408
  flushBatch() {
409
409
  if (this.batchedEvents.length === 0) return;
410
- const t = this.config.batching?.endpoint_path ?? "/events", e = this.batchedEvents.splice(0, this.batchedEvents.length);
411
- this.queue.enqueue(t, { events: e, message_id: this.createMessageId() });
410
+ const e = this.config.batching?.endpoint_path ?? "/events", t = this.batchedEvents.splice(0, this.batchedEvents.length);
411
+ this.queue.enqueue(e, { events: t, message_id: this.createMessageId() });
412
412
  }
413
413
  createMessageId() {
414
414
  return typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : `msg_${Date.now()}_${Math.random().toString(16).slice(2)}`;
415
415
  }
416
416
  ensureSession() {
417
- const t = Date.now(), e = this.deps.storage.getSessionId?.(), i = this.deps.storage.getLastActivityAt?.(), n = i ? Date.parse(i) : 0;
418
- if (!e || !n || t - n >= this.sessionTimeoutMs || this.crossedUtcDay(n, t)) {
419
- const a = this.createMessageId(), c = new Date(t).toISOString();
417
+ const e = Date.now(), t = this.deps.storage.getSessionId?.(), i = this.deps.storage.getLastActivityAt?.(), n = i ? Date.parse(i) : 0;
418
+ if (!t || !n || e - n >= this.sessionTimeoutMs || this.crossedUtcDay(n, e)) {
419
+ const a = this.createMessageId(), c = new Date(e).toISOString();
420
420
  this.deps.storage.update({
421
421
  session_id: a,
422
422
  session_started_at: c,
@@ -424,10 +424,10 @@ class J {
424
424
  });
425
425
  return;
426
426
  }
427
- this.deps.storage.update({ last_activity_at: new Date(t).toISOString() });
427
+ this.deps.storage.update({ last_activity_at: new Date(e).toISOString() });
428
428
  }
429
- crossedUtcDay(t, e) {
430
- const i = new Date(t), n = new Date(e);
429
+ crossedUtcDay(e, t) {
430
+ const i = new Date(e), n = new Date(t);
431
431
  return i.getUTCFullYear() !== n.getUTCFullYear() || i.getUTCMonth() !== n.getUTCMonth() || i.getUTCDate() !== n.getUTCDate();
432
432
  }
433
433
  shouldSampleTrack() {
@@ -436,17 +436,17 @@ class J {
436
436
  isDntBlocked() {
437
437
  if (!this.config.honor_dnt || typeof navigator > "u")
438
438
  return !1;
439
- const t = navigator.doNotTrack, e = navigator.globalPrivacyControl;
440
- return t === "1" || e === !0;
439
+ const e = navigator.doNotTrack, t = navigator.globalPrivacyControl;
440
+ return e === "1" || t === !0;
441
441
  }
442
- scrubReferrer(t) {
442
+ scrubReferrer(e) {
443
443
  try {
444
- const e = new URL(t);
445
- if (typeof window > "u") return t;
444
+ const t = new URL(e);
445
+ if (typeof window > "u") return e;
446
446
  const i = new URL(window.location.href);
447
- return e.origin !== i.origin ? (e.search = "", e.toString()) : t;
447
+ return t.origin !== i.origin ? (t.search = "", t.toString()) : e;
448
448
  } catch {
449
- return t;
449
+ return e;
450
450
  }
451
451
  }
452
452
  warnMisconfiguredSiteHost() {
@@ -462,9 +462,9 @@ class J {
462
462
  * poll briefly (CMPs commonly load asynchronously) and give up after ~2s.
463
463
  */
464
464
  subscribeTcf() {
465
- const t = this.config.consent_source;
466
- if (t?.type !== "tcf" || typeof window > "u") return;
467
- const e = t.purposes, i = (n) => {
465
+ const e = this.config.consent_source;
466
+ if (e?.type !== "tcf" || typeof window > "u") return;
467
+ const t = e.purposes, i = (n) => {
468
468
  try {
469
469
  const o = window;
470
470
  if (typeof o.__tcfapi != "function") {
@@ -481,7 +481,7 @@ class J {
481
481
  return;
482
482
  }
483
483
  const f = a.purpose?.consents ?? {};
484
- this.tcfCachedAllowed = e.every((l) => f[String(l)] === !0);
484
+ this.tcfCachedAllowed = t.every((u) => f[String(u)] === !0);
485
485
  });
486
486
  } catch {
487
487
  this.tcfCachedAllowed = !1;
@@ -490,15 +490,15 @@ class J {
490
490
  i(10);
491
491
  }
492
492
  }
493
- class Z {
493
+ class ee {
494
494
  config;
495
495
  endpoint;
496
496
  pending = /* @__PURE__ */ new Set();
497
- constructor(t) {
498
- this.config = t, this.endpoint = t.endpoint ?? N;
497
+ constructor(e) {
498
+ this.config = e, this.endpoint = e.endpoint ?? H;
499
499
  }
500
- async send(t, e, i) {
501
- const n = this.sendInternal(t, e, i);
500
+ async send(e, t, i) {
501
+ const n = this.sendInternal(e, t, i);
502
502
  this.pending.add(n);
503
503
  try {
504
504
  await n;
@@ -509,71 +509,64 @@ class Z {
509
509
  async flush() {
510
510
  this.pending.size !== 0 && await Promise.allSettled(Array.from(this.pending));
511
511
  }
512
- async sendInternal(t, e, i) {
513
- const n = this.joinUrl(this.endpoint, t), o = this.config.key, a = {
512
+ async sendInternal(e, t, i) {
513
+ const n = this.joinUrl(this.endpoint, e), o = this.config.key, a = {
514
514
  "Content-Type": "application/json",
515
515
  [o.startsWith("sk_") ? "x-secret-key" : "x-publishable-key"]: o
516
516
  };
517
- this.config.debug && console.log("[Mark] Sending", n, e);
518
- const c = JSON.stringify(e);
519
- if (i?.preferBeacon && typeof navigator < "u" && typeof navigator.sendBeacon == "function") {
520
- const u = new Blob([c], { type: "application/json" });
521
- if (navigator.sendBeacon(n, u))
522
- return;
523
- }
524
- if (typeof fetch != "function")
525
- throw this.config.debug && console.error("[Mark] Global fetch is not available in this runtime."), new p("[Mark] Global fetch is not available in this runtime.");
526
- const f = this.config.request_timeout_ms ?? 1e4, l = new AbortController();
517
+ if (this.config.debug && console.log("[Mark] Sending", n, t), typeof fetch != "function")
518
+ throw this.config.debug && console.error("[Mark] Global fetch is not available in this runtime."), new g("[Mark] Global fetch is not available in this runtime.");
519
+ const c = JSON.stringify(t), f = this.config.request_timeout_ms ?? 1e4, u = new AbortController();
527
520
  let d = !1;
528
521
  const h = setTimeout(() => {
529
- d = !0, l.abort();
522
+ d = !0, u.abort();
530
523
  }, f);
531
524
  try {
532
- const u = await fetch(n, {
525
+ const l = await fetch(n, {
533
526
  method: "POST",
534
527
  headers: a,
535
528
  body: c,
536
- keepalive: !0,
537
- signal: l.signal
529
+ keepalive: i?.preferBeacon === !0,
530
+ signal: u.signal
538
531
  });
539
- if (!u.ok) {
540
- const g = await this.readErrorSnippet(u), L = z(u.headers.get("Retry-After"));
532
+ if (!l.ok) {
533
+ const p = await this.readErrorSnippet(l), m = M(l.headers.get("Retry-After"));
541
534
  throw this.config.debug && console.error("[Mark] Request rejected", {
542
535
  url: n,
543
- status: u.status,
544
- statusText: u.statusText,
545
- body: g,
546
- retryAfterMs: L
547
- }), new p(
548
- `[Mark] Request rejected with status ${u.status}: ${g}`,
549
- { status: u.status, retryAfterMs: L }
536
+ status: l.status,
537
+ statusText: l.statusText,
538
+ body: p,
539
+ retryAfterMs: m
540
+ }), new g(
541
+ `[Mark] Request rejected with status ${l.status}: ${p}`,
542
+ { status: l.status, retryAfterMs: m }
550
543
  );
551
544
  }
552
- } catch (u) {
553
- if (this.config.debug && console.error("[Mark] Failed to send", n, u), u instanceof p)
554
- throw u;
545
+ } catch (l) {
546
+ if (this.config.debug && console.error("[Mark] Failed to send", n, l), l instanceof g)
547
+ throw l;
555
548
  if (d)
556
- throw new p(`[Mark] Request timed out after ${f}ms`, { status: 408 });
557
- const g = u instanceof Error ? u.message : String(u);
558
- throw new p(`[Mark] Network error: ${g}`);
549
+ throw new g(`[Mark] Request timed out after ${f}ms`, { status: 408 });
550
+ const p = l instanceof Error ? l.message : String(l);
551
+ throw new g(`[Mark] Network error: ${p}`);
559
552
  } finally {
560
553
  clearTimeout(h);
561
554
  }
562
555
  }
563
- joinUrl(t, e) {
564
- const i = t.replace(/\/+$/, ""), n = e.replace(/^\/+/, "");
556
+ joinUrl(e, t) {
557
+ const i = e.replace(/\/+$/, ""), n = t.replace(/^\/+/, "");
565
558
  return `${i}/${n}`;
566
559
  }
567
- async readErrorSnippet(t) {
560
+ async readErrorSnippet(e) {
568
561
  try {
569
- return (await t.text()).slice(0, 300);
562
+ return (await e.text()).slice(0, 300);
570
563
  } catch {
571
564
  return "";
572
565
  }
573
566
  }
574
567
  }
575
- const tt = "crelora_mark_data", et = "crelora_mark_outbox", k = "crelora_mark_vid";
576
- class it {
568
+ const te = "crelora_mark_data", ie = "crelora_mark_outbox", L = "crelora_mark_vid";
569
+ class ne {
577
570
  data;
578
571
  storageKey;
579
572
  outboxKey;
@@ -581,14 +574,14 @@ class it {
581
574
  bridgeFrame;
582
575
  bridgeReady = !1;
583
576
  bridgeOrigin;
584
- constructor(t) {
585
- if (this.options = t ?? {}, this.storageKey = this.options.storageKey ?? tt, this.outboxKey = this.options.outboxKey ?? et, typeof window > "u") {
577
+ constructor(e) {
578
+ if (this.options = e ?? {}, this.storageKey = this.options.storageKey ?? te, this.outboxKey = this.options.outboxKey ?? ie, typeof window > "u") {
586
579
  this.data = {};
587
580
  return;
588
581
  }
589
582
  this.data = this.load();
590
- const e = E(this.options.seed_visitor_id);
591
- !this.data.visitor_id && e && (this.data.visitor_id = e, this.save()), this.data.visitor_id || (this.data.visitor_id = this.generateUUID(), this.save()), typeof window < "u" && this.options.bridge?.url && this.setupBridge(this.options.bridge), window.addEventListener("storage", this.handleStorageEvent);
583
+ const t = T(this.options.seed_visitor_id);
584
+ !this.data.visitor_id && t && (this.data.visitor_id = t, this.save()), this.data.visitor_id || (this.data.visitor_id = this.generateUUID(), this.save()), typeof window < "u" && this.options.bridge?.url && this.setupBridge(this.options.bridge), window.addEventListener("storage", this.handleStorageEvent);
592
585
  }
593
586
  getVisitorId() {
594
587
  return this.data.visitor_id;
@@ -620,14 +613,14 @@ class it {
620
613
  getInternal() {
621
614
  return this.data.is_internal;
622
615
  }
623
- setInternal(t) {
624
- t ? this.update({ is_internal: !0 }) : this.update({ is_internal: void 0 });
616
+ setInternal(e) {
617
+ e ? this.update({ is_internal: !0 }) : this.update({ is_internal: void 0 });
625
618
  }
626
- update(t) {
627
- this.data = { ...this.data, ...t }, this.save();
619
+ update(e) {
620
+ this.data = { ...this.data, ...e }, this.save();
628
621
  }
629
- setConsentStatus(t) {
630
- this.data.consent_status = t, this.save();
622
+ setConsentStatus(e) {
623
+ this.data.consent_status = e, this.save();
631
624
  }
632
625
  clearAttribution() {
633
626
  this.update({
@@ -637,7 +630,7 @@ class it {
637
630
  });
638
631
  }
639
632
  clearCookieVisitorId() {
640
- this.setCookie(k, "", -1);
633
+ this.setCookie(L, "", -1);
641
634
  }
642
635
  rotateVisitorId() {
643
636
  this.update({ visitor_id: this.generateUUID() });
@@ -646,25 +639,25 @@ class it {
646
639
  * Adopts or replaces the stored visitor id with a trusted first-party value.
647
640
  * No-op when the id is invalid or already set to the same value.
648
641
  */
649
- setVisitorId(t) {
650
- const e = E(t);
651
- return e ? (this.data.visitor_id === e || this.update({ visitor_id: e }), !0) : !1;
642
+ setVisitorId(e) {
643
+ const t = T(e);
644
+ return t ? (this.data.visitor_id === t || this.update({ visitor_id: t }), !0) : !1;
652
645
  }
653
646
  getOutbox() {
654
647
  if (typeof window > "u") return [];
655
648
  try {
656
- const t = localStorage.getItem(this.outboxKey);
657
- if (!t) return [];
658
- const e = JSON.parse(t);
659
- return Array.isArray(e) ? e : [];
649
+ const e = localStorage.getItem(this.outboxKey);
650
+ if (!e) return [];
651
+ const t = JSON.parse(e);
652
+ return Array.isArray(t) ? t : [];
660
653
  } catch {
661
654
  return [];
662
655
  }
663
656
  }
664
- setOutbox(t) {
657
+ setOutbox(e) {
665
658
  if (!(typeof window > "u"))
666
659
  try {
667
- localStorage.setItem(this.outboxKey, JSON.stringify(t.slice(-200)));
660
+ localStorage.setItem(this.outboxKey, JSON.stringify(e.slice(-200)));
668
661
  } catch {
669
662
  }
670
663
  }
@@ -672,13 +665,13 @@ class it {
672
665
  if (typeof window > "u")
673
666
  return {};
674
667
  try {
675
- const e = localStorage.getItem(this.storageKey);
676
- if (e)
677
- return JSON.parse(e);
668
+ const t = localStorage.getItem(this.storageKey);
669
+ if (t)
670
+ return JSON.parse(t);
678
671
  } catch {
679
672
  }
680
- const t = this.getCookie(k);
681
- return t ? { visitor_id: t } : {};
673
+ const e = this.getCookie(L);
674
+ return e ? { visitor_id: e } : {};
682
675
  }
683
676
  save() {
684
677
  if (!(typeof window > "u")) {
@@ -686,27 +679,27 @@ class it {
686
679
  localStorage.setItem(this.storageKey, JSON.stringify(this.data));
687
680
  } catch {
688
681
  }
689
- this.data.visitor_id && this.isCookieEnabled() && (this.setCookie(k, this.data.visitor_id, 365), this.options.bridge?.url && this.bridgeReady && this.postBridgeMessage({
682
+ this.data.visitor_id && this.isCookieEnabled() && (this.setCookie(L, this.data.visitor_id, 365), this.options.bridge?.url && this.bridgeReady && this.postBridgeMessage({
690
683
  type: "MARK_SYNC_UPDATE",
691
684
  visitorId: this.data.visitor_id
692
685
  }));
693
686
  }
694
687
  }
695
- getCookie(t) {
688
+ getCookie(e) {
696
689
  if (typeof document > "u")
697
690
  return null;
698
691
  try {
699
- const e = document.cookie.match(new RegExp(`(^| )${t}=([^;]+)`));
700
- if (e) return e[2];
692
+ const t = document.cookie.match(new RegExp(`(^| )${e}=([^;]+)`));
693
+ if (t) return t[2];
701
694
  } catch {
702
695
  }
703
696
  return null;
704
697
  }
705
- setCookie(t, e, i) {
698
+ setCookie(e, t, i) {
706
699
  if (!(typeof document > "u"))
707
700
  try {
708
701
  const n = new Date(Date.now() + i * 24 * 60 * 60 * 1e3), o = this.options.cookie_domain ? `;domain=${this.options.cookie_domain}` : "";
709
- document.cookie = `${t}=${e};expires=${n.toUTCString()};path=/;SameSite=Lax${o}`;
702
+ document.cookie = `${e}=${t};expires=${n.toUTCString()};path=/;SameSite=Lax${o}`;
710
703
  } catch {
711
704
  }
712
705
  }
@@ -714,29 +707,29 @@ class it {
714
707
  if (typeof crypto < "u" && crypto.randomUUID)
715
708
  return crypto.randomUUID();
716
709
  if (typeof crypto < "u" && typeof crypto.getRandomValues == "function") {
717
- const t = crypto.getRandomValues(new Uint8Array(16));
718
- t[6] = t[6] & 15 | 64, t[8] = t[8] & 63 | 128;
719
- const e = Array.from(t, (i) => i.toString(16).padStart(2, "0")).join("");
720
- return `${e.slice(0, 8)}-${e.slice(8, 12)}-${e.slice(12, 16)}-${e.slice(16, 20)}-${e.slice(20)}`;
710
+ const e = crypto.getRandomValues(new Uint8Array(16));
711
+ e[6] = e[6] & 15 | 64, e[8] = e[8] & 63 | 128;
712
+ const t = Array.from(e, (i) => i.toString(16).padStart(2, "0")).join("");
713
+ return `${t.slice(0, 8)}-${t.slice(8, 12)}-${t.slice(12, 16)}-${t.slice(16, 20)}-${t.slice(20)}`;
721
714
  }
722
- return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (t) => {
723
- const e = (Date.now() + Math.random() * 16) % 16 | 0;
724
- return (t === "x" ? e : e & 3 | 8).toString(16);
715
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (e) => {
716
+ const t = (Date.now() + Math.random() * 16) % 16 | 0;
717
+ return (e === "x" ? t : t & 3 | 8).toString(16);
725
718
  });
726
719
  }
727
720
  isCookieEnabled() {
728
721
  return this.options.mode ? this.options.mode === "single" || this.options.mode === "subdomain" : !0;
729
722
  }
730
- setupBridge(t) {
723
+ setupBridge(e) {
731
724
  if (typeof document > "u") return;
732
- let e;
725
+ let t;
733
726
  try {
734
- e = new URL(t.url, window.location.href);
727
+ t = new URL(e.url, window.location.href);
735
728
  } catch {
736
729
  return;
737
730
  }
738
- this.bridgeOrigin = e.origin, this.bridgeFrame = document.createElement("iframe"), this.bridgeFrame.style.display = "none", this.bridgeFrame.setAttribute("aria-hidden", "true"), this.bridgeFrame.src = e.toString();
739
- const i = t.timeout_ms ?? 3e3, n = setTimeout(() => {
731
+ this.bridgeOrigin = t.origin, this.bridgeFrame = document.createElement("iframe"), this.bridgeFrame.style.display = "none", this.bridgeFrame.setAttribute("aria-hidden", "true"), this.bridgeFrame.src = t.toString();
732
+ const i = e.timeout_ms ?? 3e3, n = setTimeout(() => {
740
733
  window.removeEventListener("message", this.handleBridgeMessage);
741
734
  }, i);
742
735
  window.addEventListener("message", this.handleBridgeMessage);
@@ -750,39 +743,39 @@ class it {
750
743
  });
751
744
  });
752
745
  }
753
- handleBridgeMessage = (t) => {
754
- if (!this.bridgeFrame?.contentWindow || t.source !== this.bridgeFrame.contentWindow || !this.isDomainAllowed(t.origin))
746
+ handleBridgeMessage = (e) => {
747
+ if (!this.bridgeFrame?.contentWindow || e.source !== this.bridgeFrame.contentWindow || !this.isDomainAllowed(e.origin))
755
748
  return;
756
- const e = t.data;
757
- !e || !e.type || e.type === "MARK_SYNC_RESPONSE" && e.visitorId && e.visitorId !== this.data.visitor_id && (this.data.visitor_id = e.visitorId, this.save());
749
+ const t = e.data;
750
+ !t || !t.type || t.type === "MARK_SYNC_RESPONSE" && t.visitorId && t.visitorId !== this.data.visitor_id && (this.data.visitor_id = t.visitorId, this.save());
758
751
  };
759
- postBridgeMessage(t) {
760
- this.bridgeFrame?.contentWindow && this.bridgeFrame.contentWindow.postMessage(t, this.bridgeOrigin ?? "*");
752
+ postBridgeMessage(e) {
753
+ this.bridgeFrame?.contentWindow && this.bridgeFrame.contentWindow.postMessage(e, this.bridgeOrigin ?? "*");
761
754
  }
762
- isDomainAllowed(t) {
755
+ isDomainAllowed(e) {
763
756
  try {
764
- const e = new URL(t);
757
+ const t = new URL(e);
765
758
  if (this.options.allowed_domains?.length)
766
759
  return this.options.allowed_domains.some(
767
- (n) => e.hostname === n || e.hostname.endsWith(`.${n}`)
760
+ (n) => t.hostname === n || t.hostname.endsWith(`.${n}`)
768
761
  );
769
762
  if (!this.bridgeOrigin)
770
763
  return !1;
771
764
  const i = new URL(this.bridgeOrigin);
772
- return e.hostname === i.hostname;
765
+ return t.hostname === i.hostname;
773
766
  } catch {
774
767
  return !1;
775
768
  }
776
769
  }
777
- handleStorageEvent = (t) => {
778
- if (!(t.key !== this.storageKey || typeof t.newValue != "string"))
770
+ handleStorageEvent = (e) => {
771
+ if (!(e.key !== this.storageKey || typeof e.newValue != "string"))
779
772
  try {
780
- this.data = JSON.parse(t.newValue);
773
+ this.data = JSON.parse(e.newValue);
781
774
  } catch {
782
775
  }
783
776
  };
784
777
  }
785
- const nt = [
778
+ const se = [
786
779
  "click_id",
787
780
  "ch_click_id",
788
781
  "gclid",
@@ -794,7 +787,7 @@ const nt = [
794
787
  "ttclid",
795
788
  "twclid",
796
789
  "li_fat_id"
797
- ], st = ["cid", "campaign_id"], rt = [
790
+ ], re = ["cid", "campaign_id"], oe = [
798
791
  "utm_source",
799
792
  "utm_medium",
800
793
  "utm_campaign",
@@ -816,91 +809,91 @@ const nt = [
816
809
  "ttclid",
817
810
  "twclid",
818
811
  "li_fat_id"
819
- ], ot = {
812
+ ], ae = {
820
813
  referral: "ref",
821
814
  affiliate_id: "ref",
822
815
  ch_click_id: "click_id",
823
816
  cid: "campaign_id"
824
- }, at = ["email", "phone", "token", "auth", "password", "code"], ct = 30, dt = 256;
825
- function U(r, t = {}) {
826
- const e = new URLSearchParams(r), i = lt(e), n = R(i, nt), o = R(i, st), a = ut(e, t), c = {};
817
+ }, ce = ["email", "phone", "token", "auth", "password", "code"], de = 30, ue = 256;
818
+ function R(r, e = {}) {
819
+ const t = new URLSearchParams(r), i = fe(t), n = F(i, se), o = F(i, re), a = le(t, e), c = {};
827
820
  return n && (c.last_click_id = n), o && (c.campaign_id = o), Object.keys(a).length > 0 && (c.query_params = a), c;
828
821
  }
829
- function ut(r, t) {
830
- const e = {}, i = new Set(B(t.query_param_denylist, at)), n = F(
831
- t.max_captured_query_params,
832
- ct
833
- ), o = F(
834
- t.max_query_param_value_length,
835
- dt
836
- ), c = t.capture_all_query_params ?? !1 ? null : /* @__PURE__ */ new Set([
837
- ...rt.map(S),
838
- ...B(t.capture_query_params, [])
822
+ function le(r, e) {
823
+ const t = {}, i = new Set(B(e.query_param_denylist, ce)), n = O(
824
+ e.max_captured_query_params,
825
+ de
826
+ ), o = O(
827
+ e.max_query_param_value_length,
828
+ ue
829
+ ), c = e.capture_all_query_params ?? !1 ? null : /* @__PURE__ */ new Set([
830
+ ...oe.map(x),
831
+ ...B(e.capture_query_params, [])
839
832
  ]);
840
- for (const [f, l] of r.entries()) {
841
- const d = S(f);
833
+ for (const [f, u] of r.entries()) {
834
+ const d = x(f);
842
835
  if (!d)
843
836
  continue;
844
- const h = ot[d] ?? d;
837
+ const h = ae[d] ?? d;
845
838
  if (i.has(d) || i.has(h) || c && !c.has(d))
846
839
  continue;
847
- const u = l.trim();
848
- if (u) {
849
- if (!(h in e) && Object.keys(e).length >= n)
840
+ const l = u.trim();
841
+ if (l) {
842
+ if (!(h in t) && Object.keys(t).length >= n)
850
843
  break;
851
- e[h] = u.slice(0, o);
844
+ t[h] = l.slice(0, o);
852
845
  }
853
846
  }
854
- return e;
847
+ return t;
855
848
  }
856
- function R(r, t) {
857
- for (const e of t) {
858
- const i = S(e), n = r[i]?.trim();
849
+ function F(r, e) {
850
+ for (const t of e) {
851
+ const i = x(t), n = r[i]?.trim();
859
852
  if (n)
860
853
  return n;
861
854
  }
862
855
  }
863
- function lt(r) {
864
- const t = {};
865
- for (const [e, i] of r.entries()) {
866
- const n = S(e);
867
- !n || n in t || (t[n] = i);
856
+ function fe(r) {
857
+ const e = {};
858
+ for (const [t, i] of r.entries()) {
859
+ const n = x(t);
860
+ !n || n in e || (e[n] = i);
868
861
  }
869
- return t;
862
+ return e;
870
863
  }
871
- function S(r) {
864
+ function x(r) {
872
865
  return r.trim().toLowerCase();
873
866
  }
874
- function B(r, t) {
875
- const e = r ?? t, i = /* @__PURE__ */ new Set();
876
- for (const n of e) {
867
+ function B(r, e) {
868
+ const t = r ?? e, i = /* @__PURE__ */ new Set();
869
+ for (const n of t) {
877
870
  if (typeof n != "string") continue;
878
- const o = S(n);
871
+ const o = x(n);
879
872
  o && i.add(o);
880
873
  }
881
874
  return Array.from(i);
882
875
  }
883
- function F(r, t) {
876
+ function O(r, e) {
884
877
  if (typeof r != "number" || !Number.isFinite(r))
885
- return t;
886
- const e = Math.floor(r);
887
- return e < 0 ? t : e;
878
+ return e;
879
+ const t = Math.floor(r);
880
+ return t < 0 ? e : t;
888
881
  }
889
- function x(r) {
882
+ function k(r) {
890
883
  return r.length > 1 && r.endsWith("/") ? r.slice(0, -1) : r;
891
884
  }
892
- function ft(r) {
885
+ function he(r) {
893
886
  if (!r || r === "?")
894
887
  return "";
895
- const t = r.startsWith("?") ? r.slice(1) : r;
896
- if (!t)
888
+ const e = r.startsWith("?") ? r.slice(1) : r;
889
+ if (!e)
897
890
  return "";
898
- const e = new URLSearchParams(t), i = [];
899
- e.forEach((a, c) => {
891
+ const t = new URLSearchParams(e), i = [];
892
+ t.forEach((a, c) => {
900
893
  i.push([c, a]);
901
- }), i.sort(([a, c], [f, l]) => {
894
+ }), i.sort(([a, c], [f, u]) => {
902
895
  const d = a.localeCompare(f);
903
- return d !== 0 ? d : c.localeCompare(l);
896
+ return d !== 0 ? d : c.localeCompare(u);
904
897
  });
905
898
  const n = new URLSearchParams();
906
899
  for (const [a, c] of i)
@@ -908,140 +901,146 @@ function ft(r) {
908
901
  const o = n.toString();
909
902
  return o === "" ? "" : `?${o}`;
910
903
  }
911
- function q(r) {
912
- const t = x(r.pathname), e = ft(r.search);
913
- return `${r.origin}${t}${e}${r.hash}`;
904
+ function P(r) {
905
+ const e = k(r.pathname), t = he(r.search);
906
+ return `${r.origin}${e}${t}${r.hash}`;
914
907
  }
915
- let D = !1, m = null;
916
- const w = [], y = [], _ = [];
917
- let v = null, b = null, A = null, I = null;
918
- function C() {
908
+ let q = !1, w = null;
909
+ const y = [], _ = [], v = [];
910
+ let b = null, A = null, I = null, S = null, E = null;
911
+ function D() {
919
912
  if (typeof window > "u") return;
920
- const r = q(window.location);
921
- if (r === m) return;
922
- const t = { previousKey: m, nextKey: r };
923
- for (const e of w)
924
- e(t);
925
- m = r;
926
- for (const e of y)
927
- e(t);
913
+ const r = P(window.location);
914
+ if (r === w) return;
915
+ const e = { previousKey: w, nextKey: r };
916
+ for (const t of y)
917
+ t(e);
918
+ w = r;
919
+ for (const t of _)
920
+ t(e);
928
921
  }
929
- function ht() {
930
- for (const r of _)
922
+ function ge() {
923
+ for (const r of v)
931
924
  r();
932
925
  }
933
- function gt(r = {}) {
934
- if (D || typeof window > "u" || typeof document > "u")
926
+ function pe(r = {}) {
927
+ if (q || typeof window > "u" || typeof document > "u")
935
928
  return;
936
- D = !0;
937
- const t = r.trackRouteChanges ?? !0;
938
- m = q(window.location), I = ht, window.addEventListener("pagehide", I), t && (v = history.pushState, b = history.replaceState, history.pushState = function(...e) {
939
- const i = v.apply(this, e);
940
- return C(), i;
941
- }, history.replaceState = function(...e) {
942
- const i = b.apply(this, e);
943
- return C(), i;
944
- }, A = C, window.addEventListener("popstate", A));
945
- }
946
- function pt(r) {
947
- return w.push(r), () => {
948
- const t = w.indexOf(r);
949
- t >= 0 && w.splice(t, 1);
950
- };
929
+ q = !0;
930
+ const e = r.trackRouteChanges ?? !0;
931
+ w = P(window.location), E = ge, window.addEventListener("pagehide", E), e && (b = history.pushState, A = history.replaceState, history.pushState = function(...t) {
932
+ const i = b.apply(this, t);
933
+ return D(), i;
934
+ }, history.replaceState = function(...t) {
935
+ const i = A.apply(this, t);
936
+ return D(), i;
937
+ }, I = D, window.addEventListener("popstate", I), S = D, window.addEventListener("hashchange", S));
951
938
  }
952
- function P(r) {
939
+ function me(r) {
953
940
  return y.push(r), () => {
954
- const t = y.indexOf(r);
955
- t >= 0 && y.splice(t, 1);
941
+ const e = y.indexOf(r);
942
+ e >= 0 && y.splice(e, 1);
956
943
  };
957
944
  }
958
- function mt(r) {
945
+ function U(r) {
959
946
  return _.push(r), () => {
960
- const t = _.indexOf(r);
961
- t >= 0 && _.splice(t, 1);
947
+ const e = _.indexOf(r);
948
+ e >= 0 && _.splice(e, 1);
949
+ };
950
+ }
951
+ function we(r) {
952
+ return v.push(r), () => {
953
+ const e = v.indexOf(r);
954
+ e >= 0 && v.splice(e, 1);
962
955
  };
963
956
  }
964
- function wt() {
965
- !D || typeof window > "u" || (v && (history.pushState = v), b && (history.replaceState = b), A && window.removeEventListener("popstate", A), I && window.removeEventListener("pagehide", I), v = null, b = null, A = null, I = null, w.length = 0, y.length = 0, _.length = 0, m = null, D = !1);
957
+ function ye() {
958
+ !q || typeof window > "u" || (b && (history.pushState = b), A && (history.replaceState = A), I && window.removeEventListener("popstate", I), S && window.removeEventListener("hashchange", S), E && window.removeEventListener("pagehide", E), b = null, A = null, I = null, S = null, E = null, y.length = 0, _.length = 0, v.length = 0, w = null, q = !1);
966
959
  }
967
- let T = 0;
968
- function H() {
969
- T = 0;
960
+ let C = 0;
961
+ function V() {
962
+ C = 0;
970
963
  }
971
- function yt() {
972
- return T;
964
+ function _e() {
965
+ return C;
973
966
  }
974
- function _t() {
967
+ function ve() {
975
968
  if (typeof document > "u" || typeof window > "u")
976
969
  return 0;
977
- const r = document.documentElement, t = window.scrollY || r.scrollTop, e = Math.max(1, r.scrollHeight - window.innerHeight);
978
- return Math.min(100, Math.round(t / e * 100));
970
+ const r = document.documentElement, e = window.scrollY || r.scrollTop, t = Math.max(1, r.scrollHeight - window.innerHeight);
971
+ return Math.min(100, Math.round(e / t * 100));
979
972
  }
980
973
  function K() {
981
- const r = _t();
982
- return r > T && (T = r), r;
974
+ const r = ve();
975
+ return r > C && (C = r), r;
983
976
  }
984
- const vt = [25, 50, 75, 100];
985
- function bt(r, t = vt) {
977
+ const be = [25, 50, 75, 100];
978
+ function Ae(r, e = be) {
986
979
  if (typeof window > "u") return;
987
- const e = /* @__PURE__ */ new Set(), i = () => {
988
- e.clear(), H();
980
+ const t = /* @__PURE__ */ new Set(), i = () => {
981
+ t.clear(), V();
989
982
  };
990
- i(), P(() => {
983
+ i(), U(() => {
991
984
  i();
992
985
  }), window.addEventListener(
993
986
  "scroll",
994
987
  () => {
995
988
  const n = K();
996
- for (const o of t)
997
- n >= o && !e.has(o) && (e.add(o), r.track("scroll_depth", { percent: o }));
989
+ for (const o of e)
990
+ n >= o && !t.has(o) && (t.add(o), r.track("scroll_depth", { percent: o }));
998
991
  },
999
992
  { passive: !0 }
1000
993
  );
1001
994
  }
1002
- const O = 1e4;
1003
- function At(r) {
1004
- return r === !0 ? { minActiveMs: O, useBeacon: !0 } : {
1005
- minActiveMs: r.min_active_ms ?? O,
995
+ const N = 1e4;
996
+ function Ie(r) {
997
+ return r === !0 ? { minActiveMs: N, useBeacon: !0 } : {
998
+ minActiveMs: r.min_active_ms ?? N,
1006
999
  useBeacon: r.use_beacon !== !1
1007
1000
  };
1008
1001
  }
1009
- function It(r, t) {
1002
+ function Se(r, e) {
1010
1003
  if (typeof window > "u" || typeof document > "u") return;
1011
- let e = Date.now(), i = 0, n = document.visibilityState === "visible" ? Date.now() : null, o = x(window.location.pathname), a = !1;
1004
+ let t = Date.now(), i = 0, n = document.visibilityState === "visible" ? Date.now() : null, o = k(window.location.pathname), a = !1;
1012
1005
  const c = () => {
1013
1006
  n !== null && (i += Date.now() - n, n = null);
1014
1007
  }, f = () => {
1015
1008
  document.visibilityState === "visible" && n === null && (n = Date.now());
1016
- }, l = (h) => {
1009
+ }, u = () => {
1010
+ document.visibilityState === "visible" ? f() : c();
1011
+ }, d = (l) => {
1017
1012
  if (!a) {
1018
1013
  a = !0;
1019
1014
  try {
1020
- if (c(), K(), i < t.minActiveMs)
1015
+ if (c(), K(), i < e.minActiveMs) {
1016
+ e.debug && console.debug("[Mark] page_engagement skipped (active time below min_active_ms)", {
1017
+ page: o,
1018
+ active_time_ms: i,
1019
+ min_active_ms: e.minActiveMs
1020
+ });
1021
1021
  return;
1022
- const u = Date.now() - e, g = {
1022
+ }
1023
+ const p = Date.now() - t, m = {
1023
1024
  page: o,
1024
1025
  active_time_ms: i,
1025
- total_time_ms: u,
1026
- max_scroll_percent: yt()
1026
+ total_time_ms: p,
1027
+ max_scroll_percent: _e()
1027
1028
  };
1028
- t.useBeacon && h ? r.trackWithOptions("page_engagement", g, { preferBeacon: !0 }) : r.track("page_engagement", g);
1029
+ e.useBeacon && l ? r.trackWithOptions("page_engagement", m, { preferBeacon: !0 }) : r.track("page_engagement", m);
1029
1030
  } finally {
1030
1031
  a = !1;
1031
1032
  }
1032
1033
  }
1033
- }, d = () => {
1034
- e = Date.now(), i = 0, o = x(window.location.pathname), H(), f();
1034
+ }, h = () => {
1035
+ t = Date.now(), i = 0, o = k(window.location.pathname), V(), f();
1035
1036
  };
1036
- d(), pt(() => {
1037
- l(!0), c();
1038
- }), P(() => {
1039
- d();
1040
- }), mt(() => {
1041
- l(!0);
1042
- }), document.addEventListener("visibilitychange", () => {
1043
- document.visibilityState === "hidden" ? c() : f();
1044
- });
1037
+ h(), me(() => {
1038
+ d(!1), c();
1039
+ }), U(() => {
1040
+ h();
1041
+ }), we(() => {
1042
+ d(!0);
1043
+ }), document.addEventListener("visibilitychange", u), window.addEventListener("pageshow", u), window.addEventListener("focus", u), queueMicrotask(u), typeof requestAnimationFrame == "function" && requestAnimationFrame(u);
1045
1044
  }
1046
1045
  class s {
1047
1046
  static client = null;
@@ -1055,56 +1054,56 @@ class s {
1055
1054
  static visibilityHandler = null;
1056
1055
  static onlineHandler = null;
1057
1056
  static kickTimer = null;
1058
- static init(t) {
1057
+ static init(e) {
1059
1058
  if (!s.client) {
1060
- const e = new it({
1061
- ...t.cross_domain,
1062
- seed_visitor_id: t.visitor_id
1063
- }), i = new Z(t);
1064
- s.client = new J(t, { storage: e, transport: i }), s.storage = e, s.config = t, s.refreshAttribution(e, t), typeof window < "u" && (s.installPageLifecycleIfNeeded(t), t.autocapture?.pageview && s.installPageviewTracking(t, e), s.installExtendedAutocapture(t), s.installLifecycleFlushing());
1059
+ const t = new ne({
1060
+ ...e.cross_domain,
1061
+ seed_visitor_id: e.visitor_id
1062
+ }), i = new ee(e);
1063
+ s.client = new Z(e, { storage: t, transport: i }), s.storage = t, s.config = e, s.refreshAttribution(t, e), typeof window < "u" && (s.installPageLifecycleIfNeeded(e), e.autocapture?.pageview && s.installPageviewTracking(e, t), s.installExtendedAutocapture(e), s.installLifecycleFlushing());
1065
1064
  }
1066
1065
  return s.client;
1067
1066
  }
1068
1067
  static installLifecycleFlushing() {
1069
1068
  if (typeof window > "u" || s.beaconDrainHandler) return;
1070
- const t = () => {
1069
+ const e = () => {
1071
1070
  s.client?.drainViaBeacon();
1072
- }, e = () => {
1073
- typeof document < "u" && document.visibilityState === "hidden" && t();
1071
+ }, t = () => {
1072
+ typeof document < "u" && document.visibilityState === "hidden" && e();
1074
1073
  }, i = () => {
1075
1074
  s.client?.kickQueue();
1076
1075
  };
1077
- s.beaconDrainHandler = t, s.visibilityHandler = e, s.onlineHandler = i, typeof document < "u" && typeof document.addEventListener == "function" && document.addEventListener("visibilitychange", e), typeof window.addEventListener == "function" && (window.addEventListener("pagehide", t), window.addEventListener("beforeunload", t), window.addEventListener("online", i)), typeof setInterval == "function" && (s.kickTimer = setInterval(() => {
1076
+ s.beaconDrainHandler = e, s.visibilityHandler = t, s.onlineHandler = i, typeof document < "u" && typeof document.addEventListener == "function" && document.addEventListener("visibilitychange", t), typeof window.addEventListener == "function" && (window.addEventListener("pagehide", e), window.addEventListener("beforeunload", e), window.addEventListener("online", i)), typeof setInterval == "function" && (s.kickTimer = setInterval(() => {
1078
1077
  s.client?.kickQueue();
1079
1078
  }, 3e4));
1080
1079
  }
1081
- static track(t, e = {}) {
1080
+ static track(e, t = {}) {
1082
1081
  if (!s.client) {
1083
1082
  s.config?.debug && console.warn("[Mark] Not initialized. Call init() first.");
1084
1083
  return;
1085
1084
  }
1086
- s.client.track(t, e);
1085
+ s.client.track(e, t);
1087
1086
  }
1088
- static identify(t, e = {}) {
1087
+ static identify(e, t = {}) {
1089
1088
  if (!s.client) {
1090
1089
  s.config?.debug && console.warn("[Mark] Not initialized. Call init() first.");
1091
1090
  return;
1092
1091
  }
1093
- s.client.identify(t, e);
1092
+ s.client.identify(e, t);
1094
1093
  }
1095
- static conversion(t, e = {}) {
1094
+ static conversion(e, t = {}) {
1096
1095
  if (!s.client) {
1097
1096
  s.config?.debug && console.warn("[Mark] Not initialized. Call init() first.");
1098
1097
  return;
1099
1098
  }
1100
- s.client.conversion(t, e);
1099
+ s.client.conversion(e, t);
1101
1100
  }
1102
- static setConsent(t) {
1101
+ static setConsent(e) {
1103
1102
  if (!s.client) {
1104
1103
  s.config?.debug && console.warn("[Mark] Not initialized. Call init() first.");
1105
1104
  return;
1106
1105
  }
1107
- s.client.setConsent(t), t === "granted" && (s.flushPendingAttribution(), s.emitAutoPageview?.());
1106
+ s.client.setConsent(e), e === "granted" && (s.flushPendingAttribution(), s.emitAutoPageview?.());
1108
1107
  }
1109
1108
  /**
1110
1109
  * Returns the current visitor ID when available.
@@ -1124,8 +1123,8 @@ class s {
1124
1123
  * same source id. Returns false when the id is invalid or the SDK is not
1125
1124
  * initialized.
1126
1125
  */
1127
- static setVisitorId(t) {
1128
- return s.client ? s.client.setVisitorId(t) : (s.config?.debug && console.warn("[Mark] Not initialized. Call init() first."), !1);
1126
+ static setVisitorId(e) {
1127
+ return s.client ? s.client.setVisitorId(e) : (s.config?.debug && console.warn("[Mark] Not initialized. Call init() first."), !1);
1129
1128
  }
1130
1129
  static flush() {
1131
1130
  return s.client ? s.client.flush() : Promise.resolve();
@@ -1144,12 +1143,12 @@ class s {
1144
1143
  * if (params.get('onelence_internal') === '1') Mark.setInternal(true);
1145
1144
  * if (params.get('onelence_internal') === '0') Mark.setInternal(false);
1146
1145
  */
1147
- static setInternal(t) {
1146
+ static setInternal(e) {
1148
1147
  if (!s.client) {
1149
1148
  s.config?.debug && console.warn("[Mark] Not initialized. Call init() first.");
1150
1149
  return;
1151
1150
  }
1152
- s.client.setInternal(t);
1151
+ s.client.setInternal(e);
1153
1152
  }
1154
1153
  static getInternal() {
1155
1154
  return s.client?.getInternal() ?? !1;
@@ -1161,73 +1160,73 @@ class s {
1161
1160
  return s.client?.getStats() ?? { queued: 0, sent: 0, failed: 0, dropped: 0 };
1162
1161
  }
1163
1162
  static destroy() {
1164
- typeof window > "u" || (wt(), s.beaconDrainHandler && (window.removeEventListener("pagehide", s.beaconDrainHandler), window.removeEventListener("beforeunload", s.beaconDrainHandler)), s.visibilityHandler && typeof document < "u" && document.removeEventListener("visibilitychange", s.visibilityHandler), s.onlineHandler && window.removeEventListener("online", s.onlineHandler), s.kickTimer && clearInterval(s.kickTimer), s.beaconDrainHandler = null, s.visibilityHandler = null, s.onlineHandler = null, s.kickTimer = null, s.pageviewTrackerInstalled = !1);
1163
+ typeof window > "u" || (ye(), s.beaconDrainHandler && (window.removeEventListener("pagehide", s.beaconDrainHandler), window.removeEventListener("beforeunload", s.beaconDrainHandler)), s.visibilityHandler && typeof document < "u" && document.removeEventListener("visibilitychange", s.visibilityHandler), s.onlineHandler && window.removeEventListener("online", s.onlineHandler), s.kickTimer && clearInterval(s.kickTimer), s.beaconDrainHandler = null, s.visibilityHandler = null, s.onlineHandler = null, s.kickTimer = null, s.pageviewTrackerInstalled = !1);
1165
1164
  }
1166
- static installPageLifecycleIfNeeded(t) {
1167
- const e = t.autocapture;
1168
- if (!(!!e?.pageview || !!e?.scroll_depth || !!e?.page_engagement)) return;
1169
- const n = t.track_route_changes ?? !0;
1170
- gt({ trackRouteChanges: n });
1165
+ static installPageLifecycleIfNeeded(e) {
1166
+ const t = e.autocapture;
1167
+ if (!(!!t?.pageview || !!t?.scroll_depth || !!t?.page_engagement)) return;
1168
+ const n = e.track_route_changes ?? !0;
1169
+ pe({ trackRouteChanges: n });
1171
1170
  }
1172
- static installPageviewTracking(t, e) {
1171
+ static installPageviewTracking(e, t) {
1173
1172
  if (s.pageviewTrackerInstalled) return;
1174
1173
  s.pageviewTrackerInstalled = !0;
1175
1174
  const i = () => {
1176
1175
  if (!s.client) return;
1177
- s.refreshAttribution(e, t);
1178
- const o = q(window.location);
1176
+ s.refreshAttribution(t, e);
1177
+ const o = P(window.location);
1179
1178
  if (o === s.lastPageviewDedupeKey) return;
1180
1179
  s.client.track("page_view", {
1181
1180
  site: window.location.host,
1182
- page: x(window.location.pathname),
1181
+ page: k(window.location.pathname),
1183
1182
  title: document.title,
1184
1183
  referrer: document.referrer || void 0
1185
1184
  }) && (s.lastPageviewDedupeKey = o);
1186
1185
  };
1187
- s.emitAutoPageview = i, i(), (t.track_route_changes ?? !0) && P(() => {
1186
+ s.emitAutoPageview = i, i(), (e.track_route_changes ?? !0) && U(() => {
1188
1187
  i();
1189
1188
  });
1190
1189
  }
1191
- static refreshAttribution(t, e) {
1190
+ static refreshAttribution(e, t) {
1192
1191
  if (typeof window > "u")
1193
1192
  return;
1194
- const i = U(window.location.search, e);
1193
+ const i = R(window.location.search, t);
1195
1194
  if (Object.keys(i).length !== 0) {
1196
- if (s.shouldPersistAttribution(t, e)) {
1195
+ if (s.shouldPersistAttribution(e, t)) {
1197
1196
  const n = s.mergeAttributionUpdates(s.pendingAttribution, i);
1198
- t.update(n), s.pendingAttribution = {};
1197
+ e.update(n), s.pendingAttribution = {};
1199
1198
  return;
1200
1199
  }
1201
1200
  s.pendingAttribution = s.mergeAttributionUpdates(s.pendingAttribution, i);
1202
1201
  }
1203
1202
  }
1204
1203
  static flushPendingAttribution() {
1205
- const t = s.storage, e = s.config;
1206
- if (!t || !e || typeof window > "u")
1204
+ const e = s.storage, t = s.config;
1205
+ if (!e || !t || typeof window > "u")
1207
1206
  return;
1208
- const i = U(window.location.search, e), n = s.mergeAttributionUpdates(s.pendingAttribution, i);
1209
- Object.keys(n).length > 0 && t.update(n), s.pendingAttribution = {};
1207
+ const i = R(window.location.search, t), n = s.mergeAttributionUpdates(s.pendingAttribution, i);
1208
+ Object.keys(n).length > 0 && e.update(n), s.pendingAttribution = {};
1210
1209
  }
1211
- static shouldPersistAttribution(t, e) {
1212
- return e.require_consent ?? !1 ? t.getConsentStatus() === "granted" : !0;
1210
+ static shouldPersistAttribution(e, t) {
1211
+ return t.require_consent ?? !1 ? e.getConsentStatus() === "granted" : !0;
1213
1212
  }
1214
- static mergeAttributionUpdates(t, e) {
1213
+ static mergeAttributionUpdates(e, t) {
1215
1214
  return {
1216
- ...t,
1217
1215
  ...e,
1216
+ ...t,
1218
1217
  query_params: {
1219
- ...t.query_params ?? {},
1220
- ...e.query_params ?? {}
1218
+ ...e.query_params ?? {},
1219
+ ...t.query_params ?? {}
1221
1220
  }
1222
1221
  };
1223
1222
  }
1224
- static installExtendedAutocapture(t) {
1223
+ static installExtendedAutocapture(e) {
1225
1224
  if (!s.client || typeof document > "u") return;
1226
- const e = t.autocapture;
1227
- e && (e.click && document.addEventListener("click", (i) => {
1225
+ const t = e.autocapture;
1226
+ t && (t.click && document.addEventListener("click", (i) => {
1228
1227
  const n = i.target;
1229
1228
  if (!n) return;
1230
- const o = typeof e.click == "object" ? e.click.selector : void 0, a = o ? n.closest(o) : n.closest("[data-mark-event]");
1229
+ const o = typeof t.click == "object" ? t.click.selector : void 0, a = o ? n.closest(o) : n.closest("[data-mark-event]");
1231
1230
  if (!a) return;
1232
1231
  const c = a.getAttribute("data-mark-event") || "click";
1233
1232
  s.client?.track(c, {
@@ -1236,14 +1235,14 @@ class s {
1236
1235
  text: a.textContent?.trim().slice(0, 120) || void 0,
1237
1236
  href: a.href || void 0
1238
1237
  });
1239
- }), e.form_submit && document.addEventListener("submit", (i) => {
1238
+ }), t.form_submit && document.addEventListener("submit", (i) => {
1240
1239
  const n = i.target;
1241
1240
  n && s.client?.track("form_submit", {
1242
1241
  form_id: n.id || void 0,
1243
1242
  form_name: n.name || void 0,
1244
1243
  action: n.action || void 0
1245
1244
  });
1246
- }), e.outbound_link && document.addEventListener("click", (i) => {
1245
+ }), t.outbound_link && document.addEventListener("click", (i) => {
1247
1246
  const n = i.target?.closest("a[href]");
1248
1247
  if (!(!n || !n.href))
1249
1248
  try {
@@ -1251,7 +1250,10 @@ class s {
1251
1250
  o.origin !== a.origin && s.client?.trackWithOptions("outbound_link_click", { href: o.toString() }, { preferBeacon: !0 });
1252
1251
  } catch {
1253
1252
  }
1254
- }), e.scroll_depth && s.client && bt(s.client), e.page_engagement && s.client && It(s.client, At(e.page_engagement)), e.web_vitals && import("./web-vitals-CrnTllyu.js").then((i) => {
1253
+ }), t.scroll_depth && s.client && Ae(s.client), t.page_engagement && s.client && Se(s.client, {
1254
+ ...Ie(t.page_engagement),
1255
+ debug: e.debug
1256
+ }), t.web_vitals && import("./web-vitals-CrnTllyu.js").then((i) => {
1255
1257
  const n = (o) => {
1256
1258
  s.client?.track("web_vital", {
1257
1259
  metric: o.name,
@@ -1262,7 +1264,7 @@ class s {
1262
1264
  };
1263
1265
  i.onLCP(n), i.onCLS(n), i.onINP(n), i.onTTFB(n);
1264
1266
  }).catch(() => {
1265
- t.debug && console.warn("[Mark] web-vitals package not available; skipping autocapture.web_vitals.");
1267
+ e.debug && console.warn("[Mark] web-vitals package not available; skipping autocapture.web_vitals.");
1266
1268
  }));
1267
1269
  }
1268
1270
  }