@crelora/mark 0.2.1 → 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 E(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 x(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
21
  const n = i - Date.now();
22
22
  return n > 0 ? n : 0;
23
23
  }
24
24
  }
25
- const q = 5, T = 300, D = 15e3, C = 2880 * 60 * 1e3;
26
- class U {
27
- constructor(t, e = {}) {
28
- this.transport = t, this.maxAttempts = e.maxAttempts ?? q, this.baseBackoffMs = e.baseBackoffMs ?? T, this.maxBackoffMs = e.maxBackoffMs ?? D, this.maxItemAgeMs = e.maxItemAgeMs ?? C, 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
31
  const n = Date.now();
32
- for (const r of i) {
33
- const o = r.enqueuedAt ?? n;
34
- if (n - o > this.maxItemAgeMs) {
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 U {
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 U {
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 U {
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 h ? i.status : void 0;
121
- if (E(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 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 U {
147
147
  }
148
148
  }
149
149
  }
150
- const k = /* @__PURE__ */ new Set(["event_name", "user_id", "consent_state", "source", "is_conversion"]), P = /* @__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,13 +156,13 @@ const k = /* @__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 U(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),
@@ -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, n) {
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 u = r.site_id ?? this.siteId, l = r.site_host ?? this.siteHost;
217
- u && (a.site_id = u), l && (a.site_host = l), this.config.include_page_context && typeof window < "u" && (this.applyPageContext(a), !l && 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 && !n?.preferBeacon ? (this.enqueueBatch(d), !0) : (this.queue.enqueue("/event", { ...d, __prefer_beacon: n?.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
238
  const n = this.config.before_send ? this.config.before_send(i) : i;
239
- n && this.queue.enqueue("/identify", n);
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,12 +251,12 @@ 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
  };
@@ -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?.(), n = 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() ?? {}, u = t?.query ?? {}, l = { ...a, ...u }, d = {};
322
- return e && (d.visitor_id = e), i && (d.user_id = i), n && (d.click_id = n), r && (d.campaign_id = r), o && (d.session_id = o), Object.keys(l).length > 0 && (d.query = l), 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, n] of Object.entries(t))
335
- k.has(i) || (e[i] = n);
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, n] of Object.entries(t))
341
- P.has(i) || (e[i] = n);
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,27 +388,27 @@ 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?.(), n = i ? Date.parse(i) : 0;
385
- if (!e || !n || t - n >= this.sessionTimeoutMs || this.crossedUtcDay(n, 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), n = new Date(e);
410
+ crossedUtcDay(e, t) {
411
+ const i = new Date(e), n = new Date(t);
398
412
  return i.getUTCFullYear() !== n.getUTCFullYear() || i.getUTCMonth() !== n.getUTCMonth() || i.getUTCDate() !== n.getUTCDate();
399
413
  }
400
414
  shouldSampleTrack() {
@@ -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 = (n) => {
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") {
450
+ const o = window;
451
+ if (typeof o.__tcfapi != "function") {
438
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 u = o.purpose?.consents ?? {};
451
- this.tcfCachedAllowed = e.every((l) => u[String(l)] === !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,15 +471,15 @@ class L {
457
471
  i(10);
458
472
  }
459
473
  }
460
- class R {
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 n = this.sendInternal(t, e, i);
481
+ async send(e, t, i) {
482
+ const n = this.sendInternal(e, t, i);
469
483
  this.pending.add(n);
470
484
  try {
471
485
  await n;
@@ -476,71 +490,71 @@ class R {
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 n = 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", n, 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 f = new Blob([a], { type: "application/json" });
488
- if (navigator.sendBeacon(n, f))
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 u = this.config.request_timeout_ms ?? 1e4, l = 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 p = setTimeout(() => {
509
+ const h = setTimeout(() => {
496
510
  d = !0, l.abort();
497
- }, u);
511
+ }, f);
498
512
  try {
499
- const f = await fetch(n, {
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
518
  signal: l.signal
505
519
  });
506
- if (!f.ok) {
507
- const g = await this.readErrorSnippet(f), w = x(f.headers.get("Retry-After"));
520
+ if (!u.ok) {
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
523
  url: n,
510
- status: f.status,
511
- statusText: f.statusText,
524
+ status: u.status,
525
+ statusText: u.statusText,
512
526
  body: g,
513
- retryAfterMs: w
514
- }), new h(
515
- `[Mark] Request rejected with status ${f.status}: ${g}`,
516
- { status: f.status, retryAfterMs: w }
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
- } catch (f) {
520
- if (this.config.debug && console.error("[Mark] Failed to send", n, f), f instanceof h)
521
- throw f;
533
+ } catch (u) {
534
+ if (this.config.debug && console.error("[Mark] Failed to send", n, u), u instanceof p)
535
+ throw u;
522
536
  if (d)
523
- throw new h(`[Mark] Request timed out after ${u}ms`, { status: 408 });
524
- const g = f instanceof Error ? f.message : String(f);
525
- throw new h(`[Mark] Network error: ${g}`);
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(p);
541
+ clearTimeout(h);
528
542
  }
529
543
  }
530
- joinUrl(t, e) {
531
- const i = t.replace(/\/+$/, ""), n = e.replace(/^\/+/, "");
544
+ joinUrl(e, t) {
545
+ const i = e.replace(/\/+$/, ""), n = t.replace(/^\/+/, "");
532
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 B = "crelora_mark_data", F = "crelora_mark_outbox", y = "crelora_mark_vid";
543
- class H {
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 H {
548
562
  bridgeFrame;
549
563
  bridgeReady = !1;
550
564
  bridgeOrigin;
551
- constructor(t) {
552
- if (this.options = t ?? {}, this.storageKey = this.options.storageKey ?? B, this.outboxKey = this.options.outboxKey ?? F, 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 H {
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 H {
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 H {
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 H {
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 H {
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 n = 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=${n.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 H {
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, n = 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", () => {
717
+ document.body ? o() : document.addEventListener("DOMContentLoaded", o, { once: !0 }), this.bridgeFrame.addEventListener("load", () => {
704
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
- (n) => e.hostname === n || e.hostname.endsWith(`.${n}`)
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 O = [
756
+ const te = [
743
757
  "click_id",
744
758
  "ch_click_id",
745
759
  "gclid",
@@ -751,7 +765,7 @@ const O = [
751
765
  "ttclid",
752
766
  "twclid",
753
767
  "li_fat_id"
754
- ], N = ["cid", "campaign_id"], K = [
768
+ ], ie = ["cid", "campaign_id"], ne = [
755
769
  "utm_source",
756
770
  "utm_medium",
757
771
  "utm_campaign",
@@ -773,101 +787,232 @@ const O = [
773
787
  "ttclid",
774
788
  "twclid",
775
789
  "li_fat_id"
776
- ], z = {
790
+ ], se = {
777
791
  referral: "ref",
778
792
  affiliate_id: "ref",
779
793
  ch_click_id: "click_id",
780
794
  cid: "campaign_id"
781
- }, $ = ["email", "phone", "token", "auth", "password", "code"], V = 30, j = 256;
782
- function b(c, t = {}) {
783
- const e = new URLSearchParams(c), i = Q(e), n = v(i, O), r = v(i, N), o = Y(e, t), a = {};
784
- return n && (a.last_click_id = n), 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 Y(c, t) {
787
- const e = {}, i = new Set(_(t.query_param_denylist, $)), n = A(
788
- t.max_captured_query_params,
789
- V
790
- ), r = A(
791
- t.max_query_param_value_length,
792
- j
793
- ), a = t.capture_all_query_params ?? !1 ? null : /* @__PURE__ */ new Set([
794
- ...K.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 [u, l] of c.entries()) {
798
- const d = m(u);
811
+ for (const [f, l] of r.entries()) {
812
+ const d = I(f);
799
813
  if (!d)
800
814
  continue;
801
- const p = z[d] ?? d;
802
- if (i.has(d) || i.has(p) || 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 f = l.trim();
805
- if (f) {
806
- if (!(p in e) && Object.keys(e).length >= n)
818
+ const u = l.trim();
819
+ if (u) {
820
+ if (!(h in t) && Object.keys(t).length >= n)
807
821
  break;
808
- e[p] = f.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), n = c[i]?.trim();
827
+ function U(r, e) {
828
+ for (const t of e) {
829
+ const i = I(t), n = r[i]?.trim();
816
830
  if (n)
817
831
  return n;
818
832
  }
819
833
  }
820
- function Q(c) {
821
- const t = {};
822
- for (const [e, i] of c.entries()) {
823
- const n = m(e);
824
- !n || n in t || (t[n] = 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 n of e) {
845
+ function R(r, e) {
846
+ const t = r ?? e, i = /* @__PURE__ */ new Set();
847
+ for (const n of t) {
834
848
  if (typeof n != "string") continue;
835
- const r = m(n);
836
- r && i.add(r);
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;
845
859
  }
846
- function S(c) {
847
- return c.length > 1 && c.endsWith("/") ? c.slice(0, -1) : c;
860
+ function E(r) {
861
+ return r.length > 1 && r.endsWith("/") ? r.slice(0, -1) : r;
848
862
  }
849
- function W(c) {
850
- if (!c || c === "?")
863
+ function ue(r) {
864
+ if (!r || r === "?")
851
865
  return "";
852
- const t = c.startsWith("?") ? c.slice(1) : c;
853
- if (!t)
866
+ const e = r.startsWith("?") ? r.slice(1) : r;
867
+ if (!e)
854
868
  return "";
855
- const e = new URLSearchParams(t), i = [];
856
- e.forEach((o, a) => {
857
- i.push([a, o]);
858
- }), i.sort(([o, a], [u, l]) => {
859
- const d = o.localeCompare(u);
860
- return d !== 0 ? d : a.localeCompare(l);
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);
861
875
  });
862
876
  const n = new URLSearchParams();
863
- for (const [o, a] of i)
864
- n.append(o, a);
865
- const r = n.toString();
866
- return r === "" ? "" : `?${r}`;
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;
944
+ }
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));
867
950
  }
868
- function M(c) {
869
- const t = S(c.pathname), e = W(c.search);
870
- return `${c.origin}${t}${e}${c.hash}`;
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
+ });
871
1016
  }
872
1017
  class s {
873
1018
  static client = null;
@@ -877,60 +1022,57 @@ class s {
877
1022
  static lastPageviewDedupeKey = null;
878
1023
  static emitAutoPageview = null;
879
1024
  static pendingAttribution = {};
880
- static originalPushState = null;
881
- static originalReplaceState = null;
882
- static popstateHandler = null;
883
1025
  static beaconDrainHandler = null;
884
1026
  static visibilityHandler = null;
885
1027
  static onlineHandler = null;
886
1028
  static kickTimer = null;
887
- static init(t) {
1029
+ static init(e) {
888
1030
  if (!s.client) {
889
- const e = new H(t.cross_domain), i = new R(t);
890
- s.client = new L(t, { storage: e, transport: i }), s.storage = e, s.config = t, s.refreshAttribution(e, t), typeof window < "u" && t.autocapture?.pageview && s.installPageviewTracking(t, e), typeof window < "u" && (s.installExtendedAutocapture(t), s.installLifecycleFlushing());
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());
891
1033
  }
892
1034
  return s.client;
893
1035
  }
894
1036
  static installLifecycleFlushing() {
895
1037
  if (typeof window > "u" || s.beaconDrainHandler) return;
896
- const t = () => {
1038
+ const e = () => {
897
1039
  s.client?.drainViaBeacon();
898
- }, e = () => {
899
- typeof document < "u" && document.visibilityState === "hidden" && t();
1040
+ }, t = () => {
1041
+ typeof document < "u" && document.visibilityState === "hidden" && e();
900
1042
  }, i = () => {
901
1043
  s.client?.kickQueue();
902
1044
  };
903
- 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(() => {
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(() => {
904
1046
  s.client?.kickQueue();
905
1047
  }, 3e4));
906
1048
  }
907
- static track(t, e = {}) {
1049
+ static track(e, t = {}) {
908
1050
  if (!s.client) {
909
1051
  s.config?.debug && console.warn("[Mark] Not initialized. Call init() first.");
910
1052
  return;
911
1053
  }
912
- s.client.track(t, e);
1054
+ s.client.track(e, t);
913
1055
  }
914
- static identify(t, e = {}) {
1056
+ static identify(e, t = {}) {
915
1057
  if (!s.client) {
916
1058
  s.config?.debug && console.warn("[Mark] Not initialized. Call init() first.");
917
1059
  return;
918
1060
  }
919
- s.client.identify(t, e);
1061
+ s.client.identify(e, t);
920
1062
  }
921
- static conversion(t, e = {}) {
1063
+ static conversion(e, t = {}) {
922
1064
  if (!s.client) {
923
1065
  s.config?.debug && console.warn("[Mark] Not initialized. Call init() first.");
924
1066
  return;
925
1067
  }
926
- s.client.conversion(t, e);
1068
+ s.client.conversion(e, t);
927
1069
  }
928
- static setConsent(t) {
1070
+ static setConsent(e) {
929
1071
  if (!s.client) {
930
1072
  s.config?.debug && console.warn("[Mark] Not initialized. Call init() first.");
931
1073
  return;
932
1074
  }
933
- s.client.setConsent(t), t === "granted" && (s.flushPendingAttribution(), s.emitAutoPageview?.());
1075
+ s.client.setConsent(e), e === "granted" && (s.flushPendingAttribution(), s.emitAutoPageview?.());
934
1076
  }
935
1077
  /**
936
1078
  * Returns the current visitor ID when available.
@@ -959,12 +1101,12 @@ class s {
959
1101
  * if (params.get('onelence_internal') === '1') Mark.setInternal(true);
960
1102
  * if (params.get('onelence_internal') === '0') Mark.setInternal(false);
961
1103
  */
962
- static setInternal(t) {
1104
+ static setInternal(e) {
963
1105
  if (!s.client) {
964
1106
  s.config?.debug && console.warn("[Mark] Not initialized. Call init() first.");
965
1107
  return;
966
1108
  }
967
- s.client.setInternal(t);
1109
+ s.client.setInternal(e);
968
1110
  }
969
1111
  static getInternal() {
970
1112
  return s.client?.getInternal() ?? !1;
@@ -976,123 +1118,109 @@ class s {
976
1118
  return s.client?.getStats() ?? { queued: 0, sent: 0, failed: 0, dropped: 0 };
977
1119
  }
978
1120
  static destroy() {
979
- typeof window > "u" || (s.originalPushState && (history.pushState = s.originalPushState), s.originalReplaceState && (history.replaceState = s.originalReplaceState), s.popstateHandler && window.removeEventListener("popstate", s.popstateHandler), 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.originalPushState = null, s.originalReplaceState = null, s.popstateHandler = null, s.beaconDrainHandler = null, s.visibilityHandler = null, s.onlineHandler = null, s.kickTimer = null, s.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 });
980
1128
  }
981
- static installPageviewTracking(t, e) {
1129
+ static installPageviewTracking(e, t) {
982
1130
  if (s.pageviewTrackerInstalled) return;
983
1131
  s.pageviewTrackerInstalled = !0;
984
1132
  const i = () => {
985
1133
  if (!s.client) return;
986
- s.refreshAttribution(e, t);
987
- const a = M(window.location);
988
- if (a === s.lastPageviewDedupeKey) return;
1134
+ s.refreshAttribution(t, e);
1135
+ const o = C(window.location);
1136
+ if (o === s.lastPageviewDedupeKey) return;
989
1137
  s.client.track("page_view", {
990
1138
  site: window.location.host,
991
- page: S(window.location.pathname),
1139
+ page: E(window.location.pathname),
992
1140
  title: document.title,
993
1141
  referrer: document.referrer || void 0
994
- }) && (s.lastPageviewDedupeKey = a);
1142
+ }) && (s.lastPageviewDedupeKey = o);
995
1143
  };
996
- if (s.emitAutoPageview = i, i(), !(t.track_route_changes ?? !0)) return;
997
- const r = history.pushState, o = history.replaceState;
998
- s.originalPushState = r, s.originalReplaceState = o, history.pushState = function(...a) {
999
- const u = r.apply(this, a);
1000
- return i(), u;
1001
- }, history.replaceState = function(...a) {
1002
- const u = o.apply(this, a);
1003
- return i(), u;
1004
- }, s.popstateHandler = i, window.addEventListener("popstate", i);
1005
- }
1006
- static refreshAttribution(t, e) {
1144
+ s.emitAutoPageview = i, i(), (e.track_route_changes ?? !0) && q(() => {
1145
+ i();
1146
+ });
1147
+ }
1148
+ static refreshAttribution(e, t) {
1007
1149
  if (typeof window > "u")
1008
1150
  return;
1009
- const i = b(window.location.search, e);
1151
+ const i = L(window.location.search, t);
1010
1152
  if (Object.keys(i).length !== 0) {
1011
- if (s.shouldPersistAttribution(t, e)) {
1153
+ if (s.shouldPersistAttribution(e, t)) {
1012
1154
  const n = s.mergeAttributionUpdates(s.pendingAttribution, i);
1013
- t.update(n), s.pendingAttribution = {};
1155
+ e.update(n), s.pendingAttribution = {};
1014
1156
  return;
1015
1157
  }
1016
1158
  s.pendingAttribution = s.mergeAttributionUpdates(s.pendingAttribution, i);
1017
1159
  }
1018
1160
  }
1019
1161
  static flushPendingAttribution() {
1020
- const t = s.storage, e = s.config;
1021
- if (!t || !e || typeof window > "u")
1162
+ const e = s.storage, t = s.config;
1163
+ if (!e || !t || typeof window > "u")
1022
1164
  return;
1023
- const i = b(window.location.search, e), n = s.mergeAttributionUpdates(s.pendingAttribution, i);
1024
- Object.keys(n).length > 0 && t.update(n), s.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 = {};
1025
1167
  }
1026
- static shouldPersistAttribution(t, e) {
1027
- return e.require_consent ?? !1 ? t.getConsentStatus() === "granted" : !0;
1168
+ static shouldPersistAttribution(e, t) {
1169
+ return t.require_consent ?? !1 ? e.getConsentStatus() === "granted" : !0;
1028
1170
  }
1029
- static mergeAttributionUpdates(t, e) {
1171
+ static mergeAttributionUpdates(e, t) {
1030
1172
  return {
1031
- ...t,
1032
1173
  ...e,
1174
+ ...t,
1033
1175
  query_params: {
1034
- ...t.query_params ?? {},
1035
- ...e.query_params ?? {}
1176
+ ...e.query_params ?? {},
1177
+ ...t.query_params ?? {}
1036
1178
  }
1037
1179
  };
1038
1180
  }
1039
- static installExtendedAutocapture(t) {
1181
+ static installExtendedAutocapture(e) {
1040
1182
  if (!s.client || typeof document > "u") return;
1041
- const e = t.autocapture;
1042
- if (e) {
1043
- if (e.click && document.addEventListener("click", (i) => {
1044
- const n = i.target;
1045
- if (!n) return;
1046
- const r = typeof e.click == "object" ? e.click.selector : void 0, o = r ? n.closest(r) : n.closest("[data-mark-event]");
1047
- if (!o) return;
1048
- const a = o.getAttribute("data-mark-event") || "click";
1049
- s.client?.track(a, {
1050
- element_id: o.id || void 0,
1051
- element_classes: o.className || void 0,
1052
- text: o.textContent?.trim().slice(0, 120) || void 0,
1053
- href: o.href || void 0
1054
- });
1055
- }), e.form_submit && document.addEventListener("submit", (i) => {
1056
- const n = i.target;
1057
- n && s.client?.track("form_submit", {
1058
- form_id: n.id || void 0,
1059
- form_name: n.name || void 0,
1060
- action: n.action || void 0
1061
- });
1062
- }), e.outbound_link && document.addEventListener("click", (i) => {
1063
- const n = i.target?.closest("a[href]");
1064
- if (!(!n || !n.href))
1065
- try {
1066
- const r = new URL(n.href, window.location.href), o = new URL(window.location.href);
1067
- r.origin !== o.origin && s.client?.trackWithOptions("outbound_link_click", { href: r.toString() }, { preferBeacon: !0 });
1068
- } catch {
1069
- }
1070
- }), e.scroll_depth) {
1071
- const i = [25, 50, 75, 100], n = /* @__PURE__ */ new Set();
1072
- window.addEventListener(
1073
- "scroll",
1074
- () => {
1075
- const r = document.documentElement, o = window.scrollY || r.scrollTop, a = Math.max(1, r.scrollHeight - window.innerHeight), u = Math.min(100, Math.round(o / a * 100));
1076
- for (const l of i)
1077
- u >= l && !n.has(l) && (n.add(l), s.client?.track("scroll_depth", { percent: l }));
1078
- },
1079
- { passive: !0 }
1080
- );
1081
- }
1082
- e.web_vitals && import("./web-vitals-CrnTllyu.js").then((i) => {
1083
- const n = (r) => {
1084
- s.client?.track("web_vital", {
1085
- metric: r.name,
1086
- value: r.value,
1087
- rating: r.rating,
1088
- metric_id: r.id
1089
- });
1090
- };
1091
- i.onLCP(n), i.onCLS(n), i.onINP(n), i.onTTFB(n);
1092
- }).catch(() => {
1093
- t.debug && console.warn("[Mark] web-vitals package not available; skipping autocapture.web_vitals.");
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
1094
1195
  });
1095
- }
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
+ }));
1096
1224
  }
1097
1225
  }
1098
1226
  typeof window < "u" && (window.Mark = s);