@crelora/mark 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/browser.es.js
CHANGED
|
@@ -6,10 +6,10 @@ class h extends Error {
|
|
|
6
6
|
super(t), this.name = "TransportError", this.status = e.status, this.retryAfterMs = e.retryAfterMs;
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
-
function
|
|
9
|
+
function E(c) {
|
|
10
10
|
return !(typeof c != "number" || c < 400 || c >= 500 || c === 408 || c === 429);
|
|
11
11
|
}
|
|
12
|
-
function
|
|
12
|
+
function x(c) {
|
|
13
13
|
if (!c) return;
|
|
14
14
|
const t = c.trim();
|
|
15
15
|
if (!t) return;
|
|
@@ -18,20 +18,20 @@ function E(c) {
|
|
|
18
18
|
return Math.floor(e * 1e3);
|
|
19
19
|
const i = Date.parse(t);
|
|
20
20
|
if (Number.isFinite(i)) {
|
|
21
|
-
const
|
|
22
|
-
return
|
|
21
|
+
const n = i - Date.now();
|
|
22
|
+
return n > 0 ? n : 0;
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
const
|
|
26
|
-
class
|
|
25
|
+
const q = 5, T = 300, D = 15e3, C = 2880 * 60 * 1e3;
|
|
26
|
+
class U {
|
|
27
27
|
constructor(t, e = {}) {
|
|
28
|
-
this.transport = t, this.maxAttempts = e.maxAttempts ??
|
|
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;
|
|
29
29
|
const i = this.loadPersisted?.() ?? [];
|
|
30
30
|
if (i.length > 0) {
|
|
31
|
-
const
|
|
31
|
+
const n = Date.now();
|
|
32
32
|
for (const r of i) {
|
|
33
|
-
const o = r.enqueuedAt ??
|
|
34
|
-
if (
|
|
33
|
+
const o = r.enqueuedAt ?? n;
|
|
34
|
+
if (n - o > this.maxItemAgeMs) {
|
|
35
35
|
this.dropped += 1;
|
|
36
36
|
continue;
|
|
37
37
|
}
|
|
@@ -100,8 +100,8 @@ class C {
|
|
|
100
100
|
if (this.queue.length === 0) return;
|
|
101
101
|
const e = Date.now() - this.maxItemAgeMs;
|
|
102
102
|
let i = 0;
|
|
103
|
-
for (let
|
|
104
|
-
this.queue[
|
|
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);
|
|
105
105
|
i > 0 && this.persist();
|
|
106
106
|
}
|
|
107
107
|
async process(t = !1) {
|
|
@@ -113,13 +113,13 @@ class C {
|
|
|
113
113
|
if (!t && e.nextAttemptAt > Date.now())
|
|
114
114
|
break;
|
|
115
115
|
try {
|
|
116
|
-
const i = { ...e.data },
|
|
117
|
-
delete i.__prefer_beacon, await this.transport.send(e.path, i, { preferBeacon:
|
|
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
119
|
this.failed += 1, this.onError?.(i, e.data);
|
|
120
|
-
const
|
|
121
|
-
if (
|
|
122
|
-
this.queue.shift(), this.dropped += 1, this.persist(), this.debug && console.error("[Mark] Dropping event after non-retriable status",
|
|
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);
|
|
123
123
|
continue;
|
|
124
124
|
}
|
|
125
125
|
if (e.attempts += 1, e.attempts >= this.maxAttempts) {
|
|
@@ -147,7 +147,7 @@ class C {
|
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
|
-
const
|
|
150
|
+
const k = /* @__PURE__ */ new Set(["event_name", "user_id", "consent_state", "source", "is_conversion"]), P = /* @__PURE__ */ new Set([
|
|
151
151
|
"user_id",
|
|
152
152
|
"visitor_id",
|
|
153
153
|
"click_id",
|
|
@@ -162,11 +162,11 @@ class L {
|
|
|
162
162
|
endpoint: t.endpoint ?? I,
|
|
163
163
|
...t,
|
|
164
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
|
|
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, {
|
|
166
166
|
debug: this.config.debug,
|
|
167
167
|
loadPersisted: () => this.deps.storage.getOutbox?.() ?? [],
|
|
168
168
|
savePersisted: (i) => this.deps.storage.setOutbox?.(i),
|
|
169
|
-
onError: (i,
|
|
169
|
+
onError: (i, n) => this.config.on_error?.(i, n)
|
|
170
170
|
}), this.warnMisconfiguredSiteHost(), this.subscribeTcf();
|
|
171
171
|
}
|
|
172
172
|
config;
|
|
@@ -197,7 +197,7 @@ class L {
|
|
|
197
197
|
track(t, e = {}) {
|
|
198
198
|
return this.trackInternal(t, e, !1);
|
|
199
199
|
}
|
|
200
|
-
trackInternal(t, e = {}, i = !1,
|
|
200
|
+
trackInternal(t, e = {}, i = !1, n) {
|
|
201
201
|
if (!t)
|
|
202
202
|
return this.config.debug && console.warn("[Mark] track called without event name"), !1;
|
|
203
203
|
if (!this.hasConsent() || this.isDntBlocked())
|
|
@@ -213,10 +213,10 @@ class L {
|
|
|
213
213
|
...o
|
|
214
214
|
};
|
|
215
215
|
i && (a.is_conversion = !0);
|
|
216
|
-
const
|
|
217
|
-
|
|
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
218
|
const d = this.config.before_send ? this.config.before_send(a) : a;
|
|
219
|
-
return d ? (this.ensureSession(), this.config.batching?.enabled && !i && !
|
|
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
220
|
}
|
|
221
221
|
identify(t, e = {}) {
|
|
222
222
|
if (!t) {
|
|
@@ -235,8 +235,8 @@ class L {
|
|
|
235
235
|
...this.getIdentityFields()
|
|
236
236
|
};
|
|
237
237
|
this.siteId && (i.site_id = this.siteId), this.siteHost && (i.site_host = this.siteHost), this.applyInternalFlag(i);
|
|
238
|
-
const
|
|
239
|
-
|
|
238
|
+
const n = this.config.before_send ? this.config.before_send(i) : i;
|
|
239
|
+
n && this.queue.enqueue("/identify", n);
|
|
240
240
|
}
|
|
241
241
|
conversion(t, e = {}) {
|
|
242
242
|
return this.trackInternal(t, e, !0);
|
|
@@ -261,8 +261,8 @@ class L {
|
|
|
261
261
|
message_id: this.createMessageId()
|
|
262
262
|
};
|
|
263
263
|
this.siteId && (i.site_id = this.siteId), this.siteHost && (i.site_host = this.siteHost), this.applyInternalFlag(i);
|
|
264
|
-
const
|
|
265
|
-
|
|
264
|
+
const n = this.config.before_send ? this.config.before_send(i) : i;
|
|
265
|
+
n && this.queue.enqueue("/consent", n);
|
|
266
266
|
}
|
|
267
267
|
reset() {
|
|
268
268
|
this.deps.storage.update({
|
|
@@ -318,8 +318,8 @@ class L {
|
|
|
318
318
|
e === !0 || i ? t.is_internal = !0 : delete t.is_internal;
|
|
319
319
|
}
|
|
320
320
|
getIdentityFields(t) {
|
|
321
|
-
const e = t?.visitor_id ?? this.deps.storage.getVisitorId(), i = t?.user_id ?? this.deps.storage.getUserId?.(),
|
|
322
|
-
return e && (d.visitor_id = e), i && (d.user_id = i),
|
|
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;
|
|
323
323
|
}
|
|
324
324
|
hasConsent() {
|
|
325
325
|
if (this.config.consent_source?.type === "tcf" && typeof window < "u" && !this.tcfCachedAllowed)
|
|
@@ -331,14 +331,14 @@ class L {
|
|
|
331
331
|
}
|
|
332
332
|
sanitizeTrackData(t) {
|
|
333
333
|
const e = {};
|
|
334
|
-
for (const [i,
|
|
335
|
-
|
|
334
|
+
for (const [i, n] of Object.entries(t))
|
|
335
|
+
k.has(i) || (e[i] = n);
|
|
336
336
|
return e;
|
|
337
337
|
}
|
|
338
338
|
sanitizeIdentifyTraits(t) {
|
|
339
339
|
const e = {};
|
|
340
|
-
for (const [i,
|
|
341
|
-
|
|
340
|
+
for (const [i, n] of Object.entries(t))
|
|
341
|
+
P.has(i) || (e[i] = n);
|
|
342
342
|
return e;
|
|
343
343
|
}
|
|
344
344
|
validateConfig(t) {
|
|
@@ -381,8 +381,8 @@ class L {
|
|
|
381
381
|
return typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : `msg_${Date.now()}_${Math.random().toString(16).slice(2)}`;
|
|
382
382
|
}
|
|
383
383
|
ensureSession() {
|
|
384
|
-
const t = Date.now(), e = this.deps.storage.getSessionId?.(), i = this.deps.storage.getLastActivityAt?.(),
|
|
385
|
-
if (!e || !
|
|
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
386
|
const o = this.createMessageId(), a = new Date(t).toISOString();
|
|
387
387
|
this.deps.storage.update({
|
|
388
388
|
session_id: o,
|
|
@@ -394,8 +394,8 @@ class L {
|
|
|
394
394
|
this.deps.storage.update({ last_activity_at: new Date(t).toISOString() });
|
|
395
395
|
}
|
|
396
396
|
crossedUtcDay(t, e) {
|
|
397
|
-
const i = new Date(t),
|
|
398
|
-
return i.getUTCFullYear() !==
|
|
397
|
+
const i = new Date(t), n = new Date(e);
|
|
398
|
+
return i.getUTCFullYear() !== n.getUTCFullYear() || i.getUTCMonth() !== n.getUTCMonth() || i.getUTCDate() !== n.getUTCDate();
|
|
399
399
|
}
|
|
400
400
|
shouldSampleTrack() {
|
|
401
401
|
return typeof this.config.sample_rate != "number" ? !0 : this.config.sample_rate <= 0 ? !1 : this.config.sample_rate >= 1 ? !0 : Math.random() <= this.config.sample_rate;
|
|
@@ -431,11 +431,11 @@ class L {
|
|
|
431
431
|
subscribeTcf() {
|
|
432
432
|
const t = this.config.consent_source;
|
|
433
433
|
if (t?.type !== "tcf" || typeof window > "u") return;
|
|
434
|
-
const e = t.purposes, i = (
|
|
434
|
+
const e = t.purposes, i = (n) => {
|
|
435
435
|
try {
|
|
436
436
|
const r = window;
|
|
437
437
|
if (typeof r.__tcfapi != "function") {
|
|
438
|
-
|
|
438
|
+
n > 0 && setTimeout(() => i(n - 1), 200);
|
|
439
439
|
return;
|
|
440
440
|
}
|
|
441
441
|
r.__tcfapi("addEventListener", 2, (o, a) => {
|
|
@@ -447,8 +447,8 @@ class L {
|
|
|
447
447
|
this.tcfCachedAllowed = !0;
|
|
448
448
|
return;
|
|
449
449
|
}
|
|
450
|
-
const
|
|
451
|
-
this.tcfCachedAllowed = e.every((
|
|
450
|
+
const u = o.purpose?.consents ?? {};
|
|
451
|
+
this.tcfCachedAllowed = e.every((l) => u[String(l)] === !0);
|
|
452
452
|
});
|
|
453
453
|
} catch {
|
|
454
454
|
this.tcfCachedAllowed = !1;
|
|
@@ -457,7 +457,7 @@ class L {
|
|
|
457
457
|
i(10);
|
|
458
458
|
}
|
|
459
459
|
}
|
|
460
|
-
class
|
|
460
|
+
class R {
|
|
461
461
|
config;
|
|
462
462
|
endpoint;
|
|
463
463
|
pending = /* @__PURE__ */ new Set();
|
|
@@ -465,71 +465,71 @@ class P {
|
|
|
465
465
|
this.config = t, this.endpoint = t.endpoint ?? I;
|
|
466
466
|
}
|
|
467
467
|
async send(t, e, i) {
|
|
468
|
-
const
|
|
469
|
-
this.pending.add(
|
|
468
|
+
const n = this.sendInternal(t, e, i);
|
|
469
|
+
this.pending.add(n);
|
|
470
470
|
try {
|
|
471
|
-
await
|
|
471
|
+
await n;
|
|
472
472
|
} finally {
|
|
473
|
-
this.pending.delete(
|
|
473
|
+
this.pending.delete(n);
|
|
474
474
|
}
|
|
475
475
|
}
|
|
476
476
|
async flush() {
|
|
477
477
|
this.pending.size !== 0 && await Promise.allSettled(Array.from(this.pending));
|
|
478
478
|
}
|
|
479
479
|
async sendInternal(t, e, i) {
|
|
480
|
-
const
|
|
480
|
+
const n = this.joinUrl(this.endpoint, t), r = this.config.key, o = {
|
|
481
481
|
"Content-Type": "application/json",
|
|
482
482
|
[r.startsWith("sk_") ? "x-secret-key" : "x-publishable-key"]: r
|
|
483
483
|
};
|
|
484
|
-
this.config.debug && console.log("[Mark] Sending",
|
|
484
|
+
this.config.debug && console.log("[Mark] Sending", n, e);
|
|
485
485
|
const a = JSON.stringify(e);
|
|
486
486
|
if (i?.preferBeacon && typeof navigator < "u" && typeof navigator.sendBeacon == "function") {
|
|
487
|
-
const
|
|
488
|
-
if (navigator.sendBeacon(
|
|
487
|
+
const f = new Blob([a], { type: "application/json" });
|
|
488
|
+
if (navigator.sendBeacon(n, f))
|
|
489
489
|
return;
|
|
490
490
|
}
|
|
491
491
|
if (typeof fetch != "function")
|
|
492
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
|
|
493
|
+
const u = this.config.request_timeout_ms ?? 1e4, l = new AbortController();
|
|
494
494
|
let d = !1;
|
|
495
|
-
const
|
|
496
|
-
d = !0,
|
|
497
|
-
},
|
|
495
|
+
const p = setTimeout(() => {
|
|
496
|
+
d = !0, l.abort();
|
|
497
|
+
}, u);
|
|
498
498
|
try {
|
|
499
|
-
const
|
|
499
|
+
const f = await fetch(n, {
|
|
500
500
|
method: "POST",
|
|
501
501
|
headers: o,
|
|
502
502
|
body: a,
|
|
503
503
|
keepalive: !0,
|
|
504
|
-
signal:
|
|
504
|
+
signal: l.signal
|
|
505
505
|
});
|
|
506
|
-
if (!
|
|
507
|
-
const
|
|
506
|
+
if (!f.ok) {
|
|
507
|
+
const g = await this.readErrorSnippet(f), w = x(f.headers.get("Retry-After"));
|
|
508
508
|
throw this.config.debug && console.error("[Mark] Request rejected", {
|
|
509
|
-
url:
|
|
510
|
-
status:
|
|
511
|
-
statusText:
|
|
512
|
-
body:
|
|
509
|
+
url: n,
|
|
510
|
+
status: f.status,
|
|
511
|
+
statusText: f.statusText,
|
|
512
|
+
body: g,
|
|
513
513
|
retryAfterMs: w
|
|
514
514
|
}), new h(
|
|
515
|
-
`[Mark] Request rejected with status ${
|
|
516
|
-
{ status:
|
|
515
|
+
`[Mark] Request rejected with status ${f.status}: ${g}`,
|
|
516
|
+
{ status: f.status, retryAfterMs: w }
|
|
517
517
|
);
|
|
518
518
|
}
|
|
519
|
-
} catch (
|
|
520
|
-
if (this.config.debug && console.error("[Mark] Failed to send",
|
|
521
|
-
throw
|
|
519
|
+
} catch (f) {
|
|
520
|
+
if (this.config.debug && console.error("[Mark] Failed to send", n, f), f instanceof h)
|
|
521
|
+
throw f;
|
|
522
522
|
if (d)
|
|
523
|
-
throw new h(`[Mark] Request timed out after ${
|
|
524
|
-
const
|
|
525
|
-
throw new h(`[Mark] Network error: ${
|
|
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}`);
|
|
526
526
|
} finally {
|
|
527
|
-
clearTimeout(
|
|
527
|
+
clearTimeout(p);
|
|
528
528
|
}
|
|
529
529
|
}
|
|
530
530
|
joinUrl(t, e) {
|
|
531
|
-
const i = t.replace(/\/+$/, ""),
|
|
532
|
-
return `${i}/${
|
|
531
|
+
const i = t.replace(/\/+$/, ""), n = e.replace(/^\/+/, "");
|
|
532
|
+
return `${i}/${n}`;
|
|
533
533
|
}
|
|
534
534
|
async readErrorSnippet(t) {
|
|
535
535
|
try {
|
|
@@ -539,8 +539,8 @@ class P {
|
|
|
539
539
|
}
|
|
540
540
|
}
|
|
541
541
|
}
|
|
542
|
-
const
|
|
543
|
-
class
|
|
542
|
+
const B = "crelora_mark_data", F = "crelora_mark_outbox", y = "crelora_mark_vid";
|
|
543
|
+
class H {
|
|
544
544
|
data;
|
|
545
545
|
storageKey;
|
|
546
546
|
outboxKey;
|
|
@@ -549,7 +549,7 @@ class F {
|
|
|
549
549
|
bridgeReady = !1;
|
|
550
550
|
bridgeOrigin;
|
|
551
551
|
constructor(t) {
|
|
552
|
-
if (this.options = t ?? {}, this.storageKey = this.options.storageKey ??
|
|
552
|
+
if (this.options = t ?? {}, this.storageKey = this.options.storageKey ?? B, this.outboxKey = this.options.outboxKey ?? F, typeof window > "u") {
|
|
553
553
|
this.data = {};
|
|
554
554
|
return;
|
|
555
555
|
}
|
|
@@ -662,8 +662,8 @@ class F {
|
|
|
662
662
|
setCookie(t, e, i) {
|
|
663
663
|
if (!(typeof document > "u"))
|
|
664
664
|
try {
|
|
665
|
-
const
|
|
666
|
-
document.cookie = `${t}=${e};expires=${
|
|
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}`;
|
|
667
667
|
} catch {
|
|
668
668
|
}
|
|
669
669
|
}
|
|
@@ -693,7 +693,7 @@ class F {
|
|
|
693
693
|
return;
|
|
694
694
|
}
|
|
695
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,
|
|
696
|
+
const i = t.timeout_ms ?? 3e3, n = setTimeout(() => {
|
|
697
697
|
window.removeEventListener("message", this.handleBridgeMessage);
|
|
698
698
|
}, i);
|
|
699
699
|
window.addEventListener("message", this.handleBridgeMessage);
|
|
@@ -701,7 +701,7 @@ class F {
|
|
|
701
701
|
this.bridgeFrame && document.body && document.body.appendChild(this.bridgeFrame);
|
|
702
702
|
};
|
|
703
703
|
document.body ? r() : document.addEventListener("DOMContentLoaded", r, { once: !0 }), this.bridgeFrame.addEventListener("load", () => {
|
|
704
|
-
clearTimeout(
|
|
704
|
+
clearTimeout(n), this.bridgeReady = !0, this.postBridgeMessage({
|
|
705
705
|
type: "MARK_SYNC_REQUEST",
|
|
706
706
|
visitorId: this.data.visitor_id
|
|
707
707
|
});
|
|
@@ -721,7 +721,7 @@ class F {
|
|
|
721
721
|
const e = new URL(t);
|
|
722
722
|
if (this.options.allowed_domains?.length)
|
|
723
723
|
return this.options.allowed_domains.some(
|
|
724
|
-
(
|
|
724
|
+
(n) => e.hostname === n || e.hostname.endsWith(`.${n}`)
|
|
725
725
|
);
|
|
726
726
|
if (!this.bridgeOrigin)
|
|
727
727
|
return !1;
|
|
@@ -739,7 +739,7 @@ class F {
|
|
|
739
739
|
}
|
|
740
740
|
};
|
|
741
741
|
}
|
|
742
|
-
const
|
|
742
|
+
const O = [
|
|
743
743
|
"click_id",
|
|
744
744
|
"ch_click_id",
|
|
745
745
|
"gclid",
|
|
@@ -751,7 +751,7 @@ const H = [
|
|
|
751
751
|
"ttclid",
|
|
752
752
|
"twclid",
|
|
753
753
|
"li_fat_id"
|
|
754
|
-
],
|
|
754
|
+
], N = ["cid", "campaign_id"], K = [
|
|
755
755
|
"utm_source",
|
|
756
756
|
"utm_medium",
|
|
757
757
|
"utm_campaign",
|
|
@@ -773,55 +773,55 @@ const H = [
|
|
|
773
773
|
"ttclid",
|
|
774
774
|
"twclid",
|
|
775
775
|
"li_fat_id"
|
|
776
|
-
],
|
|
776
|
+
], z = {
|
|
777
777
|
referral: "ref",
|
|
778
778
|
affiliate_id: "ref",
|
|
779
779
|
ch_click_id: "click_id",
|
|
780
780
|
cid: "campaign_id"
|
|
781
|
-
},
|
|
781
|
+
}, $ = ["email", "phone", "token", "auth", "password", "code"], V = 30, j = 256;
|
|
782
782
|
function b(c, t = {}) {
|
|
783
|
-
const e = new URLSearchParams(c), i =
|
|
784
|
-
return
|
|
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;
|
|
785
785
|
}
|
|
786
|
-
function
|
|
787
|
-
const e = {}, i = new Set(_(t.query_param_denylist,
|
|
786
|
+
function Y(c, t) {
|
|
787
|
+
const e = {}, i = new Set(_(t.query_param_denylist, $)), n = A(
|
|
788
788
|
t.max_captured_query_params,
|
|
789
|
-
|
|
789
|
+
V
|
|
790
790
|
), r = A(
|
|
791
791
|
t.max_query_param_value_length,
|
|
792
|
-
|
|
792
|
+
j
|
|
793
793
|
), a = t.capture_all_query_params ?? !1 ? null : /* @__PURE__ */ new Set([
|
|
794
|
-
...
|
|
794
|
+
...K.map(m),
|
|
795
795
|
..._(t.capture_query_params, [])
|
|
796
796
|
]);
|
|
797
|
-
for (const [
|
|
798
|
-
const d = m(
|
|
797
|
+
for (const [u, l] of c.entries()) {
|
|
798
|
+
const d = m(u);
|
|
799
799
|
if (!d)
|
|
800
800
|
continue;
|
|
801
|
-
const
|
|
802
|
-
if (i.has(d) || i.has(
|
|
801
|
+
const p = z[d] ?? d;
|
|
802
|
+
if (i.has(d) || i.has(p) || a && !a.has(d))
|
|
803
803
|
continue;
|
|
804
|
-
const
|
|
805
|
-
if (
|
|
806
|
-
if (!(
|
|
804
|
+
const f = l.trim();
|
|
805
|
+
if (f) {
|
|
806
|
+
if (!(p in e) && Object.keys(e).length >= n)
|
|
807
807
|
break;
|
|
808
|
-
e[
|
|
808
|
+
e[p] = f.slice(0, r);
|
|
809
809
|
}
|
|
810
810
|
}
|
|
811
811
|
return e;
|
|
812
812
|
}
|
|
813
813
|
function v(c, t) {
|
|
814
814
|
for (const e of t) {
|
|
815
|
-
const i = m(e),
|
|
816
|
-
if (
|
|
817
|
-
return
|
|
815
|
+
const i = m(e), n = c[i]?.trim();
|
|
816
|
+
if (n)
|
|
817
|
+
return n;
|
|
818
818
|
}
|
|
819
819
|
}
|
|
820
|
-
function
|
|
820
|
+
function Q(c) {
|
|
821
821
|
const t = {};
|
|
822
822
|
for (const [e, i] of c.entries()) {
|
|
823
|
-
const
|
|
824
|
-
!
|
|
823
|
+
const n = m(e);
|
|
824
|
+
!n || n in t || (t[n] = i);
|
|
825
825
|
}
|
|
826
826
|
return t;
|
|
827
827
|
}
|
|
@@ -830,9 +830,9 @@ function m(c) {
|
|
|
830
830
|
}
|
|
831
831
|
function _(c, t) {
|
|
832
832
|
const e = c ?? t, i = /* @__PURE__ */ new Set();
|
|
833
|
-
for (const
|
|
834
|
-
if (typeof
|
|
835
|
-
const r = m(
|
|
833
|
+
for (const n of e) {
|
|
834
|
+
if (typeof n != "string") continue;
|
|
835
|
+
const r = m(n);
|
|
836
836
|
r && i.add(r);
|
|
837
837
|
}
|
|
838
838
|
return Array.from(i);
|
|
@@ -843,12 +843,38 @@ function A(c, t) {
|
|
|
843
843
|
const e = Math.floor(c);
|
|
844
844
|
return e < 0 ? t : e;
|
|
845
845
|
}
|
|
846
|
-
|
|
846
|
+
function S(c) {
|
|
847
|
+
return c.length > 1 && c.endsWith("/") ? c.slice(0, -1) : c;
|
|
848
|
+
}
|
|
849
|
+
function W(c) {
|
|
850
|
+
if (!c || c === "?")
|
|
851
|
+
return "";
|
|
852
|
+
const t = c.startsWith("?") ? c.slice(1) : c;
|
|
853
|
+
if (!t)
|
|
854
|
+
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);
|
|
861
|
+
});
|
|
862
|
+
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}`;
|
|
867
|
+
}
|
|
868
|
+
function M(c) {
|
|
869
|
+
const t = S(c.pathname), e = W(c.search);
|
|
870
|
+
return `${c.origin}${t}${e}${c.hash}`;
|
|
871
|
+
}
|
|
872
|
+
class s {
|
|
847
873
|
static client = null;
|
|
848
874
|
static storage = null;
|
|
849
875
|
static config = null;
|
|
850
876
|
static pageviewTrackerInstalled = !1;
|
|
851
|
-
static
|
|
877
|
+
static lastPageviewDedupeKey = null;
|
|
852
878
|
static emitAutoPageview = null;
|
|
853
879
|
static pendingAttribution = {};
|
|
854
880
|
static originalPushState = null;
|
|
@@ -859,52 +885,52 @@ class n {
|
|
|
859
885
|
static onlineHandler = null;
|
|
860
886
|
static kickTimer = null;
|
|
861
887
|
static init(t) {
|
|
862
|
-
if (!
|
|
863
|
-
const e = new
|
|
864
|
-
|
|
888
|
+
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());
|
|
865
891
|
}
|
|
866
|
-
return
|
|
892
|
+
return s.client;
|
|
867
893
|
}
|
|
868
894
|
static installLifecycleFlushing() {
|
|
869
|
-
if (typeof window > "u" ||
|
|
895
|
+
if (typeof window > "u" || s.beaconDrainHandler) return;
|
|
870
896
|
const t = () => {
|
|
871
|
-
|
|
897
|
+
s.client?.drainViaBeacon();
|
|
872
898
|
}, e = () => {
|
|
873
899
|
typeof document < "u" && document.visibilityState === "hidden" && t();
|
|
874
900
|
}, i = () => {
|
|
875
|
-
|
|
901
|
+
s.client?.kickQueue();
|
|
876
902
|
};
|
|
877
|
-
|
|
878
|
-
|
|
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(() => {
|
|
904
|
+
s.client?.kickQueue();
|
|
879
905
|
}, 3e4));
|
|
880
906
|
}
|
|
881
907
|
static track(t, e = {}) {
|
|
882
|
-
if (!
|
|
883
|
-
|
|
908
|
+
if (!s.client) {
|
|
909
|
+
s.config?.debug && console.warn("[Mark] Not initialized. Call init() first.");
|
|
884
910
|
return;
|
|
885
911
|
}
|
|
886
|
-
|
|
912
|
+
s.client.track(t, e);
|
|
887
913
|
}
|
|
888
914
|
static identify(t, e = {}) {
|
|
889
|
-
if (!
|
|
890
|
-
|
|
915
|
+
if (!s.client) {
|
|
916
|
+
s.config?.debug && console.warn("[Mark] Not initialized. Call init() first.");
|
|
891
917
|
return;
|
|
892
918
|
}
|
|
893
|
-
|
|
919
|
+
s.client.identify(t, e);
|
|
894
920
|
}
|
|
895
921
|
static conversion(t, e = {}) {
|
|
896
|
-
if (!
|
|
897
|
-
|
|
922
|
+
if (!s.client) {
|
|
923
|
+
s.config?.debug && console.warn("[Mark] Not initialized. Call init() first.");
|
|
898
924
|
return;
|
|
899
925
|
}
|
|
900
|
-
|
|
926
|
+
s.client.conversion(t, e);
|
|
901
927
|
}
|
|
902
928
|
static setConsent(t) {
|
|
903
|
-
if (!
|
|
904
|
-
|
|
929
|
+
if (!s.client) {
|
|
930
|
+
s.config?.debug && console.warn("[Mark] Not initialized. Call init() first.");
|
|
905
931
|
return;
|
|
906
932
|
}
|
|
907
|
-
|
|
933
|
+
s.client.setConsent(t), t === "granted" && (s.flushPendingAttribution(), s.emitAutoPageview?.());
|
|
908
934
|
}
|
|
909
935
|
/**
|
|
910
936
|
* Returns the current visitor ID when available.
|
|
@@ -913,11 +939,11 @@ class n {
|
|
|
913
939
|
* when you do not have an authenticated user ID.
|
|
914
940
|
*/
|
|
915
941
|
static getVisitorId() {
|
|
916
|
-
if (!(!
|
|
917
|
-
return
|
|
942
|
+
if (!(!s.client || !s.storage || !s.config || (s.config.require_consent ?? !1) && s.storage.getConsentStatus() !== "granted"))
|
|
943
|
+
return s.client.getVisitorId();
|
|
918
944
|
}
|
|
919
945
|
static flush() {
|
|
920
|
-
return
|
|
946
|
+
return s.client ? s.client.flush() : Promise.resolve();
|
|
921
947
|
}
|
|
922
948
|
/**
|
|
923
949
|
* Flags (or un-flags) the current visitor as internal traffic. Persists
|
|
@@ -934,68 +960,68 @@ class n {
|
|
|
934
960
|
* if (params.get('onelence_internal') === '0') Mark.setInternal(false);
|
|
935
961
|
*/
|
|
936
962
|
static setInternal(t) {
|
|
937
|
-
if (!
|
|
938
|
-
|
|
963
|
+
if (!s.client) {
|
|
964
|
+
s.config?.debug && console.warn("[Mark] Not initialized. Call init() first.");
|
|
939
965
|
return;
|
|
940
966
|
}
|
|
941
|
-
|
|
967
|
+
s.client.setInternal(t);
|
|
942
968
|
}
|
|
943
969
|
static getInternal() {
|
|
944
|
-
return
|
|
970
|
+
return s.client?.getInternal() ?? !1;
|
|
945
971
|
}
|
|
946
972
|
static reset() {
|
|
947
|
-
|
|
973
|
+
s.client?.reset(), s.pendingAttribution = {}, s.lastPageviewDedupeKey = null;
|
|
948
974
|
}
|
|
949
975
|
static getStats() {
|
|
950
|
-
return
|
|
976
|
+
return s.client?.getStats() ?? { queued: 0, sent: 0, failed: 0, dropped: 0 };
|
|
951
977
|
}
|
|
952
978
|
static destroy() {
|
|
953
|
-
typeof window > "u" || (
|
|
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);
|
|
954
980
|
}
|
|
955
981
|
static installPageviewTracking(t, e) {
|
|
956
|
-
if (
|
|
957
|
-
|
|
982
|
+
if (s.pageviewTrackerInstalled) return;
|
|
983
|
+
s.pageviewTrackerInstalled = !0;
|
|
958
984
|
const i = () => {
|
|
959
|
-
if (!
|
|
960
|
-
|
|
961
|
-
const a = window.location
|
|
962
|
-
if (a ===
|
|
963
|
-
|
|
985
|
+
if (!s.client) return;
|
|
986
|
+
s.refreshAttribution(e, t);
|
|
987
|
+
const a = M(window.location);
|
|
988
|
+
if (a === s.lastPageviewDedupeKey) return;
|
|
989
|
+
s.client.track("page_view", {
|
|
964
990
|
site: window.location.host,
|
|
965
|
-
page: window.location.pathname,
|
|
991
|
+
page: S(window.location.pathname),
|
|
966
992
|
title: document.title,
|
|
967
993
|
referrer: document.referrer || void 0
|
|
968
|
-
}) && (
|
|
994
|
+
}) && (s.lastPageviewDedupeKey = a);
|
|
969
995
|
};
|
|
970
|
-
if (
|
|
996
|
+
if (s.emitAutoPageview = i, i(), !(t.track_route_changes ?? !0)) return;
|
|
971
997
|
const r = history.pushState, o = history.replaceState;
|
|
972
|
-
|
|
973
|
-
const
|
|
974
|
-
return i(),
|
|
998
|
+
s.originalPushState = r, s.originalReplaceState = o, history.pushState = function(...a) {
|
|
999
|
+
const u = r.apply(this, a);
|
|
1000
|
+
return i(), u;
|
|
975
1001
|
}, history.replaceState = function(...a) {
|
|
976
|
-
const
|
|
977
|
-
return i(),
|
|
978
|
-
},
|
|
1002
|
+
const u = o.apply(this, a);
|
|
1003
|
+
return i(), u;
|
|
1004
|
+
}, s.popstateHandler = i, window.addEventListener("popstate", i);
|
|
979
1005
|
}
|
|
980
1006
|
static refreshAttribution(t, e) {
|
|
981
1007
|
if (typeof window > "u")
|
|
982
1008
|
return;
|
|
983
1009
|
const i = b(window.location.search, e);
|
|
984
1010
|
if (Object.keys(i).length !== 0) {
|
|
985
|
-
if (
|
|
986
|
-
const
|
|
987
|
-
t.update(
|
|
1011
|
+
if (s.shouldPersistAttribution(t, e)) {
|
|
1012
|
+
const n = s.mergeAttributionUpdates(s.pendingAttribution, i);
|
|
1013
|
+
t.update(n), s.pendingAttribution = {};
|
|
988
1014
|
return;
|
|
989
1015
|
}
|
|
990
|
-
|
|
1016
|
+
s.pendingAttribution = s.mergeAttributionUpdates(s.pendingAttribution, i);
|
|
991
1017
|
}
|
|
992
1018
|
}
|
|
993
1019
|
static flushPendingAttribution() {
|
|
994
|
-
const t =
|
|
1020
|
+
const t = s.storage, e = s.config;
|
|
995
1021
|
if (!t || !e || typeof window > "u")
|
|
996
1022
|
return;
|
|
997
|
-
const i = b(window.location.search, e),
|
|
998
|
-
Object.keys(
|
|
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 = {};
|
|
999
1025
|
}
|
|
1000
1026
|
static shouldPersistAttribution(t, e) {
|
|
1001
1027
|
return e.require_consent ?? !1 ? t.getConsentStatus() === "granted" : !0;
|
|
@@ -1011,67 +1037,67 @@ class n {
|
|
|
1011
1037
|
};
|
|
1012
1038
|
}
|
|
1013
1039
|
static installExtendedAutocapture(t) {
|
|
1014
|
-
if (!
|
|
1040
|
+
if (!s.client || typeof document > "u") return;
|
|
1015
1041
|
const e = t.autocapture;
|
|
1016
1042
|
if (e) {
|
|
1017
1043
|
if (e.click && document.addEventListener("click", (i) => {
|
|
1018
|
-
const
|
|
1019
|
-
if (!
|
|
1020
|
-
const r = typeof e.click == "object" ? e.click.selector : void 0, o = r ?
|
|
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]");
|
|
1021
1047
|
if (!o) return;
|
|
1022
1048
|
const a = o.getAttribute("data-mark-event") || "click";
|
|
1023
|
-
|
|
1049
|
+
s.client?.track(a, {
|
|
1024
1050
|
element_id: o.id || void 0,
|
|
1025
1051
|
element_classes: o.className || void 0,
|
|
1026
1052
|
text: o.textContent?.trim().slice(0, 120) || void 0,
|
|
1027
1053
|
href: o.href || void 0
|
|
1028
1054
|
});
|
|
1029
1055
|
}), e.form_submit && document.addEventListener("submit", (i) => {
|
|
1030
|
-
const
|
|
1031
|
-
|
|
1032
|
-
form_id:
|
|
1033
|
-
form_name:
|
|
1034
|
-
action:
|
|
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
|
|
1035
1061
|
});
|
|
1036
1062
|
}), e.outbound_link && document.addEventListener("click", (i) => {
|
|
1037
|
-
const
|
|
1038
|
-
if (!(!
|
|
1063
|
+
const n = i.target?.closest("a[href]");
|
|
1064
|
+
if (!(!n || !n.href))
|
|
1039
1065
|
try {
|
|
1040
|
-
const r = new URL(
|
|
1041
|
-
r.origin !== o.origin &&
|
|
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 });
|
|
1042
1068
|
} catch {
|
|
1043
1069
|
}
|
|
1044
1070
|
}), e.scroll_depth) {
|
|
1045
|
-
const i = [25, 50, 75, 100],
|
|
1071
|
+
const i = [25, 50, 75, 100], n = /* @__PURE__ */ new Set();
|
|
1046
1072
|
window.addEventListener(
|
|
1047
1073
|
"scroll",
|
|
1048
1074
|
() => {
|
|
1049
|
-
const r = document.documentElement, o = window.scrollY || r.scrollTop, a = Math.max(1, r.scrollHeight - window.innerHeight),
|
|
1050
|
-
for (const
|
|
1051
|
-
|
|
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 }));
|
|
1052
1078
|
},
|
|
1053
1079
|
{ passive: !0 }
|
|
1054
1080
|
);
|
|
1055
1081
|
}
|
|
1056
1082
|
e.web_vitals && import("./web-vitals-CrnTllyu.js").then((i) => {
|
|
1057
|
-
const
|
|
1058
|
-
|
|
1083
|
+
const n = (r) => {
|
|
1084
|
+
s.client?.track("web_vital", {
|
|
1059
1085
|
metric: r.name,
|
|
1060
1086
|
value: r.value,
|
|
1061
1087
|
rating: r.rating,
|
|
1062
1088
|
metric_id: r.id
|
|
1063
1089
|
});
|
|
1064
1090
|
};
|
|
1065
|
-
i.onLCP(
|
|
1091
|
+
i.onLCP(n), i.onCLS(n), i.onINP(n), i.onTTFB(n);
|
|
1066
1092
|
}).catch(() => {
|
|
1067
1093
|
t.debug && console.warn("[Mark] web-vitals package not available; skipping autocapture.web_vitals.");
|
|
1068
1094
|
});
|
|
1069
1095
|
}
|
|
1070
1096
|
}
|
|
1071
1097
|
}
|
|
1072
|
-
typeof window < "u" && (window.Mark =
|
|
1098
|
+
typeof window < "u" && (window.Mark = s);
|
|
1073
1099
|
export {
|
|
1074
|
-
|
|
1075
|
-
|
|
1100
|
+
s as Mark,
|
|
1101
|
+
s as default
|
|
1076
1102
|
};
|
|
1077
1103
|
//# sourceMappingURL=browser.es.js.map
|