@crelora/mark 0.2.0 → 0.2.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,41 +1,41 @@
1
- const I = "https://ingest.onelence.com";
2
- class h extends Error {
1
+ const O = "https://ingest.onelence.com";
2
+ class p 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 S(c) {
10
- return !(typeof c != "number" || c < 400 || c >= 500 || c === 408 || c === 429);
9
+ function H(r) {
10
+ return !(typeof r != "number" || r < 400 || r >= 500 || r === 408 || r === 429);
11
11
  }
12
- function E(c) {
13
- if (!c) return;
14
- const t = c.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);
12
+ function V(r) {
13
+ if (!r) return;
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
- const s = i - Date.now();
22
- return s > 0 ? s : 0;
21
+ const n = i - Date.now();
22
+ return n > 0 ? n : 0;
23
23
  }
24
24
  }
25
- const x = 5, q = 300, T = 15e3, D = 2880 * 60 * 1e3;
26
- class C {
27
- constructor(t, e = {}) {
28
- this.transport = t, this.maxAttempts = e.maxAttempts ?? x, this.baseBackoffMs = e.baseBackoffMs ?? q, this.maxBackoffMs = e.maxBackoffMs ?? T, this.maxItemAgeMs = e.maxItemAgeMs ?? D, this.debug = e.debug ?? !1, this.loadPersisted = e.loadPersisted, this.savePersisted = e.savePersisted, this.onError = e.onError;
25
+ const z = 5, $ = 300, M = 15e3, j = 2880 * 60 * 1e3;
26
+ class Y {
27
+ constructor(e, t = {}) {
28
+ this.transport = e, this.maxAttempts = t.maxAttempts ?? z, this.baseBackoffMs = t.baseBackoffMs ?? $, this.maxBackoffMs = t.maxBackoffMs ?? M, this.maxItemAgeMs = t.maxItemAgeMs ?? j, 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
- const s = Date.now();
32
- for (const r of i) {
33
- const o = r.enqueuedAt ?? s;
34
- if (s - o > this.maxItemAgeMs) {
31
+ const n = Date.now();
32
+ for (const o of i) {
33
+ const a = o.enqueuedAt ?? n;
34
+ if (n - a > this.maxItemAgeMs) {
35
35
  this.dropped += 1;
36
36
  continue;
37
37
  }
38
- this.queue.push({ ...r, enqueuedAt: o });
38
+ this.queue.push({ ...o, enqueuedAt: a });
39
39
  }
40
40
  this.persist();
41
41
  }
@@ -53,10 +53,10 @@ class C {
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()
@@ -71,13 +71,13 @@ class C {
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,46 +98,46 @@ class C {
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
- for (let s = this.queue.length - 1; s >= 0; s -= 1)
104
- this.queue[s].enqueuedAt <= e && (this.queue.splice(s, 1), this.dropped += 1, i += 1);
103
+ for (let n = this.queue.length - 1; n >= 0; n -= 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 }, s = i.__prefer_beacon === !0;
117
- delete i.__prefer_beacon, await this.transport.send(e.path, i, { preferBeacon: s }), 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 s = i instanceof h ? i.status : void 0;
121
- if (S(s)) {
122
- this.queue.shift(), this.dropped += 1, this.persist(), this.debug && console.error("[Mark] Dropping event after non-retriable status", s, e.path);
119
+ this.failed += 1, this.onError?.(i, t.data);
120
+ const n = i instanceof p ? i.status : void 0;
121
+ if (H(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 r = i instanceof h ? i.retryAfterMs : void 0;
130
- let o;
131
- if (typeof r == "number")
132
- o = Math.min(this.maxBackoffMs, Math.max(0, r));
129
+ const o = i instanceof p ? i.retryAfterMs : void 0;
130
+ let a;
131
+ if (typeof o == "number")
132
+ a = Math.min(this.maxBackoffMs, Math.max(0, o));
133
133
  else {
134
- const a = Math.random() * this.baseBackoffMs;
135
- o = Math.min(
134
+ const c = Math.random() * this.baseBackoffMs;
135
+ a = Math.min(
136
136
  this.maxBackoffMs,
137
- this.baseBackoffMs * 2 ** (e.attempts - 1) + a
137
+ this.baseBackoffMs * 2 ** (t.attempts - 1) + c
138
138
  );
139
139
  }
140
- e.nextAttemptAt = Date.now() + o, this.persist();
140
+ t.nextAttemptAt = Date.now() + a, this.persist();
141
141
  break;
142
142
  }
143
143
  }
@@ -147,7 +147,7 @@ class C {
147
147
  }
148
148
  }
149
149
  }
150
- const U = /* @__PURE__ */ new Set(["event_name", "user_id", "consent_state", "source", "is_conversion"]), k = /* @__PURE__ */ new Set([
150
+ const Q = /* @__PURE__ */ new Set(["event_name", "user_id", "consent_state", "source", "is_conversion"]), W = /* @__PURE__ */ new Set([
151
151
  "user_id",
152
152
  "visitor_id",
153
153
  "click_id",
@@ -156,17 +156,17 @@ const U = /* @__PURE__ */ new Set(["event_name", "user_id", "consent_state", "so
156
156
  "consent_state",
157
157
  "source"
158
158
  ]);
159
- class L {
160
- constructor(t, e) {
161
- this.deps = e, this.validateConfig(t), this.config = {
162
- endpoint: t.endpoint ?? I,
163
- ...t,
164
- include_page_context: t.include_page_context ?? !0
165
- }, 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 C(this.deps.transport, {
159
+ class G {
160
+ constructor(e, t) {
161
+ this.deps = t, this.validateConfig(e), this.config = {
162
+ endpoint: e.endpoint ?? O,
163
+ ...e,
164
+ include_page_context: e.include_page_context ?? !0
165
+ }, 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 Y(this.deps.transport, {
166
166
  debug: this.config.debug,
167
167
  loadPersisted: () => this.deps.storage.getOutbox?.() ?? [],
168
168
  savePersisted: (i) => this.deps.storage.setOutbox?.(i),
169
- onError: (i, s) => this.config.on_error?.(i, s)
169
+ onError: (i, n) => this.config.on_error?.(i, n)
170
170
  }), this.warnMisconfiguredSiteHost(), this.subscribeTcf();
171
171
  }
172
172
  config;
@@ -194,32 +194,32 @@ class L {
194
194
  kickQueue() {
195
195
  this.queue.flush();
196
196
  }
197
- track(t, e = {}) {
198
- return this.trackInternal(t, e, !1);
197
+ track(e, t = {}) {
198
+ return this.trackInternal(e, t, !1);
199
199
  }
200
- trackInternal(t, e = {}, i = !1, s) {
201
- if (!t)
200
+ trackInternal(e, t = {}, i = !1, n) {
201
+ if (!e)
202
202
  return this.config.debug && console.warn("[Mark] track called without event name"), !1;
203
203
  if (!this.hasConsent() || this.isDntBlocked())
204
204
  return this.config.debug && console.warn("[Mark] Tracking blocked due to consent requirement."), !1;
205
205
  if (!i && !this.shouldSampleTrack())
206
206
  return !0;
207
- const r = this.sanitizeTrackData(e), o = { ...r };
208
- "query" in o && delete o.query, "site_id" in o && delete o.site_id, "site_host" in o && delete o.site_host;
209
- const a = {
210
- event_name: t,
207
+ const o = this.sanitizeTrackData(t), a = { ...o };
208
+ "query" in a && delete a.query, "site_id" in a && delete a.site_id, "site_host" in a && delete a.site_host;
209
+ const c = {
210
+ event_name: e,
211
211
  message_id: this.createMessageId(),
212
- ...this.getIdentityFields(r),
213
- ...o
212
+ ...this.getIdentityFields(o),
213
+ ...a
214
214
  };
215
- i && (a.is_conversion = !0);
216
- const l = r.site_id ?? this.siteId, f = r.site_host ?? this.siteHost;
217
- l && (a.site_id = l), f && (a.site_host = f), this.config.include_page_context && typeof window < "u" && (this.applyPageContext(a), !f && a.site && (a.site_host = a.site)), this.applyInternalFlag(a, r.is_internal);
218
- const d = this.config.before_send ? this.config.before_send(a) : a;
219
- return d ? (this.ensureSession(), this.config.batching?.enabled && !i && !s?.preferBeacon ? (this.enqueueBatch(d), !0) : (this.queue.enqueue("/event", { ...d, __prefer_beacon: s?.preferBeacon === !0 }), !0)) : !0;
220
- }
221
- identify(t, e = {}) {
222
- if (!t) {
215
+ i && (c.is_conversion = !0);
216
+ const f = o.site_id ?? this.siteId, l = o.site_host ?? this.siteHost;
217
+ 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);
218
+ const d = this.config.before_send ? this.config.before_send(c) : c;
219
+ 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;
220
+ }
221
+ identify(e, t = {}) {
222
+ if (!e) {
223
223
  this.config.debug && console.warn("[Mark] identify called without userId");
224
224
  return;
225
225
  }
@@ -227,22 +227,22 @@ class L {
227
227
  this.config.debug && console.warn("[Mark] Identify blocked due to consent requirement.");
228
228
  return;
229
229
  }
230
- this.deps.storage.update({ user_id: t });
230
+ this.deps.storage.update({ user_id: e });
231
231
  const i = {
232
- user_id: t,
232
+ user_id: e,
233
233
  message_id: this.createMessageId(),
234
- ...this.sanitizeIdentifyTraits(e),
234
+ ...this.sanitizeIdentifyTraits(t),
235
235
  ...this.getIdentityFields()
236
236
  };
237
237
  this.siteId && (i.site_id = this.siteId), this.siteHost && (i.site_host = this.siteHost), this.applyInternalFlag(i);
238
- const s = this.config.before_send ? this.config.before_send(i) : i;
239
- s && this.queue.enqueue("/identify", s);
238
+ const n = this.config.before_send ? this.config.before_send(i) : i;
239
+ n && (this.ensureSession(), this.applySessionFields(n), this.queue.enqueue("/identify", n));
240
240
  }
241
- conversion(t, e = {}) {
242
- return this.trackInternal(t, e, !0);
241
+ conversion(e, t = {}) {
242
+ return this.trackInternal(e, t, !0);
243
243
  }
244
- trackWithOptions(t, e = {}, i) {
245
- return this.trackInternal(t, e, !1, i);
244
+ trackWithOptions(e, t = {}, i) {
245
+ return this.trackInternal(e, t, !1, i);
246
246
  }
247
247
  /**
248
248
  * Returns the current visitor ID from storage, if any.
@@ -251,18 +251,18 @@ class L {
251
251
  getVisitorId() {
252
252
  return this.deps.storage.getVisitorId();
253
253
  }
254
- setConsent(t) {
255
- const e = this.deps.storage.getConsentStatus();
256
- 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?.();
254
+ setConsent(e) {
255
+ const t = this.deps.storage.getConsentStatus();
256
+ 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?.();
257
257
  const i = {
258
258
  visitor_id: this.deps.storage.getVisitorId(),
259
- consent_state: t,
259
+ consent_state: e,
260
260
  source: "sdk",
261
261
  message_id: this.createMessageId()
262
262
  };
263
263
  this.siteId && (i.site_id = this.siteId), this.siteHost && (i.site_host = this.siteHost), this.applyInternalFlag(i);
264
- const s = this.config.before_send ? this.config.before_send(i) : i;
265
- s && this.queue.enqueue("/consent", s);
264
+ const n = this.config.before_send ? this.config.before_send(i) : i;
265
+ n && this.queue.enqueue("/consent", n);
266
266
  }
267
267
  reset() {
268
268
  this.deps.storage.update({
@@ -286,8 +286,8 @@ class L {
286
286
  * it survives reloads, and is cleared by `reset()` and by
287
287
  * `setConsent('denied')`.
288
288
  */
289
- setInternal(t) {
290
- this.deps.storage.setInternal?.(!!t);
289
+ setInternal(e) {
290
+ this.deps.storage.setInternal?.(!!e);
291
291
  }
292
292
  /**
293
293
  * Returns the currently persisted internal-traffic flag, if any.
@@ -309,59 +309,73 @@ class L {
309
309
  * Explicit `is_internal: false` on a single event wins over the visitor flag
310
310
  * so individual calls can opt out.
311
311
  */
312
- applyInternalFlag(t, e) {
313
- if (e === !1) {
314
- delete t.is_internal;
312
+ applyInternalFlag(e, t) {
313
+ if (t === !1) {
314
+ delete e.is_internal;
315
315
  return;
316
316
  }
317
317
  const i = this.deps.storage.getInternal?.() === !0;
318
- e === !0 || i ? t.is_internal = !0 : delete t.is_internal;
318
+ t === !0 || i ? e.is_internal = !0 : delete e.is_internal;
319
319
  }
320
- getIdentityFields(t) {
321
- const e = t?.visitor_id ?? this.deps.storage.getVisitorId(), i = t?.user_id ?? this.deps.storage.getUserId?.(), s = t?.click_id ?? this.deps.storage.getLastClickId(), r = t?.campaign_id ?? this.deps.storage.getCampaignId(), o = t?.session_id ?? this.deps.storage.getSessionId?.(), a = this.deps.storage.getQueryParams() ?? {}, l = t?.query ?? {}, f = { ...a, ...l }, d = {};
322
- return e && (d.visitor_id = e), i && (d.user_id = i), s && (d.click_id = s), r && (d.campaign_id = r), o && (d.session_id = o), Object.keys(f).length > 0 && (d.query = f), d;
320
+ getIdentityFields(e) {
321
+ 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 ?? {}, l = { ...c, ...f }, d = {};
322
+ 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);
323
+ const h = this.deps.storage.getSessionStartedAt?.();
324
+ 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;
325
+ }
326
+ /**
327
+ * Patches session fields after ensureSession when the first event in a session was built
328
+ * before rotation created an id. Rotation events keep the previous session_id from identity.
329
+ */
330
+ applySessionFields(e) {
331
+ if (!e.session_id) {
332
+ const i = this.deps.storage.getSessionId?.(), n = this.deps.storage.getSessionStartedAt?.();
333
+ i && (e.session_id = i), n && (e.session_started_at = n);
334
+ }
335
+ const t = e.session_started_at;
336
+ e.session_id && typeof t == "string" && (e.session_elapsed_ms = Date.now() - Date.parse(t));
323
337
  }
324
338
  hasConsent() {
325
339
  if (this.config.consent_source?.type === "tcf" && typeof window < "u" && !this.tcfCachedAllowed)
326
340
  return !1;
327
341
  if (!this.consentRequirement)
328
342
  return !0;
329
- const e = this.deps.storage.getConsentStatus();
330
- return this.consentRequirement === "auto", e === "granted";
343
+ const t = this.deps.storage.getConsentStatus();
344
+ return this.consentRequirement === "auto", t === "granted";
331
345
  }
332
- sanitizeTrackData(t) {
333
- const e = {};
334
- for (const [i, s] of Object.entries(t))
335
- U.has(i) || (e[i] = s);
336
- return e;
346
+ sanitizeTrackData(e) {
347
+ const t = {};
348
+ for (const [i, n] of Object.entries(e))
349
+ Q.has(i) || (t[i] = n);
350
+ return t;
337
351
  }
338
- sanitizeIdentifyTraits(t) {
339
- const e = {};
340
- for (const [i, s] of Object.entries(t))
341
- k.has(i) || (e[i] = s);
342
- return e;
352
+ sanitizeIdentifyTraits(e) {
353
+ const t = {};
354
+ for (const [i, n] of Object.entries(e))
355
+ W.has(i) || (t[i] = n);
356
+ return t;
343
357
  }
344
- validateConfig(t) {
345
- if (!t.key || !t.key.trim())
358
+ validateConfig(e) {
359
+ if (!e.key || !e.key.trim())
346
360
  throw new Error("[Mark] `key` must be a non-empty string.");
347
- if (t.endpoint)
361
+ if (e.endpoint)
348
362
  try {
349
- new URL(t.endpoint);
363
+ new URL(e.endpoint);
350
364
  } catch {
351
365
  throw new Error("[Mark] `endpoint` must be a valid absolute URL.");
352
366
  }
353
- if (typeof t.site_id == "string" && !t.site_id.trim())
367
+ if (typeof e.site_id == "string" && !e.site_id.trim())
354
368
  throw new Error("[Mark] `site_id` cannot be an empty string.");
355
- if (typeof t.site_host == "string" && !t.site_host.trim())
369
+ if (typeof e.site_host == "string" && !e.site_host.trim())
356
370
  throw new Error("[Mark] `site_host` cannot be an empty string.");
357
371
  }
358
- applyPageContext(t) {
359
- 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)));
372
+ applyPageContext(e) {
373
+ 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)));
360
374
  }
361
- enqueueBatch(t) {
362
- this.batchedEvents.push(t);
363
- const e = this.config.batching?.max_size ?? 20;
364
- if (this.batchedEvents.length >= e) {
375
+ enqueueBatch(e) {
376
+ this.batchedEvents.push(e);
377
+ const t = this.config.batching?.max_size ?? 20;
378
+ if (this.batchedEvents.length >= t) {
365
379
  this.flushBatch();
366
380
  return;
367
381
  }
@@ -374,28 +388,28 @@ class L {
374
388
  }
375
389
  flushBatch() {
376
390
  if (this.batchedEvents.length === 0) return;
377
- const t = this.config.batching?.endpoint_path ?? "/events", e = this.batchedEvents.splice(0, this.batchedEvents.length);
378
- this.queue.enqueue(t, { events: e, message_id: this.createMessageId() });
391
+ const e = this.config.batching?.endpoint_path ?? "/events", t = this.batchedEvents.splice(0, this.batchedEvents.length);
392
+ this.queue.enqueue(e, { events: t, message_id: this.createMessageId() });
379
393
  }
380
394
  createMessageId() {
381
395
  return typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : `msg_${Date.now()}_${Math.random().toString(16).slice(2)}`;
382
396
  }
383
397
  ensureSession() {
384
- const t = Date.now(), e = this.deps.storage.getSessionId?.(), i = this.deps.storage.getLastActivityAt?.(), s = i ? Date.parse(i) : 0;
385
- if (!e || !s || t - s >= this.sessionTimeoutMs || this.crossedUtcDay(s, t)) {
386
- const o = this.createMessageId(), a = new Date(t).toISOString();
398
+ const e = Date.now(), t = this.deps.storage.getSessionId?.(), i = this.deps.storage.getLastActivityAt?.(), n = i ? Date.parse(i) : 0;
399
+ if (!t || !n || e - n >= this.sessionTimeoutMs || this.crossedUtcDay(n, e)) {
400
+ const a = this.createMessageId(), c = new Date(e).toISOString();
387
401
  this.deps.storage.update({
388
- session_id: o,
389
- session_started_at: a,
390
- last_activity_at: a
402
+ session_id: a,
403
+ session_started_at: c,
404
+ last_activity_at: c
391
405
  });
392
406
  return;
393
407
  }
394
- this.deps.storage.update({ last_activity_at: new Date(t).toISOString() });
408
+ this.deps.storage.update({ last_activity_at: new Date(e).toISOString() });
395
409
  }
396
- crossedUtcDay(t, e) {
397
- const i = new Date(t), s = new Date(e);
398
- return i.getUTCFullYear() !== s.getUTCFullYear() || i.getUTCMonth() !== s.getUTCMonth() || i.getUTCDate() !== s.getUTCDate();
410
+ crossedUtcDay(e, t) {
411
+ const i = new Date(e), n = new Date(t);
412
+ return i.getUTCFullYear() !== n.getUTCFullYear() || i.getUTCMonth() !== n.getUTCMonth() || i.getUTCDate() !== n.getUTCDate();
399
413
  }
400
414
  shouldSampleTrack() {
401
415
  return typeof this.config.sample_rate != "number" ? !0 : this.config.sample_rate <= 0 ? !1 : this.config.sample_rate >= 1 ? !0 : Math.random() <= this.config.sample_rate;
@@ -403,17 +417,17 @@ class L {
403
417
  isDntBlocked() {
404
418
  if (!this.config.honor_dnt || typeof navigator > "u")
405
419
  return !1;
406
- const t = navigator.doNotTrack, e = navigator.globalPrivacyControl;
407
- return t === "1" || e === !0;
420
+ const e = navigator.doNotTrack, t = navigator.globalPrivacyControl;
421
+ return e === "1" || t === !0;
408
422
  }
409
- scrubReferrer(t) {
423
+ scrubReferrer(e) {
410
424
  try {
411
- const e = new URL(t);
412
- if (typeof window > "u") return t;
425
+ const t = new URL(e);
426
+ if (typeof window > "u") return e;
413
427
  const i = new URL(window.location.href);
414
- return e.origin !== i.origin ? (e.search = "", e.toString()) : t;
428
+ return t.origin !== i.origin ? (t.search = "", t.toString()) : e;
415
429
  } catch {
416
- return t;
430
+ return e;
417
431
  }
418
432
  }
419
433
  warnMisconfiguredSiteHost() {
@@ -429,26 +443,26 @@ class L {
429
443
  * poll briefly (CMPs commonly load asynchronously) and give up after ~2s.
430
444
  */
431
445
  subscribeTcf() {
432
- const t = this.config.consent_source;
433
- if (t?.type !== "tcf" || typeof window > "u") return;
434
- const e = t.purposes, i = (s) => {
446
+ const e = this.config.consent_source;
447
+ if (e?.type !== "tcf" || typeof window > "u") return;
448
+ const t = e.purposes, i = (n) => {
435
449
  try {
436
- const r = window;
437
- if (typeof r.__tcfapi != "function") {
438
- s > 0 && setTimeout(() => i(s - 1), 200);
450
+ const o = window;
451
+ if (typeof o.__tcfapi != "function") {
452
+ n > 0 && setTimeout(() => i(n - 1), 200);
439
453
  return;
440
454
  }
441
- r.__tcfapi("addEventListener", 2, (o, a) => {
442
- if (!a || !o) {
455
+ o.__tcfapi("addEventListener", 2, (a, c) => {
456
+ if (!c || !a) {
443
457
  this.tcfCachedAllowed = !1;
444
458
  return;
445
459
  }
446
- if (o.gdprApplies === !1) {
460
+ if (a.gdprApplies === !1) {
447
461
  this.tcfCachedAllowed = !0;
448
462
  return;
449
463
  }
450
- const l = o.purpose?.consents ?? {};
451
- this.tcfCachedAllowed = e.every((f) => l[String(f)] === !0);
464
+ const f = a.purpose?.consents ?? {};
465
+ this.tcfCachedAllowed = t.every((l) => f[String(l)] === !0);
452
466
  });
453
467
  } catch {
454
468
  this.tcfCachedAllowed = !1;
@@ -457,90 +471,90 @@ class L {
457
471
  i(10);
458
472
  }
459
473
  }
460
- class P {
474
+ class J {
461
475
  config;
462
476
  endpoint;
463
477
  pending = /* @__PURE__ */ new Set();
464
- constructor(t) {
465
- this.config = t, this.endpoint = t.endpoint ?? I;
478
+ constructor(e) {
479
+ this.config = e, this.endpoint = e.endpoint ?? O;
466
480
  }
467
- async send(t, e, i) {
468
- const s = this.sendInternal(t, e, i);
469
- this.pending.add(s);
481
+ async send(e, t, i) {
482
+ const n = this.sendInternal(e, t, i);
483
+ this.pending.add(n);
470
484
  try {
471
- await s;
485
+ await n;
472
486
  } finally {
473
- this.pending.delete(s);
487
+ this.pending.delete(n);
474
488
  }
475
489
  }
476
490
  async flush() {
477
491
  this.pending.size !== 0 && await Promise.allSettled(Array.from(this.pending));
478
492
  }
479
- async sendInternal(t, e, i) {
480
- const s = this.joinUrl(this.endpoint, t), r = this.config.key, o = {
493
+ async sendInternal(e, t, i) {
494
+ const n = this.joinUrl(this.endpoint, e), o = this.config.key, a = {
481
495
  "Content-Type": "application/json",
482
- [r.startsWith("sk_") ? "x-secret-key" : "x-publishable-key"]: r
496
+ [o.startsWith("sk_") ? "x-secret-key" : "x-publishable-key"]: o
483
497
  };
484
- this.config.debug && console.log("[Mark] Sending", s, e);
485
- const a = JSON.stringify(e);
498
+ this.config.debug && console.log("[Mark] Sending", n, t);
499
+ const c = JSON.stringify(t);
486
500
  if (i?.preferBeacon && typeof navigator < "u" && typeof navigator.sendBeacon == "function") {
487
- const u = new Blob([a], { type: "application/json" });
488
- if (navigator.sendBeacon(s, u))
501
+ const u = new Blob([c], { type: "application/json" });
502
+ if (navigator.sendBeacon(n, u))
489
503
  return;
490
504
  }
491
505
  if (typeof fetch != "function")
492
- throw this.config.debug && console.error("[Mark] Global fetch is not available in this runtime."), new h("[Mark] Global fetch is not available in this runtime.");
493
- const l = this.config.request_timeout_ms ?? 1e4, f = new AbortController();
506
+ 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.");
507
+ const f = this.config.request_timeout_ms ?? 1e4, l = new AbortController();
494
508
  let d = !1;
495
- const g = setTimeout(() => {
496
- d = !0, f.abort();
497
- }, l);
509
+ const h = setTimeout(() => {
510
+ d = !0, l.abort();
511
+ }, f);
498
512
  try {
499
- const u = await fetch(s, {
513
+ const u = await fetch(n, {
500
514
  method: "POST",
501
- headers: o,
502
- body: a,
515
+ headers: a,
516
+ body: c,
503
517
  keepalive: !0,
504
- signal: f.signal
518
+ signal: l.signal
505
519
  });
506
520
  if (!u.ok) {
507
- const p = await this.readErrorSnippet(u), w = E(u.headers.get("Retry-After"));
521
+ const g = await this.readErrorSnippet(u), P = V(u.headers.get("Retry-After"));
508
522
  throw this.config.debug && console.error("[Mark] Request rejected", {
509
- url: s,
523
+ url: n,
510
524
  status: u.status,
511
525
  statusText: u.statusText,
512
- body: p,
513
- retryAfterMs: w
514
- }), new h(
515
- `[Mark] Request rejected with status ${u.status}: ${p}`,
516
- { status: u.status, retryAfterMs: w }
526
+ body: g,
527
+ retryAfterMs: P
528
+ }), new p(
529
+ `[Mark] Request rejected with status ${u.status}: ${g}`,
530
+ { status: u.status, retryAfterMs: P }
517
531
  );
518
532
  }
519
533
  } catch (u) {
520
- if (this.config.debug && console.error("[Mark] Failed to send", s, u), u instanceof h)
534
+ if (this.config.debug && console.error("[Mark] Failed to send", n, u), u instanceof p)
521
535
  throw u;
522
536
  if (d)
523
- throw new h(`[Mark] Request timed out after ${l}ms`, { status: 408 });
524
- const p = u instanceof Error ? u.message : String(u);
525
- throw new h(`[Mark] Network error: ${p}`);
537
+ throw new p(`[Mark] Request timed out after ${f}ms`, { status: 408 });
538
+ const g = u instanceof Error ? u.message : String(u);
539
+ throw new p(`[Mark] Network error: ${g}`);
526
540
  } finally {
527
- clearTimeout(g);
541
+ clearTimeout(h);
528
542
  }
529
543
  }
530
- joinUrl(t, e) {
531
- const i = t.replace(/\/+$/, ""), s = e.replace(/^\/+/, "");
532
- return `${i}/${s}`;
544
+ joinUrl(e, t) {
545
+ const i = e.replace(/\/+$/, ""), n = t.replace(/^\/+/, "");
546
+ return `${i}/${n}`;
533
547
  }
534
- async readErrorSnippet(t) {
548
+ async readErrorSnippet(e) {
535
549
  try {
536
- return (await t.text()).slice(0, 300);
550
+ return (await e.text()).slice(0, 300);
537
551
  } catch {
538
552
  return "";
539
553
  }
540
554
  }
541
555
  }
542
- const R = "crelora_mark_data", B = "crelora_mark_outbox", y = "crelora_mark_vid";
543
- class F {
556
+ const X = "crelora_mark_data", Z = "crelora_mark_outbox", T = "crelora_mark_vid";
557
+ class ee {
544
558
  data;
545
559
  storageKey;
546
560
  outboxKey;
@@ -548,8 +562,8 @@ class F {
548
562
  bridgeFrame;
549
563
  bridgeReady = !1;
550
564
  bridgeOrigin;
551
- constructor(t) {
552
- if (this.options = t ?? {}, this.storageKey = this.options.storageKey ?? R, this.outboxKey = this.options.outboxKey ?? B, typeof window > "u") {
565
+ constructor(e) {
566
+ if (this.options = e ?? {}, this.storageKey = this.options.storageKey ?? X, this.outboxKey = this.options.outboxKey ?? Z, typeof window > "u") {
553
567
  this.data = {};
554
568
  return;
555
569
  }
@@ -585,14 +599,14 @@ class F {
585
599
  getInternal() {
586
600
  return this.data.is_internal;
587
601
  }
588
- setInternal(t) {
589
- t ? this.update({ is_internal: !0 }) : this.update({ is_internal: void 0 });
602
+ setInternal(e) {
603
+ e ? this.update({ is_internal: !0 }) : this.update({ is_internal: void 0 });
590
604
  }
591
- update(t) {
592
- this.data = { ...this.data, ...t }, this.save();
605
+ update(e) {
606
+ this.data = { ...this.data, ...e }, this.save();
593
607
  }
594
- setConsentStatus(t) {
595
- this.data.consent_status = t, this.save();
608
+ setConsentStatus(e) {
609
+ this.data.consent_status = e, this.save();
596
610
  }
597
611
  clearAttribution() {
598
612
  this.update({
@@ -602,7 +616,7 @@ class F {
602
616
  });
603
617
  }
604
618
  clearCookieVisitorId() {
605
- this.setCookie(y, "", -1);
619
+ this.setCookie(T, "", -1);
606
620
  }
607
621
  rotateVisitorId() {
608
622
  this.update({ visitor_id: this.generateUUID() });
@@ -610,18 +624,18 @@ class F {
610
624
  getOutbox() {
611
625
  if (typeof window > "u") return [];
612
626
  try {
613
- const t = localStorage.getItem(this.outboxKey);
614
- if (!t) return [];
615
- const e = JSON.parse(t);
616
- return Array.isArray(e) ? e : [];
627
+ const e = localStorage.getItem(this.outboxKey);
628
+ if (!e) return [];
629
+ const t = JSON.parse(e);
630
+ return Array.isArray(t) ? t : [];
617
631
  } catch {
618
632
  return [];
619
633
  }
620
634
  }
621
- setOutbox(t) {
635
+ setOutbox(e) {
622
636
  if (!(typeof window > "u"))
623
637
  try {
624
- localStorage.setItem(this.outboxKey, JSON.stringify(t.slice(-200)));
638
+ localStorage.setItem(this.outboxKey, JSON.stringify(e.slice(-200)));
625
639
  } catch {
626
640
  }
627
641
  }
@@ -629,13 +643,13 @@ class F {
629
643
  if (typeof window > "u")
630
644
  return {};
631
645
  try {
632
- const e = localStorage.getItem(this.storageKey);
633
- if (e)
634
- return JSON.parse(e);
646
+ const t = localStorage.getItem(this.storageKey);
647
+ if (t)
648
+ return JSON.parse(t);
635
649
  } catch {
636
650
  }
637
- const t = this.getCookie(y);
638
- return t ? { visitor_id: t } : {};
651
+ const e = this.getCookie(T);
652
+ return e ? { visitor_id: e } : {};
639
653
  }
640
654
  save() {
641
655
  if (!(typeof window > "u")) {
@@ -643,27 +657,27 @@ class F {
643
657
  localStorage.setItem(this.storageKey, JSON.stringify(this.data));
644
658
  } catch {
645
659
  }
646
- this.data.visitor_id && this.isCookieEnabled() && (this.setCookie(y, this.data.visitor_id, 365), this.options.bridge?.url && this.bridgeReady && this.postBridgeMessage({
660
+ this.data.visitor_id && this.isCookieEnabled() && (this.setCookie(T, this.data.visitor_id, 365), this.options.bridge?.url && this.bridgeReady && this.postBridgeMessage({
647
661
  type: "MARK_SYNC_UPDATE",
648
662
  visitorId: this.data.visitor_id
649
663
  }));
650
664
  }
651
665
  }
652
- getCookie(t) {
666
+ getCookie(e) {
653
667
  if (typeof document > "u")
654
668
  return null;
655
669
  try {
656
- const e = document.cookie.match(new RegExp(`(^| )${t}=([^;]+)`));
657
- if (e) return e[2];
670
+ const t = document.cookie.match(new RegExp(`(^| )${e}=([^;]+)`));
671
+ if (t) return t[2];
658
672
  } catch {
659
673
  }
660
674
  return null;
661
675
  }
662
- setCookie(t, e, i) {
676
+ setCookie(e, t, i) {
663
677
  if (!(typeof document > "u"))
664
678
  try {
665
- const s = new Date(Date.now() + i * 24 * 60 * 60 * 1e3), r = this.options.cookie_domain ? `;domain=${this.options.cookie_domain}` : "";
666
- document.cookie = `${t}=${e};expires=${s.toUTCString()};path=/;SameSite=Lax${r}`;
679
+ const n = new Date(Date.now() + i * 24 * 60 * 60 * 1e3), o = this.options.cookie_domain ? `;domain=${this.options.cookie_domain}` : "";
680
+ document.cookie = `${e}=${t};expires=${n.toUTCString()};path=/;SameSite=Lax${o}`;
667
681
  } catch {
668
682
  }
669
683
  }
@@ -671,75 +685,75 @@ class F {
671
685
  if (typeof crypto < "u" && crypto.randomUUID)
672
686
  return crypto.randomUUID();
673
687
  if (typeof crypto < "u" && typeof crypto.getRandomValues == "function") {
674
- const t = crypto.getRandomValues(new Uint8Array(16));
675
- t[6] = t[6] & 15 | 64, t[8] = t[8] & 63 | 128;
676
- const e = Array.from(t, (i) => i.toString(16).padStart(2, "0")).join("");
677
- return `${e.slice(0, 8)}-${e.slice(8, 12)}-${e.slice(12, 16)}-${e.slice(16, 20)}-${e.slice(20)}`;
688
+ const e = crypto.getRandomValues(new Uint8Array(16));
689
+ e[6] = e[6] & 15 | 64, e[8] = e[8] & 63 | 128;
690
+ const t = Array.from(e, (i) => i.toString(16).padStart(2, "0")).join("");
691
+ return `${t.slice(0, 8)}-${t.slice(8, 12)}-${t.slice(12, 16)}-${t.slice(16, 20)}-${t.slice(20)}`;
678
692
  }
679
- return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (t) => {
680
- const e = (Date.now() + Math.random() * 16) % 16 | 0;
681
- return (t === "x" ? e : e & 3 | 8).toString(16);
693
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (e) => {
694
+ const t = (Date.now() + Math.random() * 16) % 16 | 0;
695
+ return (e === "x" ? t : t & 3 | 8).toString(16);
682
696
  });
683
697
  }
684
698
  isCookieEnabled() {
685
699
  return this.options.mode ? this.options.mode === "single" || this.options.mode === "subdomain" : !0;
686
700
  }
687
- setupBridge(t) {
701
+ setupBridge(e) {
688
702
  if (typeof document > "u") return;
689
- let e;
703
+ let t;
690
704
  try {
691
- e = new URL(t.url, window.location.href);
705
+ t = new URL(e.url, window.location.href);
692
706
  } catch {
693
707
  return;
694
708
  }
695
- 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();
696
- const i = t.timeout_ms ?? 3e3, s = setTimeout(() => {
709
+ 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();
710
+ const i = e.timeout_ms ?? 3e3, n = setTimeout(() => {
697
711
  window.removeEventListener("message", this.handleBridgeMessage);
698
712
  }, i);
699
713
  window.addEventListener("message", this.handleBridgeMessage);
700
- const r = () => {
714
+ const o = () => {
701
715
  this.bridgeFrame && document.body && document.body.appendChild(this.bridgeFrame);
702
716
  };
703
- document.body ? r() : document.addEventListener("DOMContentLoaded", r, { once: !0 }), this.bridgeFrame.addEventListener("load", () => {
704
- clearTimeout(s), this.bridgeReady = !0, this.postBridgeMessage({
717
+ document.body ? o() : document.addEventListener("DOMContentLoaded", o, { once: !0 }), this.bridgeFrame.addEventListener("load", () => {
718
+ clearTimeout(n), this.bridgeReady = !0, this.postBridgeMessage({
705
719
  type: "MARK_SYNC_REQUEST",
706
720
  visitorId: this.data.visitor_id
707
721
  });
708
722
  });
709
723
  }
710
- handleBridgeMessage = (t) => {
711
- if (!this.bridgeFrame?.contentWindow || t.source !== this.bridgeFrame.contentWindow || !this.isDomainAllowed(t.origin))
724
+ handleBridgeMessage = (e) => {
725
+ if (!this.bridgeFrame?.contentWindow || e.source !== this.bridgeFrame.contentWindow || !this.isDomainAllowed(e.origin))
712
726
  return;
713
- const e = t.data;
714
- !e || !e.type || e.type === "MARK_SYNC_RESPONSE" && e.visitorId && e.visitorId !== this.data.visitor_id && (this.data.visitor_id = e.visitorId, this.save());
727
+ const t = e.data;
728
+ !t || !t.type || t.type === "MARK_SYNC_RESPONSE" && t.visitorId && t.visitorId !== this.data.visitor_id && (this.data.visitor_id = t.visitorId, this.save());
715
729
  };
716
- postBridgeMessage(t) {
717
- this.bridgeFrame?.contentWindow && this.bridgeFrame.contentWindow.postMessage(t, this.bridgeOrigin ?? "*");
730
+ postBridgeMessage(e) {
731
+ this.bridgeFrame?.contentWindow && this.bridgeFrame.contentWindow.postMessage(e, this.bridgeOrigin ?? "*");
718
732
  }
719
- isDomainAllowed(t) {
733
+ isDomainAllowed(e) {
720
734
  try {
721
- const e = new URL(t);
735
+ const t = new URL(e);
722
736
  if (this.options.allowed_domains?.length)
723
737
  return this.options.allowed_domains.some(
724
- (s) => e.hostname === s || e.hostname.endsWith(`.${s}`)
738
+ (n) => t.hostname === n || t.hostname.endsWith(`.${n}`)
725
739
  );
726
740
  if (!this.bridgeOrigin)
727
741
  return !1;
728
742
  const i = new URL(this.bridgeOrigin);
729
- return e.hostname === i.hostname;
743
+ return t.hostname === i.hostname;
730
744
  } catch {
731
745
  return !1;
732
746
  }
733
747
  }
734
- handleStorageEvent = (t) => {
735
- if (!(t.key !== this.storageKey || typeof t.newValue != "string"))
748
+ handleStorageEvent = (e) => {
749
+ if (!(e.key !== this.storageKey || typeof e.newValue != "string"))
736
750
  try {
737
- this.data = JSON.parse(t.newValue);
751
+ this.data = JSON.parse(e.newValue);
738
752
  } catch {
739
753
  }
740
754
  };
741
755
  }
742
- const H = [
756
+ const te = [
743
757
  "click_id",
744
758
  "ch_click_id",
745
759
  "gclid",
@@ -751,7 +765,7 @@ const H = [
751
765
  "ttclid",
752
766
  "twclid",
753
767
  "li_fat_id"
754
- ], O = ["cid", "campaign_id"], N = [
768
+ ], ie = ["cid", "campaign_id"], ne = [
755
769
  "utm_source",
756
770
  "utm_medium",
757
771
  "utm_campaign",
@@ -773,138 +787,292 @@ const H = [
773
787
  "ttclid",
774
788
  "twclid",
775
789
  "li_fat_id"
776
- ], K = {
790
+ ], se = {
777
791
  referral: "ref",
778
792
  affiliate_id: "ref",
779
793
  ch_click_id: "click_id",
780
794
  cid: "campaign_id"
781
- }, V = ["email", "phone", "token", "auth", "password", "code"], z = 30, $ = 256;
782
- function b(c, t = {}) {
783
- const e = new URLSearchParams(c), i = Y(e), s = v(i, H), r = v(i, O), o = j(e, t), a = {};
784
- return s && (a.last_click_id = s), r && (a.campaign_id = r), Object.keys(o).length > 0 && (a.query_params = o), a;
795
+ }, re = ["email", "phone", "token", "auth", "password", "code"], oe = 30, ae = 256;
796
+ function L(r, e = {}) {
797
+ const t = new URLSearchParams(r), i = de(t), n = U(i, te), o = U(i, ie), a = ce(t, e), c = {};
798
+ return n && (c.last_click_id = n), o && (c.campaign_id = o), Object.keys(a).length > 0 && (c.query_params = a), c;
785
799
  }
786
- function j(c, t) {
787
- const e = {}, i = new Set(_(t.query_param_denylist, V)), s = A(
788
- t.max_captured_query_params,
789
- z
790
- ), r = A(
791
- t.max_query_param_value_length,
792
- $
793
- ), a = t.capture_all_query_params ?? !1 ? null : /* @__PURE__ */ new Set([
794
- ...N.map(m),
795
- ..._(t.capture_query_params, [])
800
+ function ce(r, e) {
801
+ const t = {}, i = new Set(R(e.query_param_denylist, re)), n = B(
802
+ e.max_captured_query_params,
803
+ oe
804
+ ), o = B(
805
+ e.max_query_param_value_length,
806
+ ae
807
+ ), c = e.capture_all_query_params ?? !1 ? null : /* @__PURE__ */ new Set([
808
+ ...ne.map(I),
809
+ ...R(e.capture_query_params, [])
796
810
  ]);
797
- for (const [l, f] of c.entries()) {
798
- const d = m(l);
811
+ for (const [f, l] of r.entries()) {
812
+ const d = I(f);
799
813
  if (!d)
800
814
  continue;
801
- const g = K[d] ?? d;
802
- if (i.has(d) || i.has(g) || a && !a.has(d))
815
+ const h = se[d] ?? d;
816
+ if (i.has(d) || i.has(h) || c && !c.has(d))
803
817
  continue;
804
- const u = f.trim();
818
+ const u = l.trim();
805
819
  if (u) {
806
- if (!(g in e) && Object.keys(e).length >= s)
820
+ if (!(h in t) && Object.keys(t).length >= n)
807
821
  break;
808
- e[g] = u.slice(0, r);
822
+ t[h] = u.slice(0, o);
809
823
  }
810
824
  }
811
- return e;
825
+ return t;
812
826
  }
813
- function v(c, t) {
814
- for (const e of t) {
815
- const i = m(e), s = c[i]?.trim();
816
- if (s)
817
- return s;
827
+ function U(r, e) {
828
+ for (const t of e) {
829
+ const i = I(t), n = r[i]?.trim();
830
+ if (n)
831
+ return n;
818
832
  }
819
833
  }
820
- function Y(c) {
821
- const t = {};
822
- for (const [e, i] of c.entries()) {
823
- const s = m(e);
824
- !s || s in t || (t[s] = i);
834
+ function de(r) {
835
+ const e = {};
836
+ for (const [t, i] of r.entries()) {
837
+ const n = I(t);
838
+ !n || n in e || (e[n] = i);
825
839
  }
826
- return t;
840
+ return e;
827
841
  }
828
- function m(c) {
829
- return c.trim().toLowerCase();
842
+ function I(r) {
843
+ return r.trim().toLowerCase();
830
844
  }
831
- function _(c, t) {
832
- const e = c ?? t, i = /* @__PURE__ */ new Set();
833
- for (const s of e) {
834
- if (typeof s != "string") continue;
835
- const r = m(s);
836
- r && i.add(r);
845
+ function R(r, e) {
846
+ const t = r ?? e, i = /* @__PURE__ */ new Set();
847
+ for (const n of t) {
848
+ if (typeof n != "string") continue;
849
+ const o = I(n);
850
+ o && i.add(o);
837
851
  }
838
852
  return Array.from(i);
839
853
  }
840
- function A(c, t) {
841
- if (typeof c != "number" || !Number.isFinite(c))
842
- return t;
843
- const e = Math.floor(c);
844
- return e < 0 ? t : e;
854
+ function B(r, e) {
855
+ if (typeof r != "number" || !Number.isFinite(r))
856
+ return e;
857
+ const t = Math.floor(r);
858
+ return t < 0 ? e : t;
859
+ }
860
+ function E(r) {
861
+ return r.length > 1 && r.endsWith("/") ? r.slice(0, -1) : r;
862
+ }
863
+ function ue(r) {
864
+ if (!r || r === "?")
865
+ return "";
866
+ const e = r.startsWith("?") ? r.slice(1) : r;
867
+ if (!e)
868
+ return "";
869
+ const t = new URLSearchParams(e), i = [];
870
+ t.forEach((a, c) => {
871
+ i.push([c, a]);
872
+ }), i.sort(([a, c], [f, l]) => {
873
+ const d = a.localeCompare(f);
874
+ return d !== 0 ? d : c.localeCompare(l);
875
+ });
876
+ const n = new URLSearchParams();
877
+ for (const [a, c] of i)
878
+ n.append(a, c);
879
+ const o = n.toString();
880
+ return o === "" ? "" : `?${o}`;
881
+ }
882
+ function C(r) {
883
+ const e = E(r.pathname), t = ue(r.search);
884
+ return `${r.origin}${e}${t}${r.hash}`;
885
+ }
886
+ let x = !1, m = null;
887
+ const w = [], y = [], _ = [];
888
+ let b = null, v = null, A = null, S = null;
889
+ function k() {
890
+ if (typeof window > "u") return;
891
+ const r = C(window.location);
892
+ if (r === m) return;
893
+ const e = { previousKey: m, nextKey: r };
894
+ for (const t of w)
895
+ t(e);
896
+ m = r;
897
+ for (const t of y)
898
+ t(e);
899
+ }
900
+ function le() {
901
+ for (const r of _)
902
+ r();
903
+ }
904
+ function fe(r = {}) {
905
+ if (x || typeof window > "u" || typeof document > "u")
906
+ return;
907
+ x = !0;
908
+ const e = r.trackRouteChanges ?? !0;
909
+ m = C(window.location), S = le, window.addEventListener("pagehide", S), e && (b = history.pushState, v = history.replaceState, history.pushState = function(...t) {
910
+ const i = b.apply(this, t);
911
+ return k(), i;
912
+ }, history.replaceState = function(...t) {
913
+ const i = v.apply(this, t);
914
+ return k(), i;
915
+ }, A = k, window.addEventListener("popstate", A));
916
+ }
917
+ function he(r) {
918
+ return w.push(r), () => {
919
+ const e = w.indexOf(r);
920
+ e >= 0 && w.splice(e, 1);
921
+ };
922
+ }
923
+ function q(r) {
924
+ return y.push(r), () => {
925
+ const e = y.indexOf(r);
926
+ e >= 0 && y.splice(e, 1);
927
+ };
928
+ }
929
+ function ge(r) {
930
+ return _.push(r), () => {
931
+ const e = _.indexOf(r);
932
+ e >= 0 && _.splice(e, 1);
933
+ };
934
+ }
935
+ function pe() {
936
+ !x || typeof window > "u" || (b && (history.pushState = b), v && (history.replaceState = v), A && window.removeEventListener("popstate", A), S && window.removeEventListener("pagehide", S), b = null, v = null, A = null, S = null, w.length = 0, y.length = 0, _.length = 0, m = null, x = !1);
937
+ }
938
+ let D = 0;
939
+ function N() {
940
+ D = 0;
941
+ }
942
+ function me() {
943
+ return D;
845
944
  }
846
- class n {
945
+ function we() {
946
+ if (typeof document > "u" || typeof window > "u")
947
+ return 0;
948
+ const r = document.documentElement, e = window.scrollY || r.scrollTop, t = Math.max(1, r.scrollHeight - window.innerHeight);
949
+ return Math.min(100, Math.round(e / t * 100));
950
+ }
951
+ function K() {
952
+ const r = we();
953
+ return r > D && (D = r), r;
954
+ }
955
+ const ye = [25, 50, 75, 100];
956
+ function _e(r, e = ye) {
957
+ if (typeof window > "u") return;
958
+ const t = /* @__PURE__ */ new Set(), i = () => {
959
+ t.clear(), N();
960
+ };
961
+ i(), q(() => {
962
+ i();
963
+ }), window.addEventListener(
964
+ "scroll",
965
+ () => {
966
+ const n = K();
967
+ for (const o of e)
968
+ n >= o && !t.has(o) && (t.add(o), r.track("scroll_depth", { percent: o }));
969
+ },
970
+ { passive: !0 }
971
+ );
972
+ }
973
+ const F = 1e4;
974
+ function be(r) {
975
+ return r === !0 ? { minActiveMs: F, useBeacon: !0 } : {
976
+ minActiveMs: r.min_active_ms ?? F,
977
+ useBeacon: r.use_beacon !== !1
978
+ };
979
+ }
980
+ function ve(r, e) {
981
+ if (typeof window > "u" || typeof document > "u") return;
982
+ let t = Date.now(), i = 0, n = document.visibilityState === "visible" ? Date.now() : null, o = E(window.location.pathname), a = !1;
983
+ const c = () => {
984
+ n !== null && (i += Date.now() - n, n = null);
985
+ }, f = () => {
986
+ document.visibilityState === "visible" && n === null && (n = Date.now());
987
+ }, l = (h) => {
988
+ if (!a) {
989
+ a = !0;
990
+ try {
991
+ if (c(), K(), i < e.minActiveMs)
992
+ return;
993
+ const u = Date.now() - t, g = {
994
+ page: o,
995
+ active_time_ms: i,
996
+ total_time_ms: u,
997
+ max_scroll_percent: me()
998
+ };
999
+ e.useBeacon && h ? r.trackWithOptions("page_engagement", g, { preferBeacon: !0 }) : r.track("page_engagement", g);
1000
+ } finally {
1001
+ a = !1;
1002
+ }
1003
+ }
1004
+ }, d = () => {
1005
+ t = Date.now(), i = 0, o = E(window.location.pathname), N(), f();
1006
+ };
1007
+ d(), he(() => {
1008
+ l(!0), c();
1009
+ }), q(() => {
1010
+ d();
1011
+ }), ge(() => {
1012
+ l(!0);
1013
+ }), document.addEventListener("visibilitychange", () => {
1014
+ document.visibilityState === "hidden" ? c() : f();
1015
+ });
1016
+ }
1017
+ class s {
847
1018
  static client = null;
848
1019
  static storage = null;
849
1020
  static config = null;
850
1021
  static pageviewTrackerInstalled = !1;
851
- static lastPageviewHref = null;
1022
+ static lastPageviewDedupeKey = null;
852
1023
  static emitAutoPageview = null;
853
1024
  static pendingAttribution = {};
854
- static originalPushState = null;
855
- static originalReplaceState = null;
856
- static popstateHandler = null;
857
1025
  static beaconDrainHandler = null;
858
1026
  static visibilityHandler = null;
859
1027
  static onlineHandler = null;
860
1028
  static kickTimer = null;
861
- static init(t) {
862
- if (!n.client) {
863
- const e = new F(t.cross_domain), i = new P(t);
864
- n.client = new L(t, { storage: e, transport: i }), n.storage = e, n.config = t, n.refreshAttribution(e, t), typeof window < "u" && t.autocapture?.pageview && n.installPageviewTracking(t, e), typeof window < "u" && (n.installExtendedAutocapture(t), n.installLifecycleFlushing());
1029
+ static init(e) {
1030
+ if (!s.client) {
1031
+ const t = new ee(e.cross_domain), i = new J(e);
1032
+ s.client = new G(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());
865
1033
  }
866
- return n.client;
1034
+ return s.client;
867
1035
  }
868
1036
  static installLifecycleFlushing() {
869
- if (typeof window > "u" || n.beaconDrainHandler) return;
870
- const t = () => {
871
- n.client?.drainViaBeacon();
872
- }, e = () => {
873
- typeof document < "u" && document.visibilityState === "hidden" && t();
1037
+ if (typeof window > "u" || s.beaconDrainHandler) return;
1038
+ const e = () => {
1039
+ s.client?.drainViaBeacon();
1040
+ }, t = () => {
1041
+ typeof document < "u" && document.visibilityState === "hidden" && e();
874
1042
  }, i = () => {
875
- n.client?.kickQueue();
1043
+ s.client?.kickQueue();
876
1044
  };
877
- n.beaconDrainHandler = t, n.visibilityHandler = e, n.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" && (n.kickTimer = setInterval(() => {
878
- n.client?.kickQueue();
1045
+ 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(() => {
1046
+ s.client?.kickQueue();
879
1047
  }, 3e4));
880
1048
  }
881
- static track(t, e = {}) {
882
- if (!n.client) {
883
- n.config?.debug && console.warn("[Mark] Not initialized. Call init() first.");
1049
+ static track(e, t = {}) {
1050
+ if (!s.client) {
1051
+ s.config?.debug && console.warn("[Mark] Not initialized. Call init() first.");
884
1052
  return;
885
1053
  }
886
- n.client.track(t, e);
1054
+ s.client.track(e, t);
887
1055
  }
888
- static identify(t, e = {}) {
889
- if (!n.client) {
890
- n.config?.debug && console.warn("[Mark] Not initialized. Call init() first.");
1056
+ static identify(e, t = {}) {
1057
+ if (!s.client) {
1058
+ s.config?.debug && console.warn("[Mark] Not initialized. Call init() first.");
891
1059
  return;
892
1060
  }
893
- n.client.identify(t, e);
1061
+ s.client.identify(e, t);
894
1062
  }
895
- static conversion(t, e = {}) {
896
- if (!n.client) {
897
- n.config?.debug && console.warn("[Mark] Not initialized. Call init() first.");
1063
+ static conversion(e, t = {}) {
1064
+ if (!s.client) {
1065
+ s.config?.debug && console.warn("[Mark] Not initialized. Call init() first.");
898
1066
  return;
899
1067
  }
900
- n.client.conversion(t, e);
1068
+ s.client.conversion(e, t);
901
1069
  }
902
- static setConsent(t) {
903
- if (!n.client) {
904
- n.config?.debug && console.warn("[Mark] Not initialized. Call init() first.");
1070
+ static setConsent(e) {
1071
+ if (!s.client) {
1072
+ s.config?.debug && console.warn("[Mark] Not initialized. Call init() first.");
905
1073
  return;
906
1074
  }
907
- n.client.setConsent(t), t === "granted" && (n.flushPendingAttribution(), n.emitAutoPageview?.());
1075
+ s.client.setConsent(e), e === "granted" && (s.flushPendingAttribution(), s.emitAutoPageview?.());
908
1076
  }
909
1077
  /**
910
1078
  * Returns the current visitor ID when available.
@@ -913,11 +1081,11 @@ class n {
913
1081
  * when you do not have an authenticated user ID.
914
1082
  */
915
1083
  static getVisitorId() {
916
- if (!(!n.client || !n.storage || !n.config || (n.config.require_consent ?? !1) && n.storage.getConsentStatus() !== "granted"))
917
- return n.client.getVisitorId();
1084
+ if (!(!s.client || !s.storage || !s.config || (s.config.require_consent ?? !1) && s.storage.getConsentStatus() !== "granted"))
1085
+ return s.client.getVisitorId();
918
1086
  }
919
1087
  static flush() {
920
- return n.client ? n.client.flush() : Promise.resolve();
1088
+ return s.client ? s.client.flush() : Promise.resolve();
921
1089
  }
922
1090
  /**
923
1091
  * Flags (or un-flags) the current visitor as internal traffic. Persists
@@ -933,145 +1101,131 @@ class n {
933
1101
  * if (params.get('onelence_internal') === '1') Mark.setInternal(true);
934
1102
  * if (params.get('onelence_internal') === '0') Mark.setInternal(false);
935
1103
  */
936
- static setInternal(t) {
937
- if (!n.client) {
938
- n.config?.debug && console.warn("[Mark] Not initialized. Call init() first.");
1104
+ static setInternal(e) {
1105
+ if (!s.client) {
1106
+ s.config?.debug && console.warn("[Mark] Not initialized. Call init() first.");
939
1107
  return;
940
1108
  }
941
- n.client.setInternal(t);
1109
+ s.client.setInternal(e);
942
1110
  }
943
1111
  static getInternal() {
944
- return n.client?.getInternal() ?? !1;
1112
+ return s.client?.getInternal() ?? !1;
945
1113
  }
946
1114
  static reset() {
947
- n.client?.reset(), n.pendingAttribution = {}, n.lastPageviewHref = null;
1115
+ s.client?.reset(), s.pendingAttribution = {}, s.lastPageviewDedupeKey = null;
948
1116
  }
949
1117
  static getStats() {
950
- return n.client?.getStats() ?? { queued: 0, sent: 0, failed: 0, dropped: 0 };
1118
+ return s.client?.getStats() ?? { queued: 0, sent: 0, failed: 0, dropped: 0 };
951
1119
  }
952
1120
  static destroy() {
953
- typeof window > "u" || (n.originalPushState && (history.pushState = n.originalPushState), n.originalReplaceState && (history.replaceState = n.originalReplaceState), n.popstateHandler && window.removeEventListener("popstate", n.popstateHandler), n.beaconDrainHandler && (window.removeEventListener("pagehide", n.beaconDrainHandler), window.removeEventListener("beforeunload", n.beaconDrainHandler)), n.visibilityHandler && typeof document < "u" && document.removeEventListener("visibilitychange", n.visibilityHandler), n.onlineHandler && window.removeEventListener("online", n.onlineHandler), n.kickTimer && clearInterval(n.kickTimer), n.originalPushState = null, n.originalReplaceState = null, n.popstateHandler = null, n.beaconDrainHandler = null, n.visibilityHandler = null, n.onlineHandler = null, n.kickTimer = null, n.pageviewTrackerInstalled = !1);
1121
+ typeof window > "u" || (pe(), 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);
1122
+ }
1123
+ static installPageLifecycleIfNeeded(e) {
1124
+ const t = e.autocapture;
1125
+ if (!(!!t?.pageview || !!t?.scroll_depth || !!t?.page_engagement)) return;
1126
+ const n = e.track_route_changes ?? !0;
1127
+ fe({ trackRouteChanges: n });
954
1128
  }
955
- static installPageviewTracking(t, e) {
956
- if (n.pageviewTrackerInstalled) return;
957
- n.pageviewTrackerInstalled = !0;
1129
+ static installPageviewTracking(e, t) {
1130
+ if (s.pageviewTrackerInstalled) return;
1131
+ s.pageviewTrackerInstalled = !0;
958
1132
  const i = () => {
959
- if (!n.client) return;
960
- n.refreshAttribution(e, t);
961
- const a = window.location.href;
962
- if (a === n.lastPageviewHref) return;
963
- n.client.track("page_view", {
1133
+ if (!s.client) return;
1134
+ s.refreshAttribution(t, e);
1135
+ const o = C(window.location);
1136
+ if (o === s.lastPageviewDedupeKey) return;
1137
+ s.client.track("page_view", {
964
1138
  site: window.location.host,
965
- page: window.location.pathname,
1139
+ page: E(window.location.pathname),
966
1140
  title: document.title,
967
1141
  referrer: document.referrer || void 0
968
- }) && (n.lastPageviewHref = a);
1142
+ }) && (s.lastPageviewDedupeKey = o);
969
1143
  };
970
- if (n.emitAutoPageview = i, i(), !(t.track_route_changes ?? !0)) return;
971
- const r = history.pushState, o = history.replaceState;
972
- n.originalPushState = r, n.originalReplaceState = o, history.pushState = function(...a) {
973
- const l = r.apply(this, a);
974
- return i(), l;
975
- }, history.replaceState = function(...a) {
976
- const l = o.apply(this, a);
977
- return i(), l;
978
- }, n.popstateHandler = i, window.addEventListener("popstate", i);
979
- }
980
- static refreshAttribution(t, e) {
1144
+ s.emitAutoPageview = i, i(), (e.track_route_changes ?? !0) && q(() => {
1145
+ i();
1146
+ });
1147
+ }
1148
+ static refreshAttribution(e, t) {
981
1149
  if (typeof window > "u")
982
1150
  return;
983
- const i = b(window.location.search, e);
1151
+ const i = L(window.location.search, t);
984
1152
  if (Object.keys(i).length !== 0) {
985
- if (n.shouldPersistAttribution(t, e)) {
986
- const s = n.mergeAttributionUpdates(n.pendingAttribution, i);
987
- t.update(s), n.pendingAttribution = {};
1153
+ if (s.shouldPersistAttribution(e, t)) {
1154
+ const n = s.mergeAttributionUpdates(s.pendingAttribution, i);
1155
+ e.update(n), s.pendingAttribution = {};
988
1156
  return;
989
1157
  }
990
- n.pendingAttribution = n.mergeAttributionUpdates(n.pendingAttribution, i);
1158
+ s.pendingAttribution = s.mergeAttributionUpdates(s.pendingAttribution, i);
991
1159
  }
992
1160
  }
993
1161
  static flushPendingAttribution() {
994
- const t = n.storage, e = n.config;
995
- if (!t || !e || typeof window > "u")
1162
+ const e = s.storage, t = s.config;
1163
+ if (!e || !t || typeof window > "u")
996
1164
  return;
997
- const i = b(window.location.search, e), s = n.mergeAttributionUpdates(n.pendingAttribution, i);
998
- Object.keys(s).length > 0 && t.update(s), n.pendingAttribution = {};
1165
+ const i = L(window.location.search, t), n = s.mergeAttributionUpdates(s.pendingAttribution, i);
1166
+ Object.keys(n).length > 0 && e.update(n), s.pendingAttribution = {};
999
1167
  }
1000
- static shouldPersistAttribution(t, e) {
1001
- return e.require_consent ?? !1 ? t.getConsentStatus() === "granted" : !0;
1168
+ static shouldPersistAttribution(e, t) {
1169
+ return t.require_consent ?? !1 ? e.getConsentStatus() === "granted" : !0;
1002
1170
  }
1003
- static mergeAttributionUpdates(t, e) {
1171
+ static mergeAttributionUpdates(e, t) {
1004
1172
  return {
1005
- ...t,
1006
1173
  ...e,
1174
+ ...t,
1007
1175
  query_params: {
1008
- ...t.query_params ?? {},
1009
- ...e.query_params ?? {}
1176
+ ...e.query_params ?? {},
1177
+ ...t.query_params ?? {}
1010
1178
  }
1011
1179
  };
1012
1180
  }
1013
- static installExtendedAutocapture(t) {
1014
- if (!n.client || typeof document > "u") return;
1015
- const e = t.autocapture;
1016
- if (e) {
1017
- if (e.click && document.addEventListener("click", (i) => {
1018
- const s = i.target;
1019
- if (!s) return;
1020
- const r = typeof e.click == "object" ? e.click.selector : void 0, o = r ? s.closest(r) : s.closest("[data-mark-event]");
1021
- if (!o) return;
1022
- const a = o.getAttribute("data-mark-event") || "click";
1023
- n.client?.track(a, {
1024
- element_id: o.id || void 0,
1025
- element_classes: o.className || void 0,
1026
- text: o.textContent?.trim().slice(0, 120) || void 0,
1027
- href: o.href || void 0
1028
- });
1029
- }), e.form_submit && document.addEventListener("submit", (i) => {
1030
- const s = i.target;
1031
- s && n.client?.track("form_submit", {
1032
- form_id: s.id || void 0,
1033
- form_name: s.name || void 0,
1034
- action: s.action || void 0
1035
- });
1036
- }), e.outbound_link && document.addEventListener("click", (i) => {
1037
- const s = i.target?.closest("a[href]");
1038
- if (!(!s || !s.href))
1039
- try {
1040
- const r = new URL(s.href, window.location.href), o = new URL(window.location.href);
1041
- r.origin !== o.origin && n.client?.trackWithOptions("outbound_link_click", { href: r.toString() }, { preferBeacon: !0 });
1042
- } catch {
1043
- }
1044
- }), e.scroll_depth) {
1045
- const i = [25, 50, 75, 100], s = /* @__PURE__ */ new Set();
1046
- window.addEventListener(
1047
- "scroll",
1048
- () => {
1049
- const r = document.documentElement, o = window.scrollY || r.scrollTop, a = Math.max(1, r.scrollHeight - window.innerHeight), l = Math.min(100, Math.round(o / a * 100));
1050
- for (const f of i)
1051
- l >= f && !s.has(f) && (s.add(f), n.client?.track("scroll_depth", { percent: f }));
1052
- },
1053
- { passive: !0 }
1054
- );
1055
- }
1056
- e.web_vitals && import("./web-vitals-CrnTllyu.js").then((i) => {
1057
- const s = (r) => {
1058
- n.client?.track("web_vital", {
1059
- metric: r.name,
1060
- value: r.value,
1061
- rating: r.rating,
1062
- metric_id: r.id
1063
- });
1064
- };
1065
- i.onLCP(s), i.onCLS(s), i.onINP(s), i.onTTFB(s);
1066
- }).catch(() => {
1067
- t.debug && console.warn("[Mark] web-vitals package not available; skipping autocapture.web_vitals.");
1181
+ static installExtendedAutocapture(e) {
1182
+ if (!s.client || typeof document > "u") return;
1183
+ const t = e.autocapture;
1184
+ t && (t.click && document.addEventListener("click", (i) => {
1185
+ const n = i.target;
1186
+ if (!n) return;
1187
+ const o = typeof t.click == "object" ? t.click.selector : void 0, a = o ? n.closest(o) : n.closest("[data-mark-event]");
1188
+ if (!a) return;
1189
+ const c = a.getAttribute("data-mark-event") || "click";
1190
+ s.client?.track(c, {
1191
+ element_id: a.id || void 0,
1192
+ element_classes: a.className || void 0,
1193
+ text: a.textContent?.trim().slice(0, 120) || void 0,
1194
+ href: a.href || void 0
1068
1195
  });
1069
- }
1196
+ }), t.form_submit && document.addEventListener("submit", (i) => {
1197
+ const n = i.target;
1198
+ n && s.client?.track("form_submit", {
1199
+ form_id: n.id || void 0,
1200
+ form_name: n.name || void 0,
1201
+ action: n.action || void 0
1202
+ });
1203
+ }), t.outbound_link && document.addEventListener("click", (i) => {
1204
+ const n = i.target?.closest("a[href]");
1205
+ if (!(!n || !n.href))
1206
+ try {
1207
+ const o = new URL(n.href, window.location.href), a = new URL(window.location.href);
1208
+ o.origin !== a.origin && s.client?.trackWithOptions("outbound_link_click", { href: o.toString() }, { preferBeacon: !0 });
1209
+ } catch {
1210
+ }
1211
+ }), t.scroll_depth && s.client && _e(s.client), t.page_engagement && s.client && ve(s.client, be(t.page_engagement)), t.web_vitals && import("./web-vitals-CrnTllyu.js").then((i) => {
1212
+ const n = (o) => {
1213
+ s.client?.track("web_vital", {
1214
+ metric: o.name,
1215
+ value: o.value,
1216
+ rating: o.rating,
1217
+ metric_id: o.id
1218
+ });
1219
+ };
1220
+ i.onLCP(n), i.onCLS(n), i.onINP(n), i.onTTFB(n);
1221
+ }).catch(() => {
1222
+ e.debug && console.warn("[Mark] web-vitals package not available; skipping autocapture.web_vitals.");
1223
+ }));
1070
1224
  }
1071
1225
  }
1072
- typeof window < "u" && (window.Mark = n);
1226
+ typeof window < "u" && (window.Mark = s);
1073
1227
  export {
1074
- n as Mark,
1075
- n as default
1228
+ s as Mark,
1229
+ s as default
1076
1230
  };
1077
1231
  //# sourceMappingURL=browser.es.js.map