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