@usermaven/nextjs 1.4.1-rc.58 → 1.4.1-rc.59

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.
@@ -0,0 +1,1620 @@
1
+ import * as React from 'react';
2
+ import { createContext, useContext, useCallback, useEffect, useState } from 'react';
3
+
4
+ const UsermavenContext = createContext(null);
5
+
6
+ const UsermavenProvider = function ({ children, client }) {
7
+ const Context = UsermavenContext;
8
+ return React.createElement(Context.Provider, { value: client }, children);
9
+ };
10
+
11
+ var v = /* @__PURE__ */ ((s) => (s[s.DEBUG = 0] = "DEBUG", s[s.INFO = 1] = "INFO", s[s.WARN = 2] = "WARN", s[s.ERROR = 3] = "ERROR", s))(v || {});
12
+ class J {
13
+ constructor(e) {
14
+ this.level = e;
15
+ }
16
+ debug(e, ...t) {
17
+ this.level <= 0 && console.debug("[Usermaven Debug]:", e, ...t);
18
+ }
19
+ info(e, ...t) {
20
+ this.level <= 1 && console.info("[Usermaven Info]:", e, ...t);
21
+ }
22
+ warn(e, ...t) {
23
+ this.level <= 2 && console.warn("[Usermaven Warning]:", e, ...t);
24
+ }
25
+ error(e, ...t) {
26
+ this.level <= 3 && console.error("[Usermaven Error]:", e, ...t);
27
+ }
28
+ }
29
+ function h(s = 0) {
30
+ return new J(s);
31
+ }
32
+ const I = {
33
+ logLevel: v.ERROR,
34
+ useBeaconApi: !1,
35
+ forceUseFetch: !1,
36
+ trackingHost: "t.usermaven.com",
37
+ autocapture: !1,
38
+ rageClick: !1,
39
+ formTracking: !1,
40
+ autoPageview: !1,
41
+ disableEventPersistence: !1,
42
+ gaHook: !1,
43
+ segmentHook: !1,
44
+ randomizeUrl: !1,
45
+ capture3rdPartyCookies: ["_ga", "_fbp", "_ym_uid", "ajs_user_id", "ajs_anonymous_id"],
46
+ idMethod: "cookie",
47
+ ipPolicy: "keep",
48
+ cookiePolicy: "keep",
49
+ minSendTimeout: 0,
50
+ maxSendTimeout: 2e3,
51
+ maxSendAttempts: 4,
52
+ propertiesStringMaxLength: null,
53
+ propertyBlacklist: [],
54
+ crossDomainLinking: !0,
55
+ maskAllText: !1,
56
+ maskAllElementAttributes: !1
57
+ };
58
+ class Q {
59
+ constructor(e) {
60
+ this.domain = e, this.cookieDomain = this.getCookieDomain(), console.log(this.cookieDomain);
61
+ }
62
+ set(e, t, i = 365, n = !0, r = !1) {
63
+ console.log("Setting cookie", e, t, i, n, r);
64
+ const o = /* @__PURE__ */ new Date();
65
+ o.setTime(o.getTime() + i * 24 * 60 * 60 * 1e3);
66
+ const c = `expires=${o.toUTCString()}`, l = n ? "; Secure" : "", a = r ? "; HttpOnly" : "";
67
+ document.cookie = `${e}=${t};${c};path=/;domain=${this.cookieDomain}${l}${a}`;
68
+ }
69
+ get(e) {
70
+ const t = e + "=", i = document.cookie.split(";");
71
+ for (let n = 0; n < i.length; n++) {
72
+ let r = i[n].trim();
73
+ if (r.indexOf(t) === 0)
74
+ return decodeURIComponent(r.substring(t.length));
75
+ }
76
+ return null;
77
+ }
78
+ delete(e, t = "/") {
79
+ document.cookie = `${e}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${t};domain=${this.cookieDomain}`;
80
+ }
81
+ getCookieDomain() {
82
+ return typeof window > "u" || this.domain ? this.domain || "" : this.extractRoot(window.location.hostname);
83
+ }
84
+ extractRoot(e) {
85
+ if (this.isIpAddress(e) || e === "localhost")
86
+ return e;
87
+ let t = this.extractTopLevelDomain(e);
88
+ return t || (t = this.extractRootDomain(e)), "." + t;
89
+ }
90
+ isIpAddress(e) {
91
+ const t = e.split(".");
92
+ return t.length === 4 && t.every((i) => !isNaN(Number(i)));
93
+ }
94
+ extractHostname(e) {
95
+ let t;
96
+ return e.indexOf("//") > -1 ? t = e.split("/")[2] : t = e.split("/")[0], t = t.split(":")[0], t = t.split("?")[0], t;
97
+ }
98
+ extractRootDomain(e) {
99
+ let t = this.extractHostname(e);
100
+ const i = t.split("."), n = i.length;
101
+ return n > 2 && (i[n - 1].length == 2 ? (t = i[n - 2] + "." + i[n - 1], i[n - 2].length == 2 && (t = i[n - 3] + "." + t)) : t = i[n - 2] + "." + i[n - 1]), t;
102
+ }
103
+ extractTopLevelDomain(e) {
104
+ const t = /[a-z0-9][a-z0-9-]+\.[a-z.]{2,6}$/i, i = e.match(t);
105
+ return i ? i[0] : "";
106
+ }
107
+ }
108
+ const W = Object.prototype, X = W.hasOwnProperty, K = Array.prototype, b = K.forEach, $ = {};
109
+ function Z(s, e, t) {
110
+ if (Array.isArray(s)) {
111
+ if (b && s.forEach === b)
112
+ s.forEach(e, t);
113
+ else if ("length" in s && s.length === +s.length) {
114
+ for (let i = 0, n = s.length; i < n; i++)
115
+ if (i in s && e.call(t, s[i], i) === $)
116
+ return;
117
+ }
118
+ }
119
+ }
120
+ const T = function(s) {
121
+ return s.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, "");
122
+ }, G = function(s) {
123
+ for (const e in s)
124
+ typeof s[e] == "function" && (s[e] = s[e].bind(s));
125
+ };
126
+ function A(s, e, t) {
127
+ if (s != null) {
128
+ if (b && Array.isArray(s) && s.forEach === b)
129
+ s.forEach(e, t);
130
+ else if ("length" in s && s.length === +s.length) {
131
+ for (let i = 0, n = s.length; i < n; i++)
132
+ if (i in s && e.call(t, s[i], i) === $)
133
+ return;
134
+ } else
135
+ for (const i in s)
136
+ if (X.call(s, i) && e.call(t, s[i], i) === $)
137
+ return;
138
+ }
139
+ }
140
+ const Y = function(s, ...e) {
141
+ return Z(e, function(t) {
142
+ for (const i in t)
143
+ t[i] !== void 0 && (s[i] = t[i]);
144
+ }), s;
145
+ };
146
+ function _(s, e) {
147
+ return s.indexOf(e) !== -1;
148
+ }
149
+ const D = function(s) {
150
+ try {
151
+ return /^\s*\bfunction\b/.test(s);
152
+ } catch {
153
+ return !1;
154
+ }
155
+ }, j = function(s) {
156
+ return s === void 0;
157
+ }, p = function() {
158
+ const s = function(i, n, r, o, c) {
159
+ if (!i) {
160
+ h().error("No valid element provided to register_event");
161
+ return;
162
+ }
163
+ if (i.addEventListener && !o)
164
+ i.addEventListener(n, r, !!c);
165
+ else {
166
+ const l = "on" + n, a = i[l];
167
+ i[l] = e(i, r, a);
168
+ }
169
+ };
170
+ function e(i, n, r) {
171
+ return function(o) {
172
+ if (o = o || t(window.event), !o)
173
+ return;
174
+ let c = !0, l;
175
+ D(r) && (l = r(o));
176
+ const a = n.call(i, o);
177
+ return (l === !1 || a === !1) && (c = !1), c;
178
+ };
179
+ }
180
+ function t(i) {
181
+ return i && (i.preventDefault = t.preventDefault, i.stopPropagation = t.stopPropagation), i;
182
+ }
183
+ return t.preventDefault = function() {
184
+ this.returnValue = !1;
185
+ }, t.stopPropagation = function() {
186
+ this.cancelBubble = !0;
187
+ }, s;
188
+ }(), ee = function(s) {
189
+ return function(...e) {
190
+ try {
191
+ return s.apply(this, e);
192
+ } catch (t) {
193
+ h().error("Implementation error. Please turn on debug and contact support@usermaven.com.", t);
194
+ }
195
+ };
196
+ }, F = function(s) {
197
+ for (const e in s)
198
+ typeof s[e] == "function" && (s[e] = ee(s[e]));
199
+ };
200
+ function R(s) {
201
+ for (let e in s)
202
+ (s[e] === "" || s[e] === null || s[e] === void 0 || typeof s[e] == "object" && Object.keys(s[e]).length === 0) && delete s[e];
203
+ return s;
204
+ }
205
+ function u() {
206
+ try {
207
+ return typeof window < "u" && window.document !== void 0 && window.document.createElement !== void 0;
208
+ } catch {
209
+ return h().warn("window is not available"), !1;
210
+ }
211
+ }
212
+ function f(s = 5) {
213
+ const e = new Uint8Array(s);
214
+ return crypto.getRandomValues(e), Array.from(e, (t) => t.toString(36).padStart(2, "0")).join("").slice(0, s);
215
+ }
216
+ function te(s) {
217
+ return s.replace(
218
+ /([-_][a-z])/g,
219
+ (e) => e.toUpperCase().replace("-", "").replace("_", "")
220
+ );
221
+ }
222
+ function S(s) {
223
+ return typeof s != "object" || s === null ? s : Array.isArray(s) ? s.map(S) : Object.keys(s).reduce((e, t) => {
224
+ const i = te(t);
225
+ return e[i] = S(s[t]), e;
226
+ }, {});
227
+ }
228
+ function E(s) {
229
+ switch (typeof s.className) {
230
+ case "string":
231
+ return s.className;
232
+ case "object":
233
+ return ("baseVal" in s.className ? s.className.baseVal : null) || s.getAttribute("class") || "";
234
+ default:
235
+ return "";
236
+ }
237
+ }
238
+ function N(s) {
239
+ let e = "";
240
+ return M(s) && !q(s) && s.childNodes && s.childNodes.length && A(s.childNodes, function(t) {
241
+ z(t) && t.textContent && (e += T(t.textContent).split(/(\s+)/).filter(x).join("").replace(/[\r\n]/g, " ").replace(/[ ]+/g, " ").substring(0, 255));
242
+ }), T(e);
243
+ }
244
+ function H(s) {
245
+ return !!s && s.nodeType === 1;
246
+ }
247
+ function d(s, e) {
248
+ return !!s && !!s.tagName && s.tagName.toLowerCase() === e.toLowerCase();
249
+ }
250
+ function z(s) {
251
+ return !!s && s.nodeType === 3;
252
+ }
253
+ function B(s) {
254
+ return !!s && s.nodeType === 11;
255
+ }
256
+ const C = ["a", "button", "form", "input", "select", "textarea", "label"];
257
+ function ie(s, e) {
258
+ if (!s || d(s, "html") || !H(s) || s.classList && s.classList.contains("um-no-capture"))
259
+ return !1;
260
+ let t = !1;
261
+ const i = [s];
262
+ let n = !0, r = s;
263
+ for (; r.parentNode && !d(r, "body"); ) {
264
+ if (B(r.parentNode)) {
265
+ i.push(r.parentNode.host), r = r.parentNode.host;
266
+ continue;
267
+ }
268
+ if (n = r.parentNode || !1, !n) break;
269
+ if (C.indexOf(n.tagName.toLowerCase()) > -1)
270
+ t = !0;
271
+ else {
272
+ const l = window.getComputedStyle(n);
273
+ l && l.getPropertyValue("cursor") === "pointer" && (t = !0);
274
+ }
275
+ i.push(n), r = n;
276
+ }
277
+ const o = window.getComputedStyle(s);
278
+ if (o && o.getPropertyValue("cursor") === "pointer" && e.type === "click")
279
+ return !0;
280
+ const c = s.tagName.toLowerCase();
281
+ switch (c) {
282
+ case "html":
283
+ return !1;
284
+ case "form":
285
+ return e.type === "submit";
286
+ case "input":
287
+ return e.type === "change" || e.type === "click";
288
+ case "select":
289
+ case "textarea":
290
+ return e.type === "change" || e.type === "click";
291
+ default:
292
+ return t ? e.type === "click" : e.type === "click" && (C.indexOf(c) > -1 || s.getAttribute("contenteditable") === "true");
293
+ }
294
+ }
295
+ function M(s) {
296
+ if (!s || !H(s))
297
+ return !1;
298
+ if (typeof s.hasAttribute == "function") {
299
+ if (s.hasAttribute(w.FORCE_CAPTURE_ATTR))
300
+ return !0;
301
+ if (s.hasAttribute(w.PREVENT_CAPTURE_ATTR))
302
+ return !1;
303
+ }
304
+ let e = s;
305
+ for (; e && e.parentElement && !d(e, "body"); ) {
306
+ const n = E(e).split(" ");
307
+ if (_(n, "ph-sensitive") || _(n, "ph-no-capture"))
308
+ return !1;
309
+ e = e.parentElement;
310
+ }
311
+ if (_(E(s).split(" "), "ph-include"))
312
+ return !0;
313
+ const t = s.type;
314
+ if (typeof t == "string")
315
+ switch (t.toLowerCase()) {
316
+ case "hidden":
317
+ case "password":
318
+ return !1;
319
+ }
320
+ const i = s.name || s.id || "";
321
+ return !(typeof i == "string" && /^cc|cardnum|ccnum|creditcard|csc|cvc|cvv|exp|pass|pwd|routing|seccode|securitycode|securitynum|socialsec|socsec|ssn/i.test(i.replace(/[^a-zA-Z0-9]/g, "")));
322
+ }
323
+ function q(s) {
324
+ const e = ["button", "checkbox", "submit", "reset"];
325
+ return !!(d(s, "input") && !e.includes(s.type) || d(s, "select") || d(s, "textarea") || s.getAttribute("contenteditable") === "true");
326
+ }
327
+ function x(s) {
328
+ return !(s === null || j(s) || typeof s == "string" && (s = T(s), /^(?:(4[0-9]{12}(?:[0-9]{3})?)|(5[1-5][0-9]{14})|(6(?:011|5[0-9]{2})[0-9]{12})|(3[47][0-9]{13})|(3(?:0[0-5]|[68][0-9])[0-9]{11})|((?:2131|1800|35[0-9]{3})[0-9]{11}))$/.test((s || "").replace(/[- ]/g, "")) || /(^\d{3}-?\d{2}-?\d{4}$)/.test(s)));
329
+ }
330
+ function se(s) {
331
+ return typeof s == "string" ? s.substring(0, 10) === "_ngcontent" || s.substring(0, 7) === "_nghost" : !1;
332
+ }
333
+ function P() {
334
+ return f(10);
335
+ }
336
+ function ne(s) {
337
+ return /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(String(s).toLowerCase());
338
+ }
339
+ function re(s, e) {
340
+ let t;
341
+ return function(...i) {
342
+ const n = () => {
343
+ clearTimeout(t), s(...i);
344
+ };
345
+ clearTimeout(t), t = setTimeout(n, e);
346
+ };
347
+ }
348
+ function oe(s) {
349
+ const e = {}, t = s.replace(/^\?/, "").split("&");
350
+ for (let i = 0; i < t.length; i++) {
351
+ const n = t[i].split("=");
352
+ n[0] !== "" && (e[decodeURIComponent(n[0])] = decodeURIComponent(n[1] || ""));
353
+ }
354
+ return e;
355
+ }
356
+ function O(s) {
357
+ return typeof s == "string" || s instanceof String;
358
+ }
359
+ function k(s) {
360
+ return s !== null && typeof s == "object" && s.constructor === Object;
361
+ }
362
+ function ae(s) {
363
+ if (s === null)
364
+ return v.ERROR;
365
+ const e = s.toUpperCase(), t = v[e];
366
+ return t || t === 0 ? t : v.ERROR;
367
+ }
368
+ class ce {
369
+ constructor(e) {
370
+ this.maxScrollDepth = 0, this.milestones = [25, 50, 75, 90], this.lastScrollDepth = 0, this.client = e, this.documentElement = document.documentElement, this.debouncedHandleScroll = re(this.handleScroll.bind(this), 250), this.initializeEventListener();
371
+ }
372
+ initializeEventListener() {
373
+ window.addEventListener("scroll", this.debouncedHandleScroll);
374
+ }
375
+ track() {
376
+ const e = this.getScrollDepth();
377
+ e > this.lastScrollDepth && (this.lastScrollDepth = e, this.checkMilestones(e));
378
+ }
379
+ send(e = "$scroll") {
380
+ const t = {
381
+ percent: this.lastScrollDepth,
382
+ window_height: this.getWindowHeight(),
383
+ document_height: this.getDocumentHeight(),
384
+ scroll_distance: this.getScrollDistance()
385
+ };
386
+ this.client.track(e, t);
387
+ }
388
+ handleScroll() {
389
+ this.track();
390
+ }
391
+ getScrollDepth() {
392
+ const e = this.getWindowHeight(), t = this.getDocumentHeight(), i = this.getScrollDistance(), n = t - e;
393
+ return Math.min(100, Math.floor(i / n * 100));
394
+ }
395
+ getWindowHeight() {
396
+ return window.innerHeight || this.documentElement.clientHeight || document.body.clientHeight || 0;
397
+ }
398
+ getDocumentHeight() {
399
+ return Math.max(
400
+ document.body.scrollHeight || 0,
401
+ this.documentElement.scrollHeight || 0,
402
+ document.body.offsetHeight || 0,
403
+ this.documentElement.offsetHeight || 0,
404
+ document.body.clientHeight || 0,
405
+ this.documentElement.clientHeight || 0
406
+ );
407
+ }
408
+ getScrollDistance() {
409
+ return window.pageYOffset || this.documentElement.scrollTop || document.body.scrollTop || 0;
410
+ }
411
+ checkMilestones(e) {
412
+ this.milestones.filter((i) => e >= i).forEach((i) => {
413
+ this.send(), this.milestones = this.milestones.filter((n) => n !== i);
414
+ });
415
+ }
416
+ }
417
+ const y = class y {
418
+ constructor(e, t, i = h()) {
419
+ this.logger = i, this.scrollDepth = null, this.client = e, this.options = t, this.scrollDepth = new ce(e), G(this), F(this);
420
+ }
421
+ init() {
422
+ if (!(document && document.body)) {
423
+ this.logger.debug("Document not ready yet, trying again in 500 milliseconds..."), setTimeout(() => this.init(), 500);
424
+ return;
425
+ }
426
+ this.addDomEventHandlers();
427
+ }
428
+ addDomEventHandlers() {
429
+ const e = (t) => {
430
+ t = t || window.event, this.captureEvent(t);
431
+ };
432
+ p(document, "submit", e, !1, !0), p(document, "change", e, !1, !0), p(document, "click", e, !1, !0), p(document, "visibilitychange", e, !1, !0), p(document, "scroll", e, !1, !0), p(window, "popstate", e, !1, !0);
433
+ }
434
+ isPageRefresh() {
435
+ if ("PerformanceNavigationTiming" in window) {
436
+ const e = performance.getEntriesByType("navigation");
437
+ if (e.length > 0)
438
+ return e[0].type === "reload";
439
+ }
440
+ return performance.navigation && performance.navigation.type === 1;
441
+ }
442
+ captureEvent(e) {
443
+ var i, n;
444
+ let t = this.getEventTarget(e);
445
+ if (z(t) && (t = t.parentNode || null), e.type === "scroll")
446
+ return (i = this.scrollDepth) == null || i.track(), !0;
447
+ if (e.type === "visibilitychange" && document.visibilityState === "hidden" || e.type === "popstate")
448
+ return this.isPageRefresh() || (n = this.scrollDepth) == null || n.send(), !0;
449
+ if (t && this.shouldCaptureElement(t, e)) {
450
+ const r = this.getElementList(t), o = this.getElementsJson(r, e), c = Y(
451
+ this.getDefaultProperties(e.type),
452
+ {
453
+ $elements: o
454
+ }
455
+ );
456
+ return this.client.track("$autocapture", c), !0;
457
+ }
458
+ }
459
+ shouldCaptureElement(e, t) {
460
+ return !e || typeof e.hasAttribute != "function" ? !1 : e.hasAttribute(y.FORCE_CAPTURE_ATTR) ? !0 : e.hasAttribute(y.PREVENT_CAPTURE_ATTR) ? !1 : ie(e, t);
461
+ }
462
+ getEventTarget(e) {
463
+ var t;
464
+ return typeof e.target > "u" ? e.srcElement || null : (t = e.target) != null && t.shadowRoot ? e.composedPath()[0] || null : e.target || null;
465
+ }
466
+ getElementList(e) {
467
+ const t = [e];
468
+ let i = e;
469
+ for (; i.parentNode && !d(i, "body"); )
470
+ B(i.parentNode) ? (t.push(i.parentNode.host), i = i.parentNode.host) : (t.push(i.parentNode), i = i.parentNode);
471
+ return t;
472
+ }
473
+ getElementsJson(e, t) {
474
+ const i = [];
475
+ let n = null, r = !1;
476
+ return A(e, (o) => {
477
+ if (d(o, "a")) {
478
+ const l = o.getAttribute("href");
479
+ l !== null && M(o) && x(l) && (n = l);
480
+ }
481
+ const c = E(o).split(" ");
482
+ _(c, "ph-no-capture") && (r = !0), i.push(this.getPropertiesFromElement(o));
483
+ }), this.options.maskAllText || (i[0].$el_text = this.sanitizeText(N(e[0]))), n !== null && (i[0].attr__href = n), r ? [] : i;
484
+ }
485
+ getPropertiesFromElement(e) {
486
+ const t = {
487
+ tag_name: e.tagName.toLowerCase()
488
+ };
489
+ C.indexOf(t.tag_name) > -1 && !this.options.maskAllText && (t.$el_text = this.sanitizeText(N(e)));
490
+ const i = E(e);
491
+ i.length > 0 && (t.classes = i.split(" ").filter((c) => c !== "")), A(e.attributes, (c) => {
492
+ q(e) && ["name", "id", "class"].indexOf(c.name) === -1 || !this.options.maskAllElementAttributes && x(c.value) && !se(c.name) && (t["attr__" + c.name] = this.sanitizeAttributeValue(c.name, c.value));
493
+ });
494
+ let n = 1, r = 1, o = e;
495
+ for (; o = this.previousElementSibling(o); )
496
+ n++, o.tagName === e.tagName && r++;
497
+ return t.nth_child = n, t.nth_of_type = r, t;
498
+ }
499
+ previousElementSibling(e) {
500
+ if (e.previousElementSibling)
501
+ return e.previousElementSibling;
502
+ do
503
+ e = e.previousSibling;
504
+ while (e && !H(e));
505
+ return e;
506
+ }
507
+ getDefaultProperties(e) {
508
+ return {
509
+ $event_type: e,
510
+ $ce_version: 1
511
+ };
512
+ }
513
+ // Input sanitization and XSS prevention methods
514
+ sanitizeText(e) {
515
+ e = e.replace(/<[^>]*?>/g, ""), e = this.encodeHtml(e);
516
+ const t = this.options.propertiesStringMaxLength || 255;
517
+ return e.length > t && (e = e.substring(0, t) + "..."), e;
518
+ }
519
+ sanitizeUrl(e) {
520
+ if (!e) return "";
521
+ try {
522
+ const t = new URL(e, window.location.href);
523
+ return t.protocol !== "http:" && t.protocol !== "https:" ? "" : encodeURI(t.toString());
524
+ } catch {
525
+ return this.encodeHtml(e);
526
+ }
527
+ }
528
+ sanitizeAttributeValue(e, t) {
529
+ switch (e.toLowerCase()) {
530
+ case "href":
531
+ case "src":
532
+ return this.sanitizeUrl(t);
533
+ default:
534
+ return this.encodeHtml(t);
535
+ }
536
+ }
537
+ encodeHtml(e) {
538
+ return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
539
+ }
540
+ static enabledForProject(e, t = 10, i = 10) {
541
+ if (!e)
542
+ return !1;
543
+ let n = 0;
544
+ for (let r = 0; r < e.length; r++)
545
+ n += e.charCodeAt(r);
546
+ return n % t < i;
547
+ }
548
+ static isBrowserSupported() {
549
+ return D(document.querySelectorAll);
550
+ }
551
+ };
552
+ y.FORCE_CAPTURE_ATTR = "data-um-force-capture", y.PREVENT_CAPTURE_ATTR = "data-um-no-capture";
553
+ let w = y;
554
+ class le {
555
+ constructor(e) {
556
+ this.client = e, this.lastPageUrl = window.location.href, this.trackInitialPageview(), this.initializePageviewTracking();
557
+ }
558
+ trackInitialPageview() {
559
+ this.trackPageview();
560
+ }
561
+ initializePageviewTracking() {
562
+ window.addEventListener("popstate", this.handlePageview.bind(this));
563
+ const e = history.pushState;
564
+ history.pushState = (...t) => {
565
+ e.apply(history, t), this.handlePageview();
566
+ }, window.addEventListener("hashchange", this.handlePageview.bind(this)), setInterval(this.checkForUrlChange.bind(this), 1e3);
567
+ }
568
+ handlePageview() {
569
+ this.trackPageview();
570
+ }
571
+ checkForUrlChange() {
572
+ window.location.href !== this.lastPageUrl && this.trackPageview();
573
+ }
574
+ trackPageview() {
575
+ const e = window.location.href;
576
+ e !== this.lastPageUrl && (this.lastPageUrl = e, this.client.track("pageview", {
577
+ url: e,
578
+ referrer: document.referrer,
579
+ title: document.title
580
+ }));
581
+ }
582
+ }
583
+ class ue {
584
+ constructor(e, t, i = h()) {
585
+ this.trackingHost = e, this.logger = i, this.config = t;
586
+ }
587
+ async send(e) {
588
+ const t = this.config.key, i = this.constructUrl(t), n = new Blob([JSON.stringify(e)], { type: "application/json" });
589
+ if (navigator.sendBeacon(i, n))
590
+ this.logger.debug(`Successfully queued ${e.length} event(s) via Beacon API`);
591
+ else
592
+ throw new Error("Failed to queue events via Beacon API");
593
+ }
594
+ constructUrl(e) {
595
+ const t = this.config.cookiePolicy !== "keep" ? `&cookie_policy=${this.config.cookiePolicy}` : "", i = this.config.ipPolicy !== "keep" ? `&ip_policy=${this.config.ipPolicy}` : "", n = u() ? "/api/v1/event" : "/api/v1/s2s/event";
596
+ return this.config.randomizeUrl ? `${this.trackingHost}/api.${f()}?p_${f()}=${e}${t}${i}` : `${this.trackingHost}${n}?token=${e}${t}${i}`;
597
+ }
598
+ // Note: Beacon API doesn't support custom headers, so we can't use them here.
599
+ // If custom headers are crucial, you might want to fall back to XHR or Fetch in those cases.
600
+ }
601
+ class L {
602
+ constructor(e, t, i = h()) {
603
+ this.trackingHost = e, this.logger = i, this.config = t;
604
+ }
605
+ async send(e) {
606
+ const t = this.config.key, i = this.constructUrl(t), n = JSON.stringify(e), r = {
607
+ "Content-Type": "application/json",
608
+ ...this.getCustomHeaders()
609
+ }, o = await fetch(i, {
610
+ method: "POST",
611
+ headers: r,
612
+ body: n
613
+ });
614
+ if (!o.ok)
615
+ throw new Error(`HTTP error! status: ${o.status}`);
616
+ this.logger.debug(`Successfully sent ${e.length} event(s)`), this.postHandle(o.status, await o.text());
617
+ }
618
+ constructUrl(e) {
619
+ const t = this.config.cookiePolicy !== "keep" ? `&cookie_policy=${this.config.cookiePolicy}` : "", i = this.config.ipPolicy !== "keep" ? `&ip_policy=${this.config.ipPolicy}` : "", n = u() ? "/api/v1/event" : "/api/v1/s2s/event";
620
+ return this.config.randomizeUrl ? `${this.trackingHost}/api.${f()}?p_${f()}=${e}${t}${i}` : `${this.trackingHost}${n}?token=${e}${t}${i}`;
621
+ }
622
+ getCustomHeaders() {
623
+ return typeof this.config.customHeaders == "function" ? this.config.customHeaders() : this.config.customHeaders ? this.config.customHeaders : {};
624
+ }
625
+ postHandle(e, t) {
626
+ this.logger.debug(`Response received. Status: ${e}, Body: ${t}`);
627
+ }
628
+ }
629
+ class he {
630
+ constructor(e, t, i = h()) {
631
+ this.trackingHost = e, this.logger = i, this.config = t;
632
+ }
633
+ send(e) {
634
+ return new Promise((t, i) => {
635
+ const n = new XMLHttpRequest(), r = this.config.key, o = this.constructUrl(r);
636
+ n.open("POST", o, !0), n.setRequestHeader("Content-Type", "application/json");
637
+ const c = this.getCustomHeaders();
638
+ Object.keys(c).forEach((l) => {
639
+ n.setRequestHeader(l, c[l]);
640
+ }), n.onload = () => {
641
+ n.status >= 200 && n.status < 300 ? (this.logger.debug(`Successfully sent ${e.length} event(s)`), t()) : i(new Error(`HTTP error! status: ${n.status}`));
642
+ }, n.onerror = () => {
643
+ i(new Error("Network error"));
644
+ }, n.send(JSON.stringify(e));
645
+ });
646
+ }
647
+ constructUrl(e) {
648
+ const t = this.config.cookiePolicy !== "keep" ? `&cookie_policy=${this.config.cookiePolicy}` : "", i = this.config.ipPolicy !== "keep" ? `&ip_policy=${this.config.ipPolicy}` : "", n = u() ? "/api/v1/event" : "/api/v1/s2s/event";
649
+ return this.config.randomizeUrl ? `${this.trackingHost}/api.${f()}?p_${f()}=${e}${t}${i}` : `${this.trackingHost}${n}?token=${e}${t}${i}`;
650
+ }
651
+ getCustomHeaders() {
652
+ return typeof this.config.customHeaders == "function" ? this.config.customHeaders() : this.config.customHeaders ? this.config.customHeaders : {};
653
+ }
654
+ postHandle(e, t) {
655
+ this.logger.debug(`Response received. Status: ${e}, Body: ${t}`);
656
+ }
657
+ }
658
+ class V {
659
+ constructor(e, t) {
660
+ this.storage = {}, this.prefix = `usermaven_${e}_`, this.load(), this.logger = t || h();
661
+ }
662
+ set(e, t) {
663
+ this.storage[e] = t, this.save();
664
+ }
665
+ get(e) {
666
+ return this.storage[e];
667
+ }
668
+ remove(e) {
669
+ delete this.storage[e], this.save();
670
+ }
671
+ clear() {
672
+ this.storage = {}, this.save();
673
+ }
674
+ save() {
675
+ if (!u()) {
676
+ this.logger.warn("localStorage is not available in this environment");
677
+ return;
678
+ }
679
+ try {
680
+ localStorage.setItem(this.prefix + "data", JSON.stringify(this.storage));
681
+ } catch (e) {
682
+ this.logger.error("Error saving to localStorage:", e);
683
+ }
684
+ }
685
+ load() {
686
+ if (!u()) {
687
+ this.logger.warn("localStorage is not available in this environment");
688
+ return;
689
+ }
690
+ try {
691
+ const e = localStorage.getItem(this.prefix + "data");
692
+ e && (this.storage = JSON.parse(e));
693
+ } catch (e) {
694
+ this.logger.error("Error loading from localStorage:", e);
695
+ }
696
+ }
697
+ }
698
+ class ge {
699
+ constructor() {
700
+ this.storage = {};
701
+ }
702
+ set(e, t) {
703
+ this.storage[e] = t;
704
+ }
705
+ get(e) {
706
+ return this.storage[e];
707
+ }
708
+ remove(e) {
709
+ delete this.storage[e];
710
+ }
711
+ save() {
712
+ }
713
+ clear() {
714
+ this.storage = {};
715
+ }
716
+ }
717
+ class U {
718
+ // Default to true for server-side
719
+ constructor(e, t = 3, i = 1e3, n = 10, r = 1e3, o = h()) {
720
+ this.transport = e, this.maxRetries = t, this.retryInterval = i, this.batchSize = n, this.batchInterval = r, this.logger = o, this.queue = [], this.processing = !1, this.batchTimeoutId = null, this.isOnline = !0, this.persistence = new V("offline_queue"), u() && (this.isOnline = navigator.onLine, this.loadQueueFromStorage(), this.initNetworkListeners(), this.scheduleBatch());
721
+ }
722
+ add(e) {
723
+ const t = { payload: e, retries: 0, timestamp: Date.now() };
724
+ this.queue.push(t), u() ? this.saveQueueToStorage() : this.processBatch();
725
+ }
726
+ initNetworkListeners() {
727
+ u() && (window.addEventListener("online", () => {
728
+ this.isOnline = !0, this.processBatch();
729
+ }), window.addEventListener("offline", () => {
730
+ this.isOnline = !1;
731
+ }));
732
+ }
733
+ scheduleBatch() {
734
+ u() && (this.batchTimeoutId !== null && clearTimeout(this.batchTimeoutId), this.batchTimeoutId = window.setTimeout(() => this.processBatch(), this.batchInterval));
735
+ }
736
+ async processBatch() {
737
+ if ((!u() || this.isOnline) && !this.processing && this.queue.length > 0) {
738
+ this.processing = !0;
739
+ const e = this.queue.splice(0, this.batchSize), t = e.map((i) => i.payload);
740
+ try {
741
+ await this.transport.send(t), this.logger.debug(`Successfully sent batch of ${e.length} payloads`), u() && this.saveQueueToStorage();
742
+ } catch (i) {
743
+ this.logger.error("Failed to send batch", i), await this.handleBatchFailure(e);
744
+ }
745
+ this.processing = !1;
746
+ }
747
+ u() && this.scheduleBatch();
748
+ }
749
+ async handleBatchFailure(e) {
750
+ for (const t of e)
751
+ t.retries < this.maxRetries ? (t.retries++, this.queue.unshift(t), this.logger.warn(`Retry attempt ${t.retries} for payload`)) : this.logger.error("Max retries reached, discarding payload", t.payload);
752
+ u() && (this.saveQueueToStorage(), await new Promise((t) => setTimeout(t, this.retryInterval)));
753
+ }
754
+ loadQueueFromStorage() {
755
+ if (u()) {
756
+ const e = this.persistence.get("queue");
757
+ e && (this.queue = JSON.parse(e));
758
+ }
759
+ }
760
+ saveQueueToStorage() {
761
+ u() && this.persistence.set("queue", JSON.stringify(this.queue));
762
+ }
763
+ }
764
+ class de {
765
+ constructor(e) {
766
+ this.clicks = [], this.threshold = 3, this.timeWindow = 2e3, this.distanceThreshold = 30, this.client = e, this.initializeEventListener(), F(this);
767
+ }
768
+ initializeEventListener() {
769
+ document.addEventListener("click", this.handleClick.bind(this));
770
+ }
771
+ handleClick(e) {
772
+ const t = e.target;
773
+ this.shouldCaptureElement(t) && this.click(e.clientX, e.clientY, Date.now());
774
+ }
775
+ shouldCaptureElement(e) {
776
+ return !e.closest(".um-no-capture");
777
+ }
778
+ click(e, t, i) {
779
+ const n = { x: e, y: t, timestamp: i };
780
+ this.clicks.push(n), this.clicks = this.clicks.filter((r) => i - r.timestamp < this.timeWindow), this.clicks.length >= this.threshold && this.checkRageClick();
781
+ }
782
+ checkRageClick() {
783
+ const e = this.clicks[0], i = (this.clicks[this.clicks.length - 1].timestamp - e.timestamp) / 1e3;
784
+ this.clicks.every((r, o) => {
785
+ if (o === 0) return !0;
786
+ const c = this.clicks[o - 1];
787
+ return Math.sqrt(Math.pow(r.x - c.x, 2) + Math.pow(r.y - c.y, 2)) < this.distanceThreshold;
788
+ }) && this.sendRageClickEvent(i);
789
+ }
790
+ sendRageClickEvent(e) {
791
+ const t = this.clicks[this.clicks.length - 1];
792
+ document.elementFromPoint(t.x, t.y) && this.client.track("$rage_click", {
793
+ no_of_clicks: this.clicks.length,
794
+ time: e.toFixed(2)
795
+ }), this.clicks = [];
796
+ }
797
+ }
798
+ class fe {
799
+ constructor(e, t, i = h()) {
800
+ this.trackingHost = e, this.logger = i, this.config = t;
801
+ }
802
+ async send(e) {
803
+ const t = this.config.key, i = new (void 0)(this.constructUrl(t)), n = {
804
+ hostname: i.hostname,
805
+ port: 443,
806
+ path: `${i.pathname}${i.search}`,
807
+ method: "POST",
808
+ headers: {
809
+ "Content-Type": "application/json",
810
+ ...this.getCustomHeaders()
811
+ }
812
+ };
813
+ return new Promise((r, o) => {
814
+ const c = (void 0)(n, (l) => {
815
+ l.on("data", (a) => {
816
+ }), l.on("end", () => {
817
+ const a = l.statusCode || 0;
818
+ a >= 200 && a < 300 ? (this.logger.debug(`Successfully sent ${e.length} event(s)`), r()) : o(new Error(`HTTP error! status: ${a}`));
819
+ });
820
+ });
821
+ c.on("error", (l) => {
822
+ o(l);
823
+ }), c.write(JSON.stringify(e)), c.end();
824
+ });
825
+ }
826
+ constructUrl(e) {
827
+ const t = this.config.cookiePolicy !== "keep" ? `&cookie_policy=${this.config.cookiePolicy}` : "", i = this.config.ipPolicy !== "keep" ? `&ip_policy=${this.config.ipPolicy}` : "";
828
+ return `${this.trackingHost}/api/v1/s2s/event?token=${e}${t}${i}`;
829
+ }
830
+ getCustomHeaders() {
831
+ return typeof this.config.customHeaders == "function" ? this.config.customHeaders() : this.config.customHeaders ? this.config.customHeaders : {};
832
+ }
833
+ }
834
+ class m {
835
+ constructor(e, t = "all", i = {}) {
836
+ this.instance = e, this.trackingType = t, this.options = i, document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", this.initialize.bind(this)) : this.initialize();
837
+ }
838
+ initialize() {
839
+ this.trackingType !== "none" && this.setupFormTracking();
840
+ }
841
+ setupFormTracking() {
842
+ var e;
843
+ this.formElements = this.trackingType === "tagged" ? document.querySelectorAll("form[data-um-form]") : document.querySelectorAll("form"), (e = this.formElements) == null || e.forEach((t) => {
844
+ t.addEventListener("submit", this.handleFormSubmit.bind(this));
845
+ });
846
+ }
847
+ handleFormSubmit(e) {
848
+ const t = e.target, i = this._getFormDetails(t);
849
+ this.instance.track("$form", R(i)), this.options.trackFieldChanges && this.trackFieldChanges(t);
850
+ }
851
+ trackFieldChanges(e) {
852
+ e.querySelectorAll("input, select, textarea").forEach((i) => {
853
+ i.addEventListener("change", (n) => {
854
+ const r = this._getFieldProps(n.target, 0);
855
+ this.instance.track("$form_field_change", R(r));
856
+ });
857
+ });
858
+ }
859
+ static getInstance(e, t = "all", i = {}) {
860
+ return m.instance || (m.instance = new m(e, t, i)), m.instance;
861
+ }
862
+ _getFormDetails(e) {
863
+ const t = {
864
+ form_id: e.id,
865
+ form_name: e.name || "",
866
+ form_action: e.action,
867
+ form_method: e.method,
868
+ form_class: e.className,
869
+ form_attributes: this._getElementAttributes(e)
870
+ }, i = e.querySelectorAll("input, select, textarea");
871
+ return Array.from(i).filter((r) => !r.classList.contains("um-no-capture")).forEach((r, o) => {
872
+ const c = this._getFieldProps(r, o);
873
+ Object.assign(t, c);
874
+ }), t;
875
+ }
876
+ _getFieldProps(e, t) {
877
+ const i = Object.keys(e.dataset).length ? JSON.stringify(e.dataset) : void 0, n = this.getSafeText(e);
878
+ return {
879
+ [`field_${t + 1}_tag`]: e.tagName.toLowerCase(),
880
+ [`field_${t + 1}_type`]: e instanceof HTMLInputElement ? e.type : void 0,
881
+ [`field_${t + 1}_data_attributes`]: i,
882
+ [`field_${t + 1}_id`]: e.id,
883
+ [`field_${t + 1}_value`]: n,
884
+ [`field_${t + 1}_class`]: e.className,
885
+ [`field_${t + 1}_name`]: e.name,
886
+ [`field_${t + 1}_attributes`]: this._getElementAttributes(e)
887
+ };
888
+ }
889
+ _getElementAttributes(e) {
890
+ const t = {};
891
+ for (let i = 0; i < e.attributes.length; i++) {
892
+ const n = e.attributes[i];
893
+ n.name !== "value" && !n.name.startsWith("data-") && (t[n.name] = n.value);
894
+ }
895
+ return t;
896
+ }
897
+ getSafeText(e) {
898
+ let t = "";
899
+ return "value" in e && e.type !== "password" ? t = e.value : e.hasChildNodes() ? t = Array.from(e.childNodes).filter(
900
+ (n) => n.nodeType === Node.TEXT_NODE
901
+ ).map((n) => n.textContent).join("") : t = e.textContent || "", this._scrubPotentiallySensitiveValues(t);
902
+ }
903
+ _scrubPotentiallySensitiveValues(e) {
904
+ return this._shouldCaptureValue(e) ? e : "<redacted>";
905
+ }
906
+ _shouldCaptureValue(e) {
907
+ return !(this._isNullish(e) || this._isString(e) && (e = this._trim(e), /^(?:(4[0-9]{12}(?:[0-9]{3})?)|(5[1-5][0-9]{14})|(6(?:011|5[0-9]{2})[0-9]{12})|(3[47][0-9]{13})|(3(?:0[0-5]|[68][0-9])[0-9]{11})|((?:2131|1800|35[0-9]{3})[0-9]{11}))$/.test((e || "").replace(/[- ]/g, "")) || /(^\d{3}-?\d{2}-?\d{4}$)/.test(e)));
908
+ }
909
+ _isNullish(e) {
910
+ return e == null;
911
+ }
912
+ _isString(e) {
913
+ return typeof e == "string" || e instanceof String;
914
+ }
915
+ _trim(e) {
916
+ if (typeof String.prototype.trim == "function")
917
+ return e.trim();
918
+ let t = 0, i = e.length - 1;
919
+ const n = [
920
+ " ",
921
+ `
922
+ `,
923
+ "\r",
924
+ " ",
925
+ "\f",
926
+ "\v",
927
+ " ",
928
+ " ",
929
+ " ",
930
+ " ",
931
+ " ",
932
+ " ",
933
+ " ",
934
+ " ",
935
+ " ",
936
+ " ",
937
+ " ",
938
+ " ",
939
+ " ",
940
+ "\u2028",
941
+ "\u2029",
942
+ " ",
943
+ " ",
944
+ " "
945
+ ].join("");
946
+ for (; t <= i && n.indexOf(e[t]) > -1; )
947
+ t++;
948
+ for (; i >= t && n.indexOf(e[i]) > -1; )
949
+ i--;
950
+ return e.slice(t, i + 1);
951
+ }
952
+ }
953
+ class pe {
954
+ constructor(e) {
955
+ this.config = this.mergeConfig(e, I), this.logger = h(this.config.logLevel), this.namespace = e.namespace || "usermaven", this.transport = this.initializeTransport(this.config), this.persistence = this.initializePersistence(), this.retryQueue = new U(
956
+ this.transport,
957
+ this.config.maxSendAttempts || 3,
958
+ this.config.minSendTimeout || 1e3,
959
+ 10,
960
+ 200,
961
+ // Reduced interval to .2 second
962
+ this.logger
963
+ ), u() && this.initializeBrowserFeatures(), this.anonymousId = this.getOrCreateAnonymousId(), this.logger.info(`Usermaven client initialized for namespace: ${this.namespace}`);
964
+ }
965
+ initializeBrowserFeatures() {
966
+ if (this.cookieManager = new Q(this.config.cookieDomain), this.config.autocapture && w.enabledForProject(this.config.key) && (this.autoCapture = new w(this, this.config, this.logger), this.autoCapture.init()), this.config.formTracking) {
967
+ const e = this.config.formTracking === !0 ? "all" : this.config.formTracking;
968
+ this.formTracking = m.getInstance(this, e || "none", {
969
+ trackFieldChanges: !1
970
+ });
971
+ }
972
+ this.config.autoPageview && (this.pageviewTracking = new le(this)), this.config.crossDomainLinking && this.manageCrossDomainLinking(), this.config.rageClick && (this.rageClick = new de(this)), this.setupPageLeaveTracking();
973
+ }
974
+ /**
975
+ * Recursively merge the provided configuration with the existing defaultConfig
976
+ * @param config
977
+ * @param defaultConfig
978
+ */
979
+ mergeConfig(e, t) {
980
+ const i = JSON.parse(JSON.stringify(e));
981
+ let n = { ...t, ...i };
982
+ return Object.keys(t).forEach((r) => {
983
+ k(t[r]) && (n[r] = this.mergeConfig(e[r], t[r]));
984
+ }), n;
985
+ }
986
+ init(e) {
987
+ this.config = { ...this.config, ...e }, this.logger = h(this.config.logLevel), this.namespace = e.namespace || this.namespace, this.transport = this.initializeTransport(e), this.persistence = this.initializePersistence(), this.retryQueue = new U(
988
+ this.transport,
989
+ this.config.maxSendAttempts || 3,
990
+ this.config.minSendTimeout || 1e3,
991
+ 10,
992
+ 250,
993
+ // Reduced interval to .25 second
994
+ this.logger
995
+ ), u() && this.initializeBrowserFeatures(), this.anonymousId = this.getOrCreateAnonymousId(), this.logger.info(`Usermaven client reinitialized for namespace: ${this.namespace}`);
996
+ }
997
+ manageCrossDomainLinking() {
998
+ if (!this.config.crossDomainLinking || !this.config.domains)
999
+ return;
1000
+ const e = this.config.domains.split(",").map((i) => i.trim()), t = this.config.cookieName || `${this.namespace}_id_${this.config.key}`;
1001
+ document.addEventListener("click", (i) => {
1002
+ var c;
1003
+ const n = this.findClosestLink(i.target);
1004
+ if (!n) return;
1005
+ const r = n.getAttribute("href");
1006
+ if (!r || !r.startsWith("http")) return;
1007
+ const o = new URL(r);
1008
+ if (o.hostname !== window.location.hostname && e.includes(o.hostname)) {
1009
+ const l = (c = this.cookieManager) == null ? void 0 : c.get(t);
1010
+ l && (o.searchParams.append("_um", l), n.setAttribute("href", o.toString()));
1011
+ }
1012
+ }), this.logger.debug("Cross-domain linking initialized");
1013
+ }
1014
+ findClosestLink(e) {
1015
+ for (; e && e.tagName !== "A"; )
1016
+ e = e.parentElement;
1017
+ return e;
1018
+ }
1019
+ initializeTransport(e) {
1020
+ if (!u())
1021
+ return new fe(e.trackingHost, e);
1022
+ const t = "XMLHttpRequest" in window, i = typeof fetch < "u", n = typeof navigator < "u" && "sendBeacon" in navigator;
1023
+ if (e.useBeaconApi && n)
1024
+ return new ue(e.trackingHost, e, this.logger);
1025
+ if (e.forceUseFetch && i)
1026
+ return new L(e.trackingHost, e, this.logger);
1027
+ if (t)
1028
+ return new he(e.trackingHost, e, this.logger);
1029
+ if (i)
1030
+ return new L(e.trackingHost, e, this.logger);
1031
+ throw new Error("No suitable transport method available");
1032
+ }
1033
+ initializePersistence() {
1034
+ return this.config.disableEventPersistence || !u() ? new ge() : new V(`${this.namespace}_${this.config.key}`, this.logger);
1035
+ }
1036
+ getOrCreateAnonymousId() {
1037
+ var i, n;
1038
+ if (!u())
1039
+ return P();
1040
+ if (this.config.privacyPolicy === "strict" || this.config.cookiePolicy === "strict")
1041
+ return this.generateFingerprint();
1042
+ const e = this.config.cookieName || `${this.namespace}_id_${this.config.key}`;
1043
+ let t = (i = this.cookieManager) == null ? void 0 : i.get(e);
1044
+ if (!t) {
1045
+ if (this.config.crossDomainLinking) {
1046
+ const c = new URLSearchParams(window.location.search).get("_um"), a = window.location.hash.substring(1).split("~"), g = a.length > 1 ? a[1] : void 0;
1047
+ t = c || g || P();
1048
+ }
1049
+ t || (t = P());
1050
+ const r = 365 * 10;
1051
+ (n = this.cookieManager) == null || n.set(e, t, r, document.location.protocol !== "http:", !1);
1052
+ }
1053
+ return t;
1054
+ }
1055
+ generateFingerprint() {
1056
+ const e = navigator.userAgent, t = `${screen.width}x${screen.height}`, i = screen.colorDepth, n = Intl.DateTimeFormat().resolvedOptions().timeZone, r = `${e}|${t}|${i}|${n}`;
1057
+ return this.hashString(r);
1058
+ }
1059
+ hashString(e) {
1060
+ let t = 0;
1061
+ for (let i = 0; i < e.length; i++) {
1062
+ const n = e.charCodeAt(i);
1063
+ t = (t << 5) - t + n, t = t & t;
1064
+ }
1065
+ return t.toString(36);
1066
+ }
1067
+ async id(e, t = !1) {
1068
+ if (!k(e))
1069
+ throw new Error("User data must be an object");
1070
+ if (e.email && !ne(e.email))
1071
+ throw new Error("Invalid email provided");
1072
+ if (!e.id || !O(e.id))
1073
+ throw new Error("User ID must be a string");
1074
+ const i = e.id;
1075
+ if (this.persistence.set("userId", i), this.persistence.set("userProps", e), !t) {
1076
+ const n = {
1077
+ ...e,
1078
+ anonymous_id: this.anonymousId
1079
+ };
1080
+ await this.track("user_identify", n);
1081
+ }
1082
+ this.logger.info("User identified:", e);
1083
+ }
1084
+ track(e, t, i = !1) {
1085
+ this.trackInternal(e, t, i);
1086
+ }
1087
+ trackInternal(e, t, i = !1) {
1088
+ if (!O(e))
1089
+ throw new Error("Event name must be a string");
1090
+ if (t !== void 0 && (typeof t != "object" || t === null || Array.isArray(t)))
1091
+ throw new Error("Event payload must be a non-null object and not an array");
1092
+ const n = this.createEventPayload(e, t);
1093
+ try {
1094
+ if (i) {
1095
+ this.transport.send(n), this.logger.debug(`Event sent: ${e}`, [n]);
1096
+ return;
1097
+ }
1098
+ this.retryQueue.add(n), this.logger.debug(`Event tracked: ${e}`, [n]);
1099
+ } catch (r) {
1100
+ throw this.logger.error(`Failed to track event: ${e}`, r), new Error(`Failed to track event: ${e}`);
1101
+ }
1102
+ }
1103
+ rawTrack(e) {
1104
+ if (!k(e))
1105
+ throw new Error("Event payload must be an object");
1106
+ this.track("raw", e);
1107
+ }
1108
+ async group(e, t = !1) {
1109
+ if (!k(e))
1110
+ throw new Error("Company properties must be an object");
1111
+ if (!e.id || !e.name || !e.created_at)
1112
+ throw new Error("Company properties must include id, name, and created_at");
1113
+ this.persistence.set("companyProps", e), t || await this.track("group", e), this.logger.info("Company identified:", e);
1114
+ }
1115
+ createEventPayload(e, t) {
1116
+ const i = this.persistence.get("userProps") || {}, n = this.persistence.get("companyProps") || void 0, r = this.persistence.get("userId"), o = this.persistence.get("global_props") || {}, c = this.persistence.get(`props_${e}`) || {};
1117
+ let l = t || {};
1118
+ const a = {
1119
+ event_id: "",
1120
+ user: {
1121
+ anonymous_id: this.anonymousId,
1122
+ id: r,
1123
+ ...i
1124
+ },
1125
+ ...n && { company: n },
1126
+ ids: this.getThirdPartyIds(),
1127
+ utc_time: (/* @__PURE__ */ new Date()).toISOString(),
1128
+ local_tz_offset: (/* @__PURE__ */ new Date()).getTimezoneOffset(),
1129
+ api_key: this.config.key,
1130
+ src: "usermaven",
1131
+ event_type: e,
1132
+ namespace: this.namespace,
1133
+ ...o,
1134
+ ...c
1135
+ };
1136
+ if (e === "$autocapture") {
1137
+ const g = this.processAutocaptureAttributes(t || {});
1138
+ a.autocapture_attributes = g;
1139
+ } else
1140
+ Array.isArray(this.config.propertyBlacklist) && this.config.propertyBlacklist.forEach((g) => {
1141
+ delete l[g];
1142
+ }), a.event_attributes = l;
1143
+ return u() && (a.referer = document.referrer, a.url = window.location.href, a.page_title = document.title, a.doc_path = window.location.pathname, a.doc_host = window.location.hostname, a.doc_search = window.location.search, a.screen_resolution = `${window.screen.width}x${window.screen.height}`, a.vp_size = `${window.innerWidth}x${window.innerHeight}`, a.user_agent = navigator.userAgent, a.user_language = navigator.language, a.doc_encoding = document.characterSet, a.utm = this.getUtmParams()), a;
1144
+ }
1145
+ processAutocaptureAttributes(e) {
1146
+ let t = {};
1147
+ const i = e.$elements || [];
1148
+ return i.length && (t = { ...i[0] }), t.el_text = t.$el_text || "", t.event_type = e.$event_type || "", ["$ce_version", "$event_type", "$initial_referrer", "$initial_referring_domain", "$referrer", "$referring_domain", "$elements"].forEach((n) => {
1149
+ delete t[n];
1150
+ }), delete t.$el_text, delete t.nth_child, delete t.nth_of_type, t;
1151
+ }
1152
+ getCookie(e) {
1153
+ var t;
1154
+ return ((t = this.cookieManager) == null ? void 0 : t.get(e)) || null;
1155
+ }
1156
+ getThirdPartyIds() {
1157
+ const e = {};
1158
+ if (u()) {
1159
+ const t = this.getCookie("_fbp");
1160
+ t && (e.fbp = t);
1161
+ }
1162
+ return e;
1163
+ }
1164
+ getUtmParams() {
1165
+ const e = {}, t = oe(window.location.search);
1166
+ return ["utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content"].forEach((n) => {
1167
+ t[n] && (e[n.replace("utm_", "")] = t[n]);
1168
+ }), e;
1169
+ }
1170
+ pageview() {
1171
+ u() ? this.track("pageview", {
1172
+ url: window.location.href,
1173
+ referrer: document.referrer,
1174
+ title: document.title
1175
+ }, !0) : this.logger.warn("Pageview tracking is not available in server-side environments");
1176
+ }
1177
+ setupPageLeaveTracking() {
1178
+ if (!u()) return;
1179
+ let e = !1, t = !1;
1180
+ const i = () => {
1181
+ !e && !t && (e = !0, this.track("$pageleave", {
1182
+ url: window.location.href,
1183
+ referrer: document.referrer,
1184
+ title: document.title
1185
+ }));
1186
+ };
1187
+ window.addEventListener("beforeunload", (r) => {
1188
+ t = !0, setTimeout(() => {
1189
+ t = !1;
1190
+ }, 100);
1191
+ }), document.addEventListener("visibilitychange", () => {
1192
+ document.visibilityState === "hidden" && !t && i();
1193
+ });
1194
+ const n = history.pushState;
1195
+ history.pushState = function() {
1196
+ return i(), n.apply(this, arguments);
1197
+ }, window.addEventListener("popstate", i);
1198
+ }
1199
+ getConfig() {
1200
+ return this.config;
1201
+ }
1202
+ getLogger() {
1203
+ return this.logger;
1204
+ }
1205
+ async reset(e = !1) {
1206
+ if (this.persistence.clear(), e && this.cookieManager) {
1207
+ const t = this.config.cookieName || `${this.namespace}_id_${this.config.key}`;
1208
+ this.cookieManager.delete(t), this.anonymousId = this.getOrCreateAnonymousId();
1209
+ }
1210
+ this.logger.info("core state reset", { resetAnonId: e, namespace: this.namespace });
1211
+ }
1212
+ set(e, t) {
1213
+ if (!k(e))
1214
+ throw new Error("Properties must be an object");
1215
+ const i = t == null ? void 0 : t.eventType, n = (t == null ? void 0 : t.persist) ?? !0;
1216
+ if (i) {
1217
+ let r = this.persistence.get(`props_${i}`) || {};
1218
+ r = { ...r, ...e }, this.persistence.set(`props_${i}`, r);
1219
+ } else {
1220
+ let r = this.persistence.get("global_props") || {};
1221
+ r = { ...r, ...e }, this.persistence.set("global_props", r);
1222
+ }
1223
+ n && this.persistence.save(), this.logger.debug("Properties set", {
1224
+ properties: e,
1225
+ eventType: i || "global",
1226
+ persist: n
1227
+ });
1228
+ }
1229
+ setUserId(e) {
1230
+ this.persistence.set("userId", e);
1231
+ let t = this.persistence.get("userProps") || {};
1232
+ t.id = e, this.persistence.set("userProps", t), this.persistence.save();
1233
+ }
1234
+ unset(e, t) {
1235
+ const i = t == null ? void 0 : t.eventType, n = (t == null ? void 0 : t.persist) ?? !0;
1236
+ if (i) {
1237
+ let r = this.persistence.get(`props_${i}`) || {};
1238
+ delete r[e], this.persistence.set(`props_${i}`, r);
1239
+ } else {
1240
+ let r = this.persistence.get("global_props") || {};
1241
+ delete r[e], this.persistence.set("global_props", r);
1242
+ }
1243
+ n && this.persistence.save(), this.logger.debug(`Property unset: ${e}`, `Event type: ${i || "global"}`);
1244
+ }
1245
+ }
1246
+ function me(s) {
1247
+ const e = JSON.parse(JSON.stringify(s)), t = S(e), i = { ...I, ...t };
1248
+ if (!i.key)
1249
+ throw new Error("API key is required!");
1250
+ if (!i.trackingHost)
1251
+ throw new Error("Tracking host is required!");
1252
+ return new pe(i);
1253
+ }
1254
+ function ye(s) {
1255
+ var n;
1256
+ const e = {
1257
+ key: s.getAttribute("data-key") || void 0,
1258
+ trackingHost: s.getAttribute("data-tracking-host") || "https://events.usermaven.com",
1259
+ logLevel: ae(s.getAttribute("data-log-level")),
1260
+ autocapture: s.getAttribute("data-autocapture") === "true",
1261
+ formTracking: s.getAttribute("data-form-tracking") === "true" ? "all" : !1,
1262
+ autoPageview: s.getAttribute("data-auto-pageview") === "true",
1263
+ useBeaconApi: s.getAttribute("data-use-beacon-api") === "true",
1264
+ forceUseFetch: s.getAttribute("data-force-use-fetch") === "true",
1265
+ gaHook: s.getAttribute("data-ga-hook") === "true",
1266
+ segmentHook: s.getAttribute("data-segment-hook") === "true",
1267
+ randomizeUrl: s.getAttribute("data-randomize-url") === "true",
1268
+ capture3rdPartyCookies: s.getAttribute("data-capture-3rd-party-cookies") === "false" ? !1 : void 0,
1269
+ idMethod: s.getAttribute("data-id-method") || void 0,
1270
+ privacyPolicy: s.getAttribute("data-privacy-policy") === "strict" ? "strict" : void 0,
1271
+ ipPolicy: s.getAttribute("data-ip-policy") || void 0,
1272
+ cookiePolicy: s.getAttribute("data-cookie-policy") || void 0,
1273
+ minSendTimeout: parseInt(s.getAttribute("data-min-send-timeout") || "", 10) || void 0,
1274
+ maxSendTimeout: parseInt(s.getAttribute("data-max-send-timeout") || "", 10) || void 0,
1275
+ maxSendAttempts: parseInt(s.getAttribute("data-max-send-attempts") || "", 10) || void 0,
1276
+ propertiesStringMaxLength: parseInt(s.getAttribute("data-properties-string-max-length") || "", 10) || null,
1277
+ propertyBlacklist: ((n = s.getAttribute("data-property-blacklist")) == null ? void 0 : n.split(",")) || void 0,
1278
+ exclude: s.getAttribute("data-exclude") || void 0,
1279
+ namespace: s.getAttribute("data-namespace") || void 0,
1280
+ crossDomainLinking: s.getAttribute("data-cross-domain-linking") !== "false",
1281
+ domains: s.getAttribute("data-domains") || void 0,
1282
+ maskAllText: s.getAttribute("data-mask-all-text") === "true",
1283
+ maskAllElementAttributes: s.getAttribute("data-mask-all-element-attributes") === "true"
1284
+ }, t = me(e), i = e.namespace || "usermaven";
1285
+ u() && t.pageview(), we(i, t);
1286
+ }
1287
+ function we(s, e) {
1288
+ let t = !1;
1289
+ const i = [], n = [];
1290
+ function r() {
1291
+ for (; i.length > 0; ) {
1292
+ const a = i.shift();
1293
+ a && window[s].apply(null, a);
1294
+ }
1295
+ }
1296
+ function o() {
1297
+ n.forEach((a) => a()), n.length = 0;
1298
+ }
1299
+ window[s] = function(...a) {
1300
+ const g = a[0];
1301
+ if (g === "onLoad") {
1302
+ typeof a[1] == "function" && (t ? a[1]() : n.push(a[1]));
1303
+ return;
1304
+ }
1305
+ if (!t) {
1306
+ i.push(a);
1307
+ return;
1308
+ }
1309
+ if (typeof e[g] == "function")
1310
+ return e[g].apply(e, a.slice(1));
1311
+ console.error(`Method ${g} not found on UsermavenClient`);
1312
+ };
1313
+ const c = `${s}Q`, l = window[c] || [];
1314
+ for (window[c] = l, l.push = function(...a) {
1315
+ return window[s].apply(null, a), Array.prototype.push.apply(this, a);
1316
+ }, setTimeout(() => {
1317
+ t = !0, r(), o(), console.log(`Usermaven client for namespace ${s} is ready`);
1318
+ }, 0); l.length > 0; ) {
1319
+ const a = l.shift();
1320
+ a && i.push(a);
1321
+ }
1322
+ }
1323
+ u() && function(s, e) {
1324
+ const t = s.currentScript;
1325
+ function i() {
1326
+ t && t.src.includes("lib.js") && ye(t);
1327
+ }
1328
+ typeof e < "u" && (s.readyState === "loading" ? s.addEventListener("DOMContentLoaded", i) : i());
1329
+ }(document, window);
1330
+
1331
+ function createClient(params) {
1332
+ return me(params);
1333
+ }
1334
+
1335
+ function useUsermaven() {
1336
+ const client = useContext(UsermavenContext);
1337
+ if (!client) {
1338
+ throw new Error("Before calling useUsermaven() hook, please wrap your component into <UsermavenProvider />. Read more in http://jitsu.com/docs/sending-data/js-sdk/react");
1339
+ }
1340
+ const id = useCallback((userData, doNotSendEvent) => client === null || client === void 0 ? void 0 : client.id(userData, doNotSendEvent), [client]);
1341
+ const trackPageView = useCallback(() => client === null || client === void 0 ? void 0 : client.track('pageview'), [client]);
1342
+ const track = useCallback((typeName, payload) => client === null || client === void 0 ? void 0 : client.track(typeName, payload), [client]);
1343
+ const rawTrack = useCallback((payload) => client === null || client === void 0 ? void 0 : client.rawTrack(payload), [client]);
1344
+ const set = useCallback((properties, opts) => client === null || client === void 0 ? void 0 : client.set(properties, opts), [client]);
1345
+ const unset = useCallback((propertyName, opts) => client === null || client === void 0 ? void 0 : client.unset(propertyName, opts), [client]);
1346
+ return Object.assign(Object.assign({}, client), { id,
1347
+ track,
1348
+ trackPageView,
1349
+ rawTrack,
1350
+ set,
1351
+ unset });
1352
+ }
1353
+
1354
+ function useUrlChange() {
1355
+ const [url, setUrl] = useState('');
1356
+ useEffect(() => {
1357
+ setUrl(window.location.href);
1358
+ const handleUrlChange = () => {
1359
+ setUrl(window.location.href);
1360
+ };
1361
+ window.addEventListener('popstate', handleUrlChange);
1362
+ const originalPushState = window.history.pushState;
1363
+ const originalReplaceState = window.history.replaceState;
1364
+ window.history.pushState = function () {
1365
+ originalPushState.apply(this, arguments);
1366
+ handleUrlChange();
1367
+ };
1368
+ window.history.replaceState = function () {
1369
+ originalReplaceState.apply(this, arguments);
1370
+ handleUrlChange();
1371
+ };
1372
+ return () => {
1373
+ window.removeEventListener('popstate', handleUrlChange);
1374
+ window.history.pushState = originalPushState;
1375
+ window.history.replaceState = originalReplaceState;
1376
+ };
1377
+ }, []);
1378
+ return url;
1379
+ }
1380
+ function usePageView(usermaven, opts = {}) {
1381
+ const url = useUrlChange();
1382
+ const trackPageView = useCallback(() => {
1383
+ if (typeof window === 'undefined') {
1384
+ return;
1385
+ }
1386
+ if (opts.before) {
1387
+ opts.before(usermaven);
1388
+ }
1389
+ usermaven.track((opts === null || opts === void 0 ? void 0 : opts.typeName) || 'pageview', Object.assign(Object.assign({}, opts.payload), { url: window.location.href, path: window.location.pathname, referrer: document.referrer, title: document.title }));
1390
+ }, [usermaven, opts.before, opts.typeName, opts.payload]);
1391
+ useEffect(() => {
1392
+ if (url) {
1393
+ trackPageView();
1394
+ }
1395
+ }, [url, trackPageView]);
1396
+ return usermaven;
1397
+ }
1398
+
1399
+ /*!
1400
+ * cookie
1401
+ * Copyright(c) 2012-2014 Roman Shtylman
1402
+ * Copyright(c) 2015 Douglas Christopher Wilson
1403
+ * MIT Licensed
1404
+ */
1405
+ var serialize_1 = serialize;
1406
+
1407
+ /**
1408
+ * Module variables.
1409
+ * @private
1410
+ */
1411
+
1412
+ var __toString = Object.prototype.toString;
1413
+
1414
+ /**
1415
+ * RegExp to match field-content in RFC 7230 sec 3.2
1416
+ *
1417
+ * field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ]
1418
+ * field-vchar = VCHAR / obs-text
1419
+ * obs-text = %x80-FF
1420
+ */
1421
+
1422
+ var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
1423
+
1424
+ /**
1425
+ * Serialize data into a cookie header.
1426
+ *
1427
+ * Serialize the a name value pair into a cookie string suitable for
1428
+ * http headers. An optional options object specified cookie parameters.
1429
+ *
1430
+ * serialize('foo', 'bar', { httpOnly: true })
1431
+ * => "foo=bar; httpOnly"
1432
+ *
1433
+ * @param {string} name
1434
+ * @param {string} val
1435
+ * @param {object} [options]
1436
+ * @return {string}
1437
+ * @public
1438
+ */
1439
+
1440
+ function serialize(name, val, options) {
1441
+ var opt = options || {};
1442
+ var enc = opt.encode || encode;
1443
+
1444
+ if (typeof enc !== 'function') {
1445
+ throw new TypeError('option encode is invalid');
1446
+ }
1447
+
1448
+ if (!fieldContentRegExp.test(name)) {
1449
+ throw new TypeError('argument name is invalid');
1450
+ }
1451
+
1452
+ var value = enc(val);
1453
+
1454
+ if (value && !fieldContentRegExp.test(value)) {
1455
+ throw new TypeError('argument val is invalid');
1456
+ }
1457
+
1458
+ var str = name + '=' + value;
1459
+
1460
+ if (null != opt.maxAge) {
1461
+ var maxAge = opt.maxAge - 0;
1462
+
1463
+ if (isNaN(maxAge) || !isFinite(maxAge)) {
1464
+ throw new TypeError('option maxAge is invalid')
1465
+ }
1466
+
1467
+ str += '; Max-Age=' + Math.floor(maxAge);
1468
+ }
1469
+
1470
+ if (opt.domain) {
1471
+ if (!fieldContentRegExp.test(opt.domain)) {
1472
+ throw new TypeError('option domain is invalid');
1473
+ }
1474
+
1475
+ str += '; Domain=' + opt.domain;
1476
+ }
1477
+
1478
+ if (opt.path) {
1479
+ if (!fieldContentRegExp.test(opt.path)) {
1480
+ throw new TypeError('option path is invalid');
1481
+ }
1482
+
1483
+ str += '; Path=' + opt.path;
1484
+ }
1485
+
1486
+ if (opt.expires) {
1487
+ var expires = opt.expires;
1488
+
1489
+ if (!isDate(expires) || isNaN(expires.valueOf())) {
1490
+ throw new TypeError('option expires is invalid');
1491
+ }
1492
+
1493
+ str += '; Expires=' + expires.toUTCString();
1494
+ }
1495
+
1496
+ if (opt.httpOnly) {
1497
+ str += '; HttpOnly';
1498
+ }
1499
+
1500
+ if (opt.secure) {
1501
+ str += '; Secure';
1502
+ }
1503
+
1504
+ if (opt.priority) {
1505
+ var priority = typeof opt.priority === 'string'
1506
+ ? opt.priority.toLowerCase()
1507
+ : opt.priority;
1508
+
1509
+ switch (priority) {
1510
+ case 'low':
1511
+ str += '; Priority=Low';
1512
+ break
1513
+ case 'medium':
1514
+ str += '; Priority=Medium';
1515
+ break
1516
+ case 'high':
1517
+ str += '; Priority=High';
1518
+ break
1519
+ default:
1520
+ throw new TypeError('option priority is invalid')
1521
+ }
1522
+ }
1523
+
1524
+ if (opt.sameSite) {
1525
+ var sameSite = typeof opt.sameSite === 'string'
1526
+ ? opt.sameSite.toLowerCase() : opt.sameSite;
1527
+
1528
+ switch (sameSite) {
1529
+ case true:
1530
+ str += '; SameSite=Strict';
1531
+ break;
1532
+ case 'lax':
1533
+ str += '; SameSite=Lax';
1534
+ break;
1535
+ case 'strict':
1536
+ str += '; SameSite=Strict';
1537
+ break;
1538
+ case 'none':
1539
+ str += '; SameSite=None';
1540
+ break;
1541
+ default:
1542
+ throw new TypeError('option sameSite is invalid');
1543
+ }
1544
+ }
1545
+
1546
+ return str;
1547
+ }
1548
+
1549
+ /**
1550
+ * URL-encode value.
1551
+ *
1552
+ * @param {string} str
1553
+ * @returns {string}
1554
+ */
1555
+
1556
+ function encode (val) {
1557
+ return encodeURIComponent(val)
1558
+ }
1559
+
1560
+ /**
1561
+ * Determine if value is a Date.
1562
+ *
1563
+ * @param {*} val
1564
+ * @private
1565
+ */
1566
+
1567
+ function isDate (val) {
1568
+ return __toString.call(val) === '[object Date]' ||
1569
+ val instanceof Date
1570
+ }
1571
+
1572
+ function middlewareEnv(req, res, opts = {}) {
1573
+ return {
1574
+ getAnonymousId({ name, domain }) {
1575
+ if (opts === null || opts === void 0 ? void 0 : opts.disableCookies) {
1576
+ return "";
1577
+ }
1578
+ const cookie = req.cookies[name];
1579
+ if (cookie) {
1580
+ return cookie;
1581
+ }
1582
+ const cookieOpts = {
1583
+ maxAge: 31622400 * 10,
1584
+ httpOnly: false,
1585
+ };
1586
+ if (domain) {
1587
+ cookieOpts.domain = domain;
1588
+ }
1589
+ let newId = Math.random().toString(36).substring(2, 12);
1590
+ res.headers.set("Set-Cookie", serialize_1(name, newId, cookieOpts));
1591
+ return newId;
1592
+ },
1593
+ getSourceIp() {
1594
+ let ip = req.headers.get("x-forwarded-for") || req.headers.get("x-real-ip") || req.ip;
1595
+ return ip && ip.split(",")[0].trim();
1596
+ },
1597
+ describeClient() {
1598
+ var _a;
1599
+ const requestHost = req.headers.get("x-forwarded-host") || req.headers.get("host") || req.nextUrl.hostname;
1600
+ const proto = req.headers.get("x-forwarded-proto") || ((_a = req.nextUrl.protocol) === null || _a === void 0 ? void 0 : _a.replace(":", ""));
1601
+ let query = req.nextUrl.search;
1602
+ let path = req.nextUrl.pathname;
1603
+ return {
1604
+ doc_encoding: "",
1605
+ doc_host: requestHost,
1606
+ doc_path: req.url,
1607
+ doc_search: query,
1608
+ page_title: "",
1609
+ referer: req.headers.get("referrer"),
1610
+ screen_resolution: "",
1611
+ url: `${proto}://${requestHost}${path || ""}${query || ""}`,
1612
+ user_agent: req.headers.get("user-agent"),
1613
+ user_language: req.headers.get("accept-language") && req.headers.get("accept-language").split(",")[0],
1614
+ vp_size: "",
1615
+ };
1616
+ },
1617
+ };
1618
+ }
1619
+
1620
+ export { UsermavenContext, UsermavenProvider, createClient, middlewareEnv, usePageView, useUsermaven };