@crelora/mark 0.2.2 → 0.3.0

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