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