@crelora/mark 0.1.1 → 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/README.md +73 -1
- package/dist/browser.es.js +284 -192
- package/dist/browser.es.js.map +1 -1
- package/dist/browser.umd.js +1 -1
- package/dist/browser.umd.js.map +1 -1
- package/dist/node.cjs +1 -1
- package/dist/node.cjs.map +1 -1
- package/dist/node.es.js +65 -12
- package/dist/node.es.js.map +1 -1
- package/dist/types/browser/BrowserStorage.d.ts +2 -0
- package/dist/types/browser/Mark.d.ts +17 -1
- package/dist/types/browser/pageviewDedupeKey.d.ts +15 -0
- package/dist/types/core/MarkCore.d.ts +24 -0
- package/dist/types/core/adapters.d.ts +2 -0
- package/dist/types/node/StatelessStorage.d.ts +2 -0
- package/dist/types/node/index.d.ts +6 -0
- package/dist/types/types.d.ts +12 -0
- package/package.json +1 -1
package/dist/browser.es.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const I = "https://ingest.onelence.com";
|
|
2
2
|
class h extends Error {
|
|
3
3
|
status;
|
|
4
4
|
retryAfterMs;
|
|
@@ -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 D {
|
|
|
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 D {
|
|
|
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 D {
|
|
|
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",
|
|
@@ -159,14 +159,14 @@ const C = /* @__PURE__ */ new Set(["event_name", "user_id", "consent_state", "so
|
|
|
159
159
|
class L {
|
|
160
160
|
constructor(t, e) {
|
|
161
161
|
this.deps = e, this.validateConfig(t), this.config = {
|
|
162
|
-
endpoint: t.endpoint ??
|
|
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) {
|
|
@@ -234,9 +234,9 @@ class L {
|
|
|
234
234
|
...this.sanitizeIdentifyTraits(e),
|
|
235
235
|
...this.getIdentityFields()
|
|
236
236
|
};
|
|
237
|
-
this.siteId && (i.site_id = this.siteId), this.siteHost && (i.site_host = this.siteHost);
|
|
238
|
-
const
|
|
239
|
-
|
|
237
|
+
this.siteId && (i.site_id = this.siteId), this.siteHost && (i.site_host = this.siteHost), this.applyInternalFlag(i);
|
|
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);
|
|
@@ -253,16 +253,16 @@ class L {
|
|
|
253
253
|
}
|
|
254
254
|
setConsent(t) {
|
|
255
255
|
const e = this.deps.storage.getConsentStatus();
|
|
256
|
-
this.deps.storage.setConsentStatus(t), t === "denied" ? (this.deps.storage.clearAttribution?.(), this.deps.storage.clearCookieVisitorId?.()) : t === "granted" && e === "denied" && this.config.rotate_visitor_on_consent_change && this.deps.storage.rotateVisitorId?.();
|
|
256
|
+
this.deps.storage.setConsentStatus(t), t === "denied" ? (this.deps.storage.clearAttribution?.(), this.deps.storage.clearCookieVisitorId?.(), this.deps.storage.setInternal?.(!1)) : t === "granted" && e === "denied" && this.config.rotate_visitor_on_consent_change && this.deps.storage.rotateVisitorId?.();
|
|
257
257
|
const i = {
|
|
258
258
|
visitor_id: this.deps.storage.getVisitorId(),
|
|
259
259
|
consent_state: t,
|
|
260
260
|
source: "sdk",
|
|
261
261
|
message_id: this.createMessageId()
|
|
262
262
|
};
|
|
263
|
-
this.siteId && (i.site_id = this.siteId), this.siteHost && (i.site_host = this.siteHost);
|
|
264
|
-
const
|
|
265
|
-
|
|
263
|
+
this.siteId && (i.site_id = this.siteId), this.siteHost && (i.site_host = this.siteHost), this.applyInternalFlag(i);
|
|
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({
|
|
@@ -272,18 +272,54 @@ class L {
|
|
|
272
272
|
query_params: void 0,
|
|
273
273
|
session_id: void 0,
|
|
274
274
|
session_started_at: void 0,
|
|
275
|
-
last_activity_at: void 0
|
|
275
|
+
last_activity_at: void 0,
|
|
276
|
+
is_internal: void 0
|
|
276
277
|
}), this.deps.storage.rotateVisitorId?.();
|
|
277
278
|
}
|
|
279
|
+
/**
|
|
280
|
+
* Marks or unmarks the current visitor as internal traffic. While set, every
|
|
281
|
+
* subsequent event (track/identify/conversion/consent) is stamped with
|
|
282
|
+
* `is_internal: true`, so the backend can exclude it from customer-facing
|
|
283
|
+
* reports by default.
|
|
284
|
+
*
|
|
285
|
+
* The flag is persisted via the storage adapter (browser: localStorage) so
|
|
286
|
+
* it survives reloads, and is cleared by `reset()` and by
|
|
287
|
+
* `setConsent('denied')`.
|
|
288
|
+
*/
|
|
289
|
+
setInternal(t) {
|
|
290
|
+
this.deps.storage.setInternal?.(!!t);
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Returns the currently persisted internal-traffic flag, if any.
|
|
294
|
+
*/
|
|
295
|
+
getInternal() {
|
|
296
|
+
return !!this.deps.storage.getInternal?.();
|
|
297
|
+
}
|
|
278
298
|
flush() {
|
|
279
299
|
return this.flushBatch(), this.queue.flush();
|
|
280
300
|
}
|
|
281
301
|
getStats() {
|
|
282
302
|
return this.queue.getStats();
|
|
283
303
|
}
|
|
304
|
+
/**
|
|
305
|
+
* Stamps `is_internal: true` on the payload when either:
|
|
306
|
+
* - the persistent visitor flag is set (via setInternal), or
|
|
307
|
+
* - the caller passed `is_internal: true` on this specific event.
|
|
308
|
+
*
|
|
309
|
+
* Explicit `is_internal: false` on a single event wins over the visitor flag
|
|
310
|
+
* so individual calls can opt out.
|
|
311
|
+
*/
|
|
312
|
+
applyInternalFlag(t, e) {
|
|
313
|
+
if (e === !1) {
|
|
314
|
+
delete t.is_internal;
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
const i = this.deps.storage.getInternal?.() === !0;
|
|
318
|
+
e === !0 || i ? t.is_internal = !0 : delete t.is_internal;
|
|
319
|
+
}
|
|
284
320
|
getIdentityFields(t) {
|
|
285
|
-
const e = t?.visitor_id ?? this.deps.storage.getVisitorId(), i = t?.user_id ?? this.deps.storage.getUserId?.(),
|
|
286
|
-
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;
|
|
287
323
|
}
|
|
288
324
|
hasConsent() {
|
|
289
325
|
if (this.config.consent_source?.type === "tcf" && typeof window < "u" && !this.tcfCachedAllowed)
|
|
@@ -295,14 +331,14 @@ class L {
|
|
|
295
331
|
}
|
|
296
332
|
sanitizeTrackData(t) {
|
|
297
333
|
const e = {};
|
|
298
|
-
for (const [i,
|
|
299
|
-
|
|
334
|
+
for (const [i, n] of Object.entries(t))
|
|
335
|
+
k.has(i) || (e[i] = n);
|
|
300
336
|
return e;
|
|
301
337
|
}
|
|
302
338
|
sanitizeIdentifyTraits(t) {
|
|
303
339
|
const e = {};
|
|
304
|
-
for (const [i,
|
|
305
|
-
|
|
340
|
+
for (const [i, n] of Object.entries(t))
|
|
341
|
+
P.has(i) || (e[i] = n);
|
|
306
342
|
return e;
|
|
307
343
|
}
|
|
308
344
|
validateConfig(t) {
|
|
@@ -345,8 +381,8 @@ class L {
|
|
|
345
381
|
return typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : `msg_${Date.now()}_${Math.random().toString(16).slice(2)}`;
|
|
346
382
|
}
|
|
347
383
|
ensureSession() {
|
|
348
|
-
const t = Date.now(), e = this.deps.storage.getSessionId?.(), i = this.deps.storage.getLastActivityAt?.(),
|
|
349
|
-
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)) {
|
|
350
386
|
const o = this.createMessageId(), a = new Date(t).toISOString();
|
|
351
387
|
this.deps.storage.update({
|
|
352
388
|
session_id: o,
|
|
@@ -358,8 +394,8 @@ class L {
|
|
|
358
394
|
this.deps.storage.update({ last_activity_at: new Date(t).toISOString() });
|
|
359
395
|
}
|
|
360
396
|
crossedUtcDay(t, e) {
|
|
361
|
-
const i = new Date(t),
|
|
362
|
-
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();
|
|
363
399
|
}
|
|
364
400
|
shouldSampleTrack() {
|
|
365
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;
|
|
@@ -395,11 +431,11 @@ class L {
|
|
|
395
431
|
subscribeTcf() {
|
|
396
432
|
const t = this.config.consent_source;
|
|
397
433
|
if (t?.type !== "tcf" || typeof window > "u") return;
|
|
398
|
-
const e = t.purposes, i = (
|
|
434
|
+
const e = t.purposes, i = (n) => {
|
|
399
435
|
try {
|
|
400
436
|
const r = window;
|
|
401
437
|
if (typeof r.__tcfapi != "function") {
|
|
402
|
-
|
|
438
|
+
n > 0 && setTimeout(() => i(n - 1), 200);
|
|
403
439
|
return;
|
|
404
440
|
}
|
|
405
441
|
r.__tcfapi("addEventListener", 2, (o, a) => {
|
|
@@ -411,8 +447,8 @@ class L {
|
|
|
411
447
|
this.tcfCachedAllowed = !0;
|
|
412
448
|
return;
|
|
413
449
|
}
|
|
414
|
-
const
|
|
415
|
-
this.tcfCachedAllowed = e.every((
|
|
450
|
+
const u = o.purpose?.consents ?? {};
|
|
451
|
+
this.tcfCachedAllowed = e.every((l) => u[String(l)] === !0);
|
|
416
452
|
});
|
|
417
453
|
} catch {
|
|
418
454
|
this.tcfCachedAllowed = !1;
|
|
@@ -421,79 +457,79 @@ class L {
|
|
|
421
457
|
i(10);
|
|
422
458
|
}
|
|
423
459
|
}
|
|
424
|
-
class
|
|
460
|
+
class R {
|
|
425
461
|
config;
|
|
426
462
|
endpoint;
|
|
427
463
|
pending = /* @__PURE__ */ new Set();
|
|
428
464
|
constructor(t) {
|
|
429
|
-
this.config = t, this.endpoint = t.endpoint ??
|
|
465
|
+
this.config = t, this.endpoint = t.endpoint ?? I;
|
|
430
466
|
}
|
|
431
467
|
async send(t, e, i) {
|
|
432
|
-
const
|
|
433
|
-
this.pending.add(
|
|
468
|
+
const n = this.sendInternal(t, e, i);
|
|
469
|
+
this.pending.add(n);
|
|
434
470
|
try {
|
|
435
|
-
await
|
|
471
|
+
await n;
|
|
436
472
|
} finally {
|
|
437
|
-
this.pending.delete(
|
|
473
|
+
this.pending.delete(n);
|
|
438
474
|
}
|
|
439
475
|
}
|
|
440
476
|
async flush() {
|
|
441
477
|
this.pending.size !== 0 && await Promise.allSettled(Array.from(this.pending));
|
|
442
478
|
}
|
|
443
479
|
async sendInternal(t, e, i) {
|
|
444
|
-
const
|
|
480
|
+
const n = this.joinUrl(this.endpoint, t), r = this.config.key, o = {
|
|
445
481
|
"Content-Type": "application/json",
|
|
446
482
|
[r.startsWith("sk_") ? "x-secret-key" : "x-publishable-key"]: r
|
|
447
483
|
};
|
|
448
|
-
this.config.debug && console.log("[Mark] Sending",
|
|
484
|
+
this.config.debug && console.log("[Mark] Sending", n, e);
|
|
449
485
|
const a = JSON.stringify(e);
|
|
450
486
|
if (i?.preferBeacon && typeof navigator < "u" && typeof navigator.sendBeacon == "function") {
|
|
451
|
-
const
|
|
452
|
-
if (navigator.sendBeacon(
|
|
487
|
+
const f = new Blob([a], { type: "application/json" });
|
|
488
|
+
if (navigator.sendBeacon(n, f))
|
|
453
489
|
return;
|
|
454
490
|
}
|
|
455
491
|
if (typeof fetch != "function")
|
|
456
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.");
|
|
457
|
-
const
|
|
493
|
+
const u = this.config.request_timeout_ms ?? 1e4, l = new AbortController();
|
|
458
494
|
let d = !1;
|
|
459
495
|
const p = setTimeout(() => {
|
|
460
|
-
d = !0,
|
|
461
|
-
},
|
|
496
|
+
d = !0, l.abort();
|
|
497
|
+
}, u);
|
|
462
498
|
try {
|
|
463
|
-
const
|
|
499
|
+
const f = await fetch(n, {
|
|
464
500
|
method: "POST",
|
|
465
501
|
headers: o,
|
|
466
502
|
body: a,
|
|
467
503
|
keepalive: !0,
|
|
468
|
-
signal:
|
|
504
|
+
signal: l.signal
|
|
469
505
|
});
|
|
470
|
-
if (!
|
|
471
|
-
const g = await this.readErrorSnippet(
|
|
506
|
+
if (!f.ok) {
|
|
507
|
+
const g = await this.readErrorSnippet(f), w = x(f.headers.get("Retry-After"));
|
|
472
508
|
throw this.config.debug && console.error("[Mark] Request rejected", {
|
|
473
|
-
url:
|
|
474
|
-
status:
|
|
475
|
-
statusText:
|
|
509
|
+
url: n,
|
|
510
|
+
status: f.status,
|
|
511
|
+
statusText: f.statusText,
|
|
476
512
|
body: g,
|
|
477
|
-
retryAfterMs:
|
|
513
|
+
retryAfterMs: w
|
|
478
514
|
}), new h(
|
|
479
|
-
`[Mark] Request rejected with status ${
|
|
480
|
-
{ status:
|
|
515
|
+
`[Mark] Request rejected with status ${f.status}: ${g}`,
|
|
516
|
+
{ status: f.status, retryAfterMs: w }
|
|
481
517
|
);
|
|
482
518
|
}
|
|
483
|
-
} catch (
|
|
484
|
-
if (this.config.debug && console.error("[Mark] Failed to send",
|
|
485
|
-
throw
|
|
519
|
+
} catch (f) {
|
|
520
|
+
if (this.config.debug && console.error("[Mark] Failed to send", n, f), f instanceof h)
|
|
521
|
+
throw f;
|
|
486
522
|
if (d)
|
|
487
|
-
throw new h(`[Mark] Request timed out after ${
|
|
488
|
-
const g =
|
|
523
|
+
throw new h(`[Mark] Request timed out after ${u}ms`, { status: 408 });
|
|
524
|
+
const g = f instanceof Error ? f.message : String(f);
|
|
489
525
|
throw new h(`[Mark] Network error: ${g}`);
|
|
490
526
|
} finally {
|
|
491
527
|
clearTimeout(p);
|
|
492
528
|
}
|
|
493
529
|
}
|
|
494
530
|
joinUrl(t, e) {
|
|
495
|
-
const i = t.replace(/\/+$/, ""),
|
|
496
|
-
return `${i}/${
|
|
531
|
+
const i = t.replace(/\/+$/, ""), n = e.replace(/^\/+/, "");
|
|
532
|
+
return `${i}/${n}`;
|
|
497
533
|
}
|
|
498
534
|
async readErrorSnippet(t) {
|
|
499
535
|
try {
|
|
@@ -503,8 +539,8 @@ class P {
|
|
|
503
539
|
}
|
|
504
540
|
}
|
|
505
541
|
}
|
|
506
|
-
const
|
|
507
|
-
class
|
|
542
|
+
const B = "crelora_mark_data", F = "crelora_mark_outbox", y = "crelora_mark_vid";
|
|
543
|
+
class H {
|
|
508
544
|
data;
|
|
509
545
|
storageKey;
|
|
510
546
|
outboxKey;
|
|
@@ -513,7 +549,7 @@ class F {
|
|
|
513
549
|
bridgeReady = !1;
|
|
514
550
|
bridgeOrigin;
|
|
515
551
|
constructor(t) {
|
|
516
|
-
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") {
|
|
517
553
|
this.data = {};
|
|
518
554
|
return;
|
|
519
555
|
}
|
|
@@ -546,6 +582,12 @@ class F {
|
|
|
546
582
|
getLastActivityAt() {
|
|
547
583
|
return this.data.last_activity_at;
|
|
548
584
|
}
|
|
585
|
+
getInternal() {
|
|
586
|
+
return this.data.is_internal;
|
|
587
|
+
}
|
|
588
|
+
setInternal(t) {
|
|
589
|
+
t ? this.update({ is_internal: !0 }) : this.update({ is_internal: void 0 });
|
|
590
|
+
}
|
|
549
591
|
update(t) {
|
|
550
592
|
this.data = { ...this.data, ...t }, this.save();
|
|
551
593
|
}
|
|
@@ -560,7 +602,7 @@ class F {
|
|
|
560
602
|
});
|
|
561
603
|
}
|
|
562
604
|
clearCookieVisitorId() {
|
|
563
|
-
this.setCookie(
|
|
605
|
+
this.setCookie(y, "", -1);
|
|
564
606
|
}
|
|
565
607
|
rotateVisitorId() {
|
|
566
608
|
this.update({ visitor_id: this.generateUUID() });
|
|
@@ -592,7 +634,7 @@ class F {
|
|
|
592
634
|
return JSON.parse(e);
|
|
593
635
|
} catch {
|
|
594
636
|
}
|
|
595
|
-
const t = this.getCookie(
|
|
637
|
+
const t = this.getCookie(y);
|
|
596
638
|
return t ? { visitor_id: t } : {};
|
|
597
639
|
}
|
|
598
640
|
save() {
|
|
@@ -601,7 +643,7 @@ class F {
|
|
|
601
643
|
localStorage.setItem(this.storageKey, JSON.stringify(this.data));
|
|
602
644
|
} catch {
|
|
603
645
|
}
|
|
604
|
-
this.data.visitor_id && this.isCookieEnabled() && (this.setCookie(
|
|
646
|
+
this.data.visitor_id && this.isCookieEnabled() && (this.setCookie(y, this.data.visitor_id, 365), this.options.bridge?.url && this.bridgeReady && this.postBridgeMessage({
|
|
605
647
|
type: "MARK_SYNC_UPDATE",
|
|
606
648
|
visitorId: this.data.visitor_id
|
|
607
649
|
}));
|
|
@@ -620,8 +662,8 @@ class F {
|
|
|
620
662
|
setCookie(t, e, i) {
|
|
621
663
|
if (!(typeof document > "u"))
|
|
622
664
|
try {
|
|
623
|
-
const
|
|
624
|
-
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}`;
|
|
625
667
|
} catch {
|
|
626
668
|
}
|
|
627
669
|
}
|
|
@@ -651,7 +693,7 @@ class F {
|
|
|
651
693
|
return;
|
|
652
694
|
}
|
|
653
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();
|
|
654
|
-
const i = t.timeout_ms ?? 3e3,
|
|
696
|
+
const i = t.timeout_ms ?? 3e3, n = setTimeout(() => {
|
|
655
697
|
window.removeEventListener("message", this.handleBridgeMessage);
|
|
656
698
|
}, i);
|
|
657
699
|
window.addEventListener("message", this.handleBridgeMessage);
|
|
@@ -659,7 +701,7 @@ class F {
|
|
|
659
701
|
this.bridgeFrame && document.body && document.body.appendChild(this.bridgeFrame);
|
|
660
702
|
};
|
|
661
703
|
document.body ? r() : document.addEventListener("DOMContentLoaded", r, { once: !0 }), this.bridgeFrame.addEventListener("load", () => {
|
|
662
|
-
clearTimeout(
|
|
704
|
+
clearTimeout(n), this.bridgeReady = !0, this.postBridgeMessage({
|
|
663
705
|
type: "MARK_SYNC_REQUEST",
|
|
664
706
|
visitorId: this.data.visitor_id
|
|
665
707
|
});
|
|
@@ -679,7 +721,7 @@ class F {
|
|
|
679
721
|
const e = new URL(t);
|
|
680
722
|
if (this.options.allowed_domains?.length)
|
|
681
723
|
return this.options.allowed_domains.some(
|
|
682
|
-
(
|
|
724
|
+
(n) => e.hostname === n || e.hostname.endsWith(`.${n}`)
|
|
683
725
|
);
|
|
684
726
|
if (!this.bridgeOrigin)
|
|
685
727
|
return !1;
|
|
@@ -697,7 +739,7 @@ class F {
|
|
|
697
739
|
}
|
|
698
740
|
};
|
|
699
741
|
}
|
|
700
|
-
const
|
|
742
|
+
const O = [
|
|
701
743
|
"click_id",
|
|
702
744
|
"ch_click_id",
|
|
703
745
|
"gclid",
|
|
@@ -709,7 +751,7 @@ const H = [
|
|
|
709
751
|
"ttclid",
|
|
710
752
|
"twclid",
|
|
711
753
|
"li_fat_id"
|
|
712
|
-
],
|
|
754
|
+
], N = ["cid", "campaign_id"], K = [
|
|
713
755
|
"utm_source",
|
|
714
756
|
"utm_medium",
|
|
715
757
|
"utm_campaign",
|
|
@@ -731,55 +773,55 @@ const H = [
|
|
|
731
773
|
"ttclid",
|
|
732
774
|
"twclid",
|
|
733
775
|
"li_fat_id"
|
|
734
|
-
],
|
|
776
|
+
], z = {
|
|
735
777
|
referral: "ref",
|
|
736
778
|
affiliate_id: "ref",
|
|
737
779
|
ch_click_id: "click_id",
|
|
738
780
|
cid: "campaign_id"
|
|
739
|
-
},
|
|
781
|
+
}, $ = ["email", "phone", "token", "auth", "password", "code"], V = 30, j = 256;
|
|
740
782
|
function b(c, t = {}) {
|
|
741
|
-
const e = new URLSearchParams(c), i =
|
|
742
|
-
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;
|
|
743
785
|
}
|
|
744
|
-
function
|
|
745
|
-
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(
|
|
746
788
|
t.max_captured_query_params,
|
|
747
|
-
|
|
789
|
+
V
|
|
748
790
|
), r = A(
|
|
749
791
|
t.max_query_param_value_length,
|
|
750
|
-
|
|
792
|
+
j
|
|
751
793
|
), a = t.capture_all_query_params ?? !1 ? null : /* @__PURE__ */ new Set([
|
|
752
|
-
...
|
|
794
|
+
...K.map(m),
|
|
753
795
|
..._(t.capture_query_params, [])
|
|
754
796
|
]);
|
|
755
|
-
for (const [
|
|
756
|
-
const d = m(
|
|
797
|
+
for (const [u, l] of c.entries()) {
|
|
798
|
+
const d = m(u);
|
|
757
799
|
if (!d)
|
|
758
800
|
continue;
|
|
759
|
-
const p =
|
|
801
|
+
const p = z[d] ?? d;
|
|
760
802
|
if (i.has(d) || i.has(p) || a && !a.has(d))
|
|
761
803
|
continue;
|
|
762
|
-
const
|
|
763
|
-
if (
|
|
764
|
-
if (!(p in e) && Object.keys(e).length >=
|
|
804
|
+
const f = l.trim();
|
|
805
|
+
if (f) {
|
|
806
|
+
if (!(p in e) && Object.keys(e).length >= n)
|
|
765
807
|
break;
|
|
766
|
-
e[p] =
|
|
808
|
+
e[p] = f.slice(0, r);
|
|
767
809
|
}
|
|
768
810
|
}
|
|
769
811
|
return e;
|
|
770
812
|
}
|
|
771
813
|
function v(c, t) {
|
|
772
814
|
for (const e of t) {
|
|
773
|
-
const i = m(e),
|
|
774
|
-
if (
|
|
775
|
-
return
|
|
815
|
+
const i = m(e), n = c[i]?.trim();
|
|
816
|
+
if (n)
|
|
817
|
+
return n;
|
|
776
818
|
}
|
|
777
819
|
}
|
|
778
|
-
function
|
|
820
|
+
function Q(c) {
|
|
779
821
|
const t = {};
|
|
780
822
|
for (const [e, i] of c.entries()) {
|
|
781
|
-
const
|
|
782
|
-
!
|
|
823
|
+
const n = m(e);
|
|
824
|
+
!n || n in t || (t[n] = i);
|
|
783
825
|
}
|
|
784
826
|
return t;
|
|
785
827
|
}
|
|
@@ -788,9 +830,9 @@ function m(c) {
|
|
|
788
830
|
}
|
|
789
831
|
function _(c, t) {
|
|
790
832
|
const e = c ?? t, i = /* @__PURE__ */ new Set();
|
|
791
|
-
for (const
|
|
792
|
-
if (typeof
|
|
793
|
-
const r = m(
|
|
833
|
+
for (const n of e) {
|
|
834
|
+
if (typeof n != "string") continue;
|
|
835
|
+
const r = m(n);
|
|
794
836
|
r && i.add(r);
|
|
795
837
|
}
|
|
796
838
|
return Array.from(i);
|
|
@@ -801,12 +843,38 @@ function A(c, t) {
|
|
|
801
843
|
const e = Math.floor(c);
|
|
802
844
|
return e < 0 ? t : e;
|
|
803
845
|
}
|
|
804
|
-
|
|
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 {
|
|
805
873
|
static client = null;
|
|
806
874
|
static storage = null;
|
|
807
875
|
static config = null;
|
|
808
876
|
static pageviewTrackerInstalled = !1;
|
|
809
|
-
static
|
|
877
|
+
static lastPageviewDedupeKey = null;
|
|
810
878
|
static emitAutoPageview = null;
|
|
811
879
|
static pendingAttribution = {};
|
|
812
880
|
static originalPushState = null;
|
|
@@ -817,52 +885,52 @@ class n {
|
|
|
817
885
|
static onlineHandler = null;
|
|
818
886
|
static kickTimer = null;
|
|
819
887
|
static init(t) {
|
|
820
|
-
if (!
|
|
821
|
-
const e = new
|
|
822
|
-
|
|
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());
|
|
823
891
|
}
|
|
824
|
-
return
|
|
892
|
+
return s.client;
|
|
825
893
|
}
|
|
826
894
|
static installLifecycleFlushing() {
|
|
827
|
-
if (typeof window > "u" ||
|
|
895
|
+
if (typeof window > "u" || s.beaconDrainHandler) return;
|
|
828
896
|
const t = () => {
|
|
829
|
-
|
|
897
|
+
s.client?.drainViaBeacon();
|
|
830
898
|
}, e = () => {
|
|
831
899
|
typeof document < "u" && document.visibilityState === "hidden" && t();
|
|
832
900
|
}, i = () => {
|
|
833
|
-
|
|
901
|
+
s.client?.kickQueue();
|
|
834
902
|
};
|
|
835
|
-
|
|
836
|
-
|
|
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();
|
|
837
905
|
}, 3e4));
|
|
838
906
|
}
|
|
839
907
|
static track(t, e = {}) {
|
|
840
|
-
if (!
|
|
841
|
-
|
|
908
|
+
if (!s.client) {
|
|
909
|
+
s.config?.debug && console.warn("[Mark] Not initialized. Call init() first.");
|
|
842
910
|
return;
|
|
843
911
|
}
|
|
844
|
-
|
|
912
|
+
s.client.track(t, e);
|
|
845
913
|
}
|
|
846
914
|
static identify(t, e = {}) {
|
|
847
|
-
if (!
|
|
848
|
-
|
|
915
|
+
if (!s.client) {
|
|
916
|
+
s.config?.debug && console.warn("[Mark] Not initialized. Call init() first.");
|
|
849
917
|
return;
|
|
850
918
|
}
|
|
851
|
-
|
|
919
|
+
s.client.identify(t, e);
|
|
852
920
|
}
|
|
853
921
|
static conversion(t, e = {}) {
|
|
854
|
-
if (!
|
|
855
|
-
|
|
922
|
+
if (!s.client) {
|
|
923
|
+
s.config?.debug && console.warn("[Mark] Not initialized. Call init() first.");
|
|
856
924
|
return;
|
|
857
925
|
}
|
|
858
|
-
|
|
926
|
+
s.client.conversion(t, e);
|
|
859
927
|
}
|
|
860
928
|
static setConsent(t) {
|
|
861
|
-
if (!
|
|
862
|
-
|
|
929
|
+
if (!s.client) {
|
|
930
|
+
s.config?.debug && console.warn("[Mark] Not initialized. Call init() first.");
|
|
863
931
|
return;
|
|
864
932
|
}
|
|
865
|
-
|
|
933
|
+
s.client.setConsent(t), t === "granted" && (s.flushPendingAttribution(), s.emitAutoPageview?.());
|
|
866
934
|
}
|
|
867
935
|
/**
|
|
868
936
|
* Returns the current visitor ID when available.
|
|
@@ -871,65 +939,89 @@ class n {
|
|
|
871
939
|
* when you do not have an authenticated user ID.
|
|
872
940
|
*/
|
|
873
941
|
static getVisitorId() {
|
|
874
|
-
if (!(!
|
|
875
|
-
return
|
|
942
|
+
if (!(!s.client || !s.storage || !s.config || (s.config.require_consent ?? !1) && s.storage.getConsentStatus() !== "granted"))
|
|
943
|
+
return s.client.getVisitorId();
|
|
876
944
|
}
|
|
877
945
|
static flush() {
|
|
878
|
-
return
|
|
946
|
+
return s.client ? s.client.flush() : Promise.resolve();
|
|
947
|
+
}
|
|
948
|
+
/**
|
|
949
|
+
* Flags (or un-flags) the current visitor as internal traffic. Persists
|
|
950
|
+
* across reloads via the SDK's browser storage. Cleared by `reset()` and by
|
|
951
|
+
* `setConsent('denied')`.
|
|
952
|
+
*
|
|
953
|
+
* The policy for deciding *when* to call this (URL query parameter, auth
|
|
954
|
+
* role, IP, feature flag, etc.) is intentionally left to the host app.
|
|
955
|
+
*
|
|
956
|
+
* @example
|
|
957
|
+
* // URL-based opt-in: call once during app bootstrap, after Mark.init()
|
|
958
|
+
* const params = new URLSearchParams(window.location.search);
|
|
959
|
+
* if (params.get('onelence_internal') === '1') Mark.setInternal(true);
|
|
960
|
+
* if (params.get('onelence_internal') === '0') Mark.setInternal(false);
|
|
961
|
+
*/
|
|
962
|
+
static setInternal(t) {
|
|
963
|
+
if (!s.client) {
|
|
964
|
+
s.config?.debug && console.warn("[Mark] Not initialized. Call init() first.");
|
|
965
|
+
return;
|
|
966
|
+
}
|
|
967
|
+
s.client.setInternal(t);
|
|
968
|
+
}
|
|
969
|
+
static getInternal() {
|
|
970
|
+
return s.client?.getInternal() ?? !1;
|
|
879
971
|
}
|
|
880
972
|
static reset() {
|
|
881
|
-
|
|
973
|
+
s.client?.reset(), s.pendingAttribution = {}, s.lastPageviewDedupeKey = null;
|
|
882
974
|
}
|
|
883
975
|
static getStats() {
|
|
884
|
-
return
|
|
976
|
+
return s.client?.getStats() ?? { queued: 0, sent: 0, failed: 0, dropped: 0 };
|
|
885
977
|
}
|
|
886
978
|
static destroy() {
|
|
887
|
-
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);
|
|
888
980
|
}
|
|
889
981
|
static installPageviewTracking(t, e) {
|
|
890
|
-
if (
|
|
891
|
-
|
|
982
|
+
if (s.pageviewTrackerInstalled) return;
|
|
983
|
+
s.pageviewTrackerInstalled = !0;
|
|
892
984
|
const i = () => {
|
|
893
|
-
if (!
|
|
894
|
-
|
|
895
|
-
const a = window.location
|
|
896
|
-
if (a ===
|
|
897
|
-
|
|
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", {
|
|
898
990
|
site: window.location.host,
|
|
899
|
-
page: window.location.pathname,
|
|
991
|
+
page: S(window.location.pathname),
|
|
900
992
|
title: document.title,
|
|
901
993
|
referrer: document.referrer || void 0
|
|
902
|
-
}) && (
|
|
994
|
+
}) && (s.lastPageviewDedupeKey = a);
|
|
903
995
|
};
|
|
904
|
-
if (
|
|
996
|
+
if (s.emitAutoPageview = i, i(), !(t.track_route_changes ?? !0)) return;
|
|
905
997
|
const r = history.pushState, o = history.replaceState;
|
|
906
|
-
|
|
907
|
-
const
|
|
908
|
-
return i(),
|
|
998
|
+
s.originalPushState = r, s.originalReplaceState = o, history.pushState = function(...a) {
|
|
999
|
+
const u = r.apply(this, a);
|
|
1000
|
+
return i(), u;
|
|
909
1001
|
}, history.replaceState = function(...a) {
|
|
910
|
-
const
|
|
911
|
-
return i(),
|
|
912
|
-
},
|
|
1002
|
+
const u = o.apply(this, a);
|
|
1003
|
+
return i(), u;
|
|
1004
|
+
}, s.popstateHandler = i, window.addEventListener("popstate", i);
|
|
913
1005
|
}
|
|
914
1006
|
static refreshAttribution(t, e) {
|
|
915
1007
|
if (typeof window > "u")
|
|
916
1008
|
return;
|
|
917
1009
|
const i = b(window.location.search, e);
|
|
918
1010
|
if (Object.keys(i).length !== 0) {
|
|
919
|
-
if (
|
|
920
|
-
const
|
|
921
|
-
t.update(
|
|
1011
|
+
if (s.shouldPersistAttribution(t, e)) {
|
|
1012
|
+
const n = s.mergeAttributionUpdates(s.pendingAttribution, i);
|
|
1013
|
+
t.update(n), s.pendingAttribution = {};
|
|
922
1014
|
return;
|
|
923
1015
|
}
|
|
924
|
-
|
|
1016
|
+
s.pendingAttribution = s.mergeAttributionUpdates(s.pendingAttribution, i);
|
|
925
1017
|
}
|
|
926
1018
|
}
|
|
927
1019
|
static flushPendingAttribution() {
|
|
928
|
-
const t =
|
|
1020
|
+
const t = s.storage, e = s.config;
|
|
929
1021
|
if (!t || !e || typeof window > "u")
|
|
930
1022
|
return;
|
|
931
|
-
const i = b(window.location.search, e),
|
|
932
|
-
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 = {};
|
|
933
1025
|
}
|
|
934
1026
|
static shouldPersistAttribution(t, e) {
|
|
935
1027
|
return e.require_consent ?? !1 ? t.getConsentStatus() === "granted" : !0;
|
|
@@ -945,67 +1037,67 @@ class n {
|
|
|
945
1037
|
};
|
|
946
1038
|
}
|
|
947
1039
|
static installExtendedAutocapture(t) {
|
|
948
|
-
if (!
|
|
1040
|
+
if (!s.client || typeof document > "u") return;
|
|
949
1041
|
const e = t.autocapture;
|
|
950
1042
|
if (e) {
|
|
951
1043
|
if (e.click && document.addEventListener("click", (i) => {
|
|
952
|
-
const
|
|
953
|
-
if (!
|
|
954
|
-
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]");
|
|
955
1047
|
if (!o) return;
|
|
956
1048
|
const a = o.getAttribute("data-mark-event") || "click";
|
|
957
|
-
|
|
1049
|
+
s.client?.track(a, {
|
|
958
1050
|
element_id: o.id || void 0,
|
|
959
1051
|
element_classes: o.className || void 0,
|
|
960
1052
|
text: o.textContent?.trim().slice(0, 120) || void 0,
|
|
961
1053
|
href: o.href || void 0
|
|
962
1054
|
});
|
|
963
1055
|
}), e.form_submit && document.addEventListener("submit", (i) => {
|
|
964
|
-
const
|
|
965
|
-
|
|
966
|
-
form_id:
|
|
967
|
-
form_name:
|
|
968
|
-
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
|
|
969
1061
|
});
|
|
970
1062
|
}), e.outbound_link && document.addEventListener("click", (i) => {
|
|
971
|
-
const
|
|
972
|
-
if (!(!
|
|
1063
|
+
const n = i.target?.closest("a[href]");
|
|
1064
|
+
if (!(!n || !n.href))
|
|
973
1065
|
try {
|
|
974
|
-
const r = new URL(
|
|
975
|
-
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 });
|
|
976
1068
|
} catch {
|
|
977
1069
|
}
|
|
978
1070
|
}), e.scroll_depth) {
|
|
979
|
-
const i = [25, 50, 75, 100],
|
|
1071
|
+
const i = [25, 50, 75, 100], n = /* @__PURE__ */ new Set();
|
|
980
1072
|
window.addEventListener(
|
|
981
1073
|
"scroll",
|
|
982
1074
|
() => {
|
|
983
|
-
const r = document.documentElement, o = window.scrollY || r.scrollTop, a = Math.max(1, r.scrollHeight - window.innerHeight),
|
|
984
|
-
for (const
|
|
985
|
-
|
|
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 }));
|
|
986
1078
|
},
|
|
987
1079
|
{ passive: !0 }
|
|
988
1080
|
);
|
|
989
1081
|
}
|
|
990
1082
|
e.web_vitals && import("./web-vitals-CrnTllyu.js").then((i) => {
|
|
991
|
-
const
|
|
992
|
-
|
|
1083
|
+
const n = (r) => {
|
|
1084
|
+
s.client?.track("web_vital", {
|
|
993
1085
|
metric: r.name,
|
|
994
1086
|
value: r.value,
|
|
995
1087
|
rating: r.rating,
|
|
996
1088
|
metric_id: r.id
|
|
997
1089
|
});
|
|
998
1090
|
};
|
|
999
|
-
i.onLCP(
|
|
1091
|
+
i.onLCP(n), i.onCLS(n), i.onINP(n), i.onTTFB(n);
|
|
1000
1092
|
}).catch(() => {
|
|
1001
1093
|
t.debug && console.warn("[Mark] web-vitals package not available; skipping autocapture.web_vitals.");
|
|
1002
1094
|
});
|
|
1003
1095
|
}
|
|
1004
1096
|
}
|
|
1005
1097
|
}
|
|
1006
|
-
typeof window < "u" && (window.Mark =
|
|
1098
|
+
typeof window < "u" && (window.Mark = s);
|
|
1007
1099
|
export {
|
|
1008
|
-
|
|
1009
|
-
|
|
1100
|
+
s as Mark,
|
|
1101
|
+
s as default
|
|
1010
1102
|
};
|
|
1011
1103
|
//# sourceMappingURL=browser.es.js.map
|