@usermaven/nextjs 1.4.1-rc.61 → 1.4.1-rc.63

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.
Files changed (2) hide show
  1. package/lib/index.es.js +201 -223
  2. package/package.json +2 -2
package/lib/index.es.js CHANGED
@@ -9,7 +9,7 @@ const UsermavenProvider = function ({ children, client }) {
9
9
  };
10
10
 
11
11
  var v = /* @__PURE__ */ ((i) => (i[i.DEBUG = 0] = "DEBUG", i[i.INFO = 1] = "INFO", i[i.WARN = 2] = "WARN", i[i.ERROR = 3] = "ERROR", i))(v || {});
12
- class V {
12
+ class W {
13
13
  constructor(e) {
14
14
  this.level = e;
15
15
  }
@@ -26,10 +26,10 @@ class V {
26
26
  this.level <= 3 && console.error("[Usermaven Error]:", e, ...t);
27
27
  }
28
28
  }
29
- function h(i = 0) {
30
- return new V(i);
29
+ function g(i = 0) {
30
+ return new W(i);
31
31
  }
32
- const I = {
32
+ const U = {
33
33
  logLevel: v.ERROR,
34
34
  useBeaconApi: !1,
35
35
  forceUseFetch: !1,
@@ -55,7 +55,7 @@ const I = {
55
55
  maskAllText: !1,
56
56
  maskAllElementAttributes: !1
57
57
  };
58
- class Q {
58
+ class X {
59
59
  constructor(e) {
60
60
  this.domain = e, this.cookieDomain = this.getCookieDomain();
61
61
  }
@@ -104,39 +104,39 @@ class Q {
104
104
  return s ? s[0] : "";
105
105
  }
106
106
  }
107
- const W = Object.prototype, X = W.hasOwnProperty, K = Array.prototype, E = K.forEach, T = {};
107
+ const K = Object.prototype, G = K.hasOwnProperty, Y = Array.prototype, $ = Y.forEach, A = {};
108
108
  function Z(i, e, t) {
109
109
  if (Array.isArray(i)) {
110
- if (E && i.forEach === E)
110
+ if ($ && i.forEach === $)
111
111
  i.forEach(e, t);
112
112
  else if ("length" in i && i.length === +i.length) {
113
113
  for (let s = 0, n = i.length; s < n; s++)
114
- if (s in i && e.call(t, i[s], s) === T)
114
+ if (s in i && e.call(t, i[s], s) === A)
115
115
  return;
116
116
  }
117
117
  }
118
118
  }
119
- const A = function(i) {
119
+ const x = function(i) {
120
120
  return i.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, "");
121
- }, G = function(i) {
121
+ }, j = function(i) {
122
122
  for (const e in i)
123
123
  typeof i[e] == "function" && (i[e] = i[e].bind(i));
124
124
  };
125
- function S(i, e, t) {
125
+ function f(i, e, t) {
126
126
  if (i != null) {
127
- if (E && Array.isArray(i) && i.forEach === E)
127
+ if ($ && Array.isArray(i) && i.forEach === $)
128
128
  i.forEach(e, t);
129
129
  else if ("length" in i && i.length === +i.length) {
130
130
  for (let s = 0, n = i.length; s < n; s++)
131
- if (s in i && e.call(t, i[s], s) === T)
131
+ if (s in i && e.call(t, i[s], s) === A)
132
132
  return;
133
133
  } else
134
134
  for (const s in i)
135
- if (X.call(i, s) && e.call(t, i[s], s) === T)
135
+ if (G.call(i, s) && e.call(t, i[s], s) === A)
136
136
  return;
137
137
  }
138
138
  }
139
- const Y = function(i, ...e) {
139
+ const ee = function(i, ...e) {
140
140
  return Z(e, function(t) {
141
141
  for (const s in t)
142
142
  t[s] !== void 0 && (i[s] = t[s]);
@@ -145,18 +145,18 @@ const Y = function(i, ...e) {
145
145
  function _(i, e) {
146
146
  return i.indexOf(e) !== -1;
147
147
  }
148
- const F = function(i) {
148
+ const te = function(i) {
149
149
  try {
150
150
  return /^\s*\bfunction\b/.test(i);
151
151
  } catch {
152
152
  return !1;
153
153
  }
154
- }, j = function(i) {
154
+ }, ie = function(i) {
155
155
  return i === void 0;
156
- }, p = function() {
156
+ }, m = function() {
157
157
  const i = function(s, n, r, o, c) {
158
158
  if (!s) {
159
- h().error("No valid element provided to register_event");
159
+ g().error("No valid element provided to register_event");
160
160
  return;
161
161
  }
162
162
  if (s.addEventListener && !o)
@@ -171,7 +171,7 @@ const F = function(i) {
171
171
  if (o = o || t(window.event), !o)
172
172
  return;
173
173
  let c = !0, l;
174
- F(r) && (l = r(o));
174
+ te(r) && (l = r(o));
175
175
  const a = n.call(s, o);
176
176
  return (l === !1 || a === !1) && (c = !1), c;
177
177
  };
@@ -184,19 +184,19 @@ const F = function(i) {
184
184
  }, t.stopPropagation = function() {
185
185
  this.cancelBubble = !0;
186
186
  }, i;
187
- }(), ee = function(i) {
187
+ }(), se = function(i) {
188
188
  return function(...e) {
189
189
  try {
190
190
  return i.apply(this, e);
191
191
  } catch (t) {
192
- h().error("Implementation error. Please turn on debug and contact support@usermaven.com.", t);
192
+ g().error("Implementation error. Please turn on debug and contact support@usermaven.com.", t);
193
193
  }
194
194
  };
195
195
  }, z = function(i) {
196
196
  for (const e in i)
197
- typeof i[e] == "function" && (i[e] = ee(i[e]));
197
+ typeof i[e] == "function" && (i[e] = se(i[e]));
198
198
  };
199
- function N(i) {
199
+ function R(i) {
200
200
  for (let e in i)
201
201
  (i[e] === "" || i[e] === null || i[e] === void 0 || typeof i[e] == "object" && Object.keys(i[e]).length === 0) && delete i[e];
202
202
  return i;
@@ -205,26 +205,26 @@ function u() {
205
205
  try {
206
206
  return typeof window < "u" && window.document !== void 0 && window.document.createElement !== void 0;
207
207
  } catch {
208
- return h().warn("window is not available"), !1;
208
+ return g().warn("window is not available"), !1;
209
209
  }
210
210
  }
211
- function f(i = 5) {
211
+ function p(i = 5) {
212
212
  const e = new Uint8Array(i);
213
213
  return crypto.getRandomValues(e), Array.from(e, (t) => t.toString(36).padStart(2, "0")).join("").slice(0, i);
214
214
  }
215
- function te(i) {
215
+ function ne(i) {
216
216
  return i.replace(
217
217
  /([-_][a-z])/g,
218
218
  (e) => e.toUpperCase().replace("-", "").replace("_", "")
219
219
  );
220
220
  }
221
- function C(i) {
222
- return typeof i != "object" || i === null ? i : Array.isArray(i) ? i.map(C) : Object.keys(i).reduce((e, t) => {
223
- const s = te(t);
224
- return e[s] = C(i[t]), e;
221
+ function H(i) {
222
+ return typeof i != "object" || i === null ? i : Array.isArray(i) ? i.map(H) : Object.keys(i).reduce((e, t) => {
223
+ const s = ne(t);
224
+ return e[s] = H(i[t]), e;
225
225
  }, {});
226
226
  }
227
- function P(i) {
227
+ function E(i) {
228
228
  switch (typeof i.className) {
229
229
  case "string":
230
230
  return i.className;
@@ -234,13 +234,13 @@ function P(i) {
234
234
  return "";
235
235
  }
236
236
  }
237
- function O(i) {
237
+ function L(i) {
238
238
  let e = "";
239
- return M(i) && !q(i) && i.childNodes && i.childNodes.length && S(i.childNodes, function(t) {
240
- B(t) && t.textContent && (e += A(t.textContent).split(/(\s+)/).filter(H).join("").replace(/[\r\n]/g, " ").replace(/[ ]+/g, " ").substring(0, 255));
241
- }), A(e);
239
+ return O(i) && !M(i) && i.childNodes && i.childNodes.length && f(i.childNodes, function(t) {
240
+ B(t) && t.textContent && (e += x(t.textContent).split(/(\s+)/).filter(P).join("").replace(/[\r\n]/g, " ").replace(/[ ]+/g, " ").substring(0, 255));
241
+ }), x(e);
242
242
  }
243
- function R(i) {
243
+ function q(i) {
244
244
  return !!i && i.nodeType === 1;
245
245
  }
246
246
  function d(i, e) {
@@ -249,22 +249,22 @@ function d(i, e) {
249
249
  function B(i) {
250
250
  return !!i && i.nodeType === 3;
251
251
  }
252
- function x(i) {
252
+ function N(i) {
253
253
  return !!i && i.nodeType === 11;
254
254
  }
255
255
  const b = ["a", "button", "form", "input", "select", "textarea", "label"];
256
- function ie(i, e) {
257
- if (!i || d(i, "html") || !R(i))
256
+ function re(i, e) {
257
+ if (!i || d(i, "html") || !q(i))
258
258
  return !1;
259
259
  let t = i;
260
260
  for (; t && !d(t, "body"); ) {
261
261
  if (t.classList && t.classList.contains("um-no-capture"))
262
262
  return !1;
263
- t.parentNode && x(t.parentNode) ? t = t.parentNode.host : t = t.parentNode;
263
+ t.parentNode && N(t.parentNode) ? t = t.parentNode.host : t = t.parentNode;
264
264
  }
265
265
  let s = !1;
266
266
  for (t = i; t && !d(t, "body"); ) {
267
- if (t.parentNode && x(t.parentNode)) {
267
+ if (t.parentNode && N(t.parentNode)) {
268
268
  t = t.parentNode.host, t && b.indexOf(t.tagName.toLowerCase()) > -1 && (s = !0);
269
269
  continue;
270
270
  }
@@ -296,51 +296,42 @@ function ie(i, e) {
296
296
  return s ? e.type === "click" : e.type === "click" && (b.indexOf(r) > -1 || i.getAttribute("contenteditable") === "true");
297
297
  }
298
298
  }
299
- function M(i) {
300
- if (!i || !R(i))
301
- return !1;
302
- if (typeof i.hasAttribute == "function") {
303
- if (i.hasAttribute(w.FORCE_CAPTURE_ATTR))
304
- return !0;
305
- if (i.hasAttribute(w.PREVENT_CAPTURE_ATTR))
306
- return !1;
307
- }
308
- let e = i;
309
- for (; e && e.parentElement && !d(e, "body"); ) {
310
- const n = P(e).split(" ");
299
+ function O(i) {
300
+ for (let s = i; s.parentNode && !d(s, "body"); s = s.parentNode) {
301
+ const n = E(s).split(" ");
311
302
  if (_(n, "ph-sensitive") || _(n, "ph-no-capture"))
312
303
  return !1;
313
- e = e.parentElement;
314
304
  }
315
- if (_(P(i).split(" "), "ph-include"))
305
+ if (_(E(i).split(" "), "ph-include"))
316
306
  return !0;
317
- const t = i.type;
318
- if (typeof t == "string")
319
- switch (t.toLowerCase()) {
307
+ const e = i.type || "";
308
+ if (typeof e == "string")
309
+ switch (e.toLowerCase()) {
320
310
  case "hidden":
311
+ return !1;
321
312
  case "password":
322
313
  return !1;
323
314
  }
324
- const s = i.name || i.id || "";
325
- return !(typeof s == "string" && /^cc|cardnum|ccnum|creditcard|csc|cvc|cvv|exp|pass|pwd|routing|seccode|securitycode|securitynum|socialsec|socsec|ssn/i.test(s.replace(/[^a-zA-Z0-9]/g, "")));
315
+ const t = i.name || i.id || "";
316
+ return !(typeof t == "string" && /^cc|cardnum|ccnum|creditcard|csc|cvc|cvv|exp|pass|pwd|routing|seccode|securitycode|securitynum|socialsec|socsec|ssn/i.test(t.replace(/[^a-zA-Z0-9]/g, "")));
326
317
  }
327
- function q(i) {
318
+ function M(i) {
328
319
  const e = ["button", "checkbox", "submit", "reset"];
329
320
  return !!(d(i, "input") && !e.includes(i.type) || d(i, "select") || d(i, "textarea") || i.getAttribute("contenteditable") === "true");
330
321
  }
331
- function H(i) {
332
- return !(i === null || j(i) || typeof i == "string" && (i = A(i), /^(?:(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((i || "").replace(/[- ]/g, "")) || /(^\d{3}-?\d{2}-?\d{4}$)/.test(i)));
322
+ function P(i) {
323
+ return !(i === null || ie(i) || typeof i == "string" && (i = x(i), /^(?:(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((i || "").replace(/[- ]/g, "")) || /(^\d{3}-?\d{2}-?\d{4}$)/.test(i)));
333
324
  }
334
- function se(i) {
325
+ function oe(i) {
335
326
  return typeof i == "string" ? i.substring(0, 10) === "_ngcontent" || i.substring(0, 7) === "_nghost" : !1;
336
327
  }
337
- function $() {
338
- return f(10);
328
+ function T() {
329
+ return p(10);
339
330
  }
340
- function ne(i) {
331
+ function ae(i) {
341
332
  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(i).toLowerCase());
342
333
  }
343
- function re(i, e) {
334
+ function ce(i, e) {
344
335
  let t;
345
336
  return function(...s) {
346
337
  const n = () => {
@@ -349,7 +340,7 @@ function re(i, e) {
349
340
  clearTimeout(t), t = setTimeout(n, e);
350
341
  };
351
342
  }
352
- function oe(i) {
343
+ function le(i) {
353
344
  const e = {}, t = i.replace(/^\?/, "").split("&");
354
345
  for (let s = 0; s < t.length; s++) {
355
346
  const n = t[s].split("=");
@@ -357,21 +348,21 @@ function oe(i) {
357
348
  }
358
349
  return e;
359
350
  }
360
- function L(i) {
351
+ function I(i) {
361
352
  return typeof i == "string" || i instanceof String;
362
353
  }
363
354
  function k(i) {
364
355
  return i !== null && typeof i == "object" && i.constructor === Object;
365
356
  }
366
- function ae(i) {
357
+ function ue(i) {
367
358
  if (i === null)
368
359
  return v.ERROR;
369
360
  const e = i.toUpperCase(), t = v[e];
370
361
  return t || t === 0 ? t : v.ERROR;
371
362
  }
372
- class ce {
363
+ class he {
373
364
  constructor(e) {
374
- 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();
365
+ this.maxScrollDepth = 0, this.milestones = [25, 50, 75, 90], this.lastScrollDepth = 0, this.client = e, this.documentElement = document.documentElement, this.debouncedHandleScroll = ce(this.handleScroll.bind(this), 250), this.initializeEventListener();
375
366
  }
376
367
  initializeEventListener() {
377
368
  window.addEventListener("scroll", this.debouncedHandleScroll);
@@ -420,9 +411,9 @@ class ce {
420
411
  });
421
412
  }
422
413
  }
423
- const y = class y {
424
- constructor(e, t, s = h()) {
425
- this.logger = s, this.scrollDepth = null, this.client = e, this.options = t, this.scrollDepth = new ce(e), G(this), z(this);
414
+ const C = class C {
415
+ constructor(e, t, s = g()) {
416
+ this.logger = s, this.scrollDepth = null, this.customProperties = [], this.client = e, this.options = t, this.scrollDepth = new he(e), j(this), z(this);
426
417
  }
427
418
  init() {
428
419
  if (!(document && document.body)) {
@@ -435,7 +426,7 @@ const y = class y {
435
426
  const e = (t) => {
436
427
  t = t || window.event, this.captureEvent(t);
437
428
  };
438
- 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);
429
+ m(document, "submit", e, !1, !0), m(document, "change", e, !1, !0), m(document, "click", e, !1, !0), m(document, "visibilitychange", e, !1, !0), m(document, "scroll", e, !1, !0), m(window, "popstate", e, !1, !0);
439
430
  }
440
431
  isPageRefresh() {
441
432
  if ("PerformanceNavigationTiming" in window) {
@@ -452,63 +443,89 @@ const y = class y {
452
443
  return (s = this.scrollDepth) == null || s.track(), !0;
453
444
  if (e.type === "visibilitychange" && document.visibilityState === "hidden" || e.type === "popstate")
454
445
  return this.isPageRefresh() || (n = this.scrollDepth) == null || n.send(), !0;
455
- if (t && this.shouldCaptureElement(t, e)) {
456
- const r = this.getElementList(t), o = this.getElementsJson(r, e), c = Y(
446
+ if (t && re(t, e)) {
447
+ const r = [t];
448
+ let o = t;
449
+ for (; o.parentNode && !d(o, "body"); ) {
450
+ if (N(o.parentNode)) {
451
+ r.push(o.parentNode.host), o = o.parentNode.host;
452
+ continue;
453
+ }
454
+ r.push(o.parentNode), o = o.parentNode;
455
+ }
456
+ const c = [];
457
+ let l, a = !1;
458
+ if (f(r, (w) => {
459
+ const J = O(w);
460
+ w.tagName.toLowerCase() === "a" && (l = w.getAttribute("href"), l = J && P(l) && l);
461
+ const Q = E(w).split(" ");
462
+ _(Q, "ph-no-capture") && (a = !0), c.push(
463
+ this.getPropertiesFromElement(
464
+ w,
465
+ this.options.maskAllElementAttributes ?? !1,
466
+ this.options.maskAllText ?? !1
467
+ )
468
+ );
469
+ }), this.options.maskAllText || (c[0].$el_text = L(t)), l && (c[0].attr__href = l), a)
470
+ return !1;
471
+ const h = ee(
457
472
  this.getDefaultProperties(e.type),
458
473
  {
459
- $elements: o
460
- }
474
+ $elements: c
475
+ },
476
+ this.getCustomProperties(r)
461
477
  );
462
- return this.client.track("$autocapture", c), !0;
478
+ return this.client.track("$autocapture", h), !0;
463
479
  }
464
480
  }
465
- shouldCaptureElement(e, t) {
466
- return !e || typeof e.hasAttribute != "function" ? !1 : e.hasAttribute(y.FORCE_CAPTURE_ATTR) ? !0 : e.hasAttribute(y.PREVENT_CAPTURE_ATTR) ? !1 : ie(e, t);
481
+ getCustomProperties(e) {
482
+ const t = {};
483
+ return f(this.customProperties, (s) => {
484
+ f(s.event_selectors, (n) => {
485
+ const r = document.querySelectorAll(n);
486
+ f(r, (o) => {
487
+ _(e, o) && O(o) && (t[s.name] = this.extractCustomPropertyValue(s));
488
+ });
489
+ });
490
+ }), t;
491
+ }
492
+ extractCustomPropertyValue(e) {
493
+ const t = [];
494
+ return f(document.querySelectorAll(e.css_selector), function(s) {
495
+ let n;
496
+ ["input", "select"].indexOf(s.tagName.toLowerCase()) > -1 ? n = s.value : s.textContent && (n = s.textContent), P(n) && t.push(n);
497
+ }), t.join(", ");
467
498
  }
468
499
  getEventTarget(e) {
469
500
  var t;
470
501
  return typeof e.target > "u" ? e.srcElement || null : (t = e.target) != null && t.shadowRoot ? e.composedPath()[0] || null : e.target || null;
471
502
  }
472
- getElementList(e) {
473
- const t = [e];
474
- let s = e;
475
- for (; s.parentNode && !d(s, "body"); )
476
- x(s.parentNode) ? (t.push(s.parentNode.host), s = s.parentNode.host) : (t.push(s.parentNode), s = s.parentNode);
477
- return t;
478
- }
479
- getElementsJson(e, t) {
480
- const s = [];
481
- let n = null, r = !1;
482
- return S(e, (o) => {
483
- if (d(o, "a")) {
484
- const l = o.getAttribute("href");
485
- l !== null && M(o) && H(l) && (n = l);
486
- }
487
- const c = P(o).split(" ");
488
- _(c, "ph-no-capture") && (r = !0), s.push(this.getPropertiesFromElement(o));
489
- }), this.options.maskAllText || (s[0].$el_text = this.sanitizeText(O(e[0]))), n !== null && (s[0].attr__href = n), r ? [] : s;
490
- }
491
- getPropertiesFromElement(e) {
492
- const t = {
493
- tag_name: e.tagName.toLowerCase()
503
+ getPropertiesFromElement(e, t, s) {
504
+ const n = e.tagName.toLowerCase(), r = {
505
+ tag_name: n
494
506
  };
495
- b.indexOf(t.tag_name) > -1 && !this.options.maskAllText && (t.$el_text = this.sanitizeText(O(e)));
496
- const s = P(e);
497
- s.length > 0 && (t.classes = s.split(" ").filter((c) => c !== "")), S(e.attributes, (c) => {
498
- q(e) && ["name", "id", "class"].indexOf(c.name) === -1 || !this.options.maskAllElementAttributes && H(c.value) && !se(c.name) && (t["attr__" + c.name] = this.sanitizeAttributeValue(c.name, c.value));
507
+ b.indexOf(n) > -1 && !s && (r.$el_text = L(e));
508
+ const o = E(e);
509
+ o.length > 0 && (r.classes = o.split(" ").filter(function(h) {
510
+ return h !== "";
511
+ })), f(e.attributes, function(h) {
512
+ M(e) && ["name", "id", "class"].indexOf(h.name) === -1 || !t && P(h.value) && !oe(h.name) && (r["attr__" + h.name] = h.value);
499
513
  });
500
- let n = 1, r = 1, o = e;
501
- for (; o = this.previousElementSibling(o); )
502
- n++, o.tagName === e.tagName && r++;
503
- return t.nth_child = n, t.nth_of_type = r, t;
514
+ let c = 1, l = 1, a = e;
515
+ for (; a = this.previousElementSibling(a); )
516
+ c++, a.tagName === e.tagName && l++;
517
+ return r.nth_child = c, r.nth_of_type = l, r;
504
518
  }
505
519
  previousElementSibling(e) {
506
520
  if (e.previousElementSibling)
507
521
  return e.previousElementSibling;
508
- do
509
- e = e.previousSibling;
510
- while (e && !R(e));
511
- return e;
522
+ {
523
+ let t = e;
524
+ do
525
+ t = t.previousSibling;
526
+ while (t && !q(t));
527
+ return t;
528
+ }
512
529
  }
513
530
  getDefaultProperties(e) {
514
531
  return {
@@ -516,30 +533,6 @@ const y = class y {
516
533
  $ce_version: 1
517
534
  };
518
535
  }
519
- // Input sanitization and XSS prevention methods
520
- sanitizeText(e) {
521
- e = e.replace(/<[^>]*?>/g, ""), e = this.encodeHtml(e);
522
- const t = this.options.propertiesStringMaxLength || 255;
523
- return e.length > t && (e = e.substring(0, t) + "..."), e;
524
- }
525
- sanitizeUrl(e) {
526
- if (!e) return "";
527
- try {
528
- const t = new URL(e, window.location.href);
529
- return t.protocol !== "http:" && t.protocol !== "https:" ? "" : encodeURI(t.toString());
530
- } catch {
531
- return this.encodeHtml(e);
532
- }
533
- }
534
- sanitizeAttributeValue(e, t) {
535
- switch (e.toLowerCase()) {
536
- case "href":
537
- case "src":
538
- return this.sanitizeUrl(t);
539
- default:
540
- return this.encodeHtml(t);
541
- }
542
- }
543
536
  encodeHtml(e) {
544
537
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
545
538
  }
@@ -551,13 +544,10 @@ const y = class y {
551
544
  n += e.charCodeAt(r);
552
545
  return n % t < s;
553
546
  }
554
- static isBrowserSupported() {
555
- return F(document.querySelectorAll);
556
- }
557
547
  };
558
- y.FORCE_CAPTURE_ATTR = "data-um-force-capture", y.PREVENT_CAPTURE_ATTR = "data-um-no-capture";
559
- let w = y;
560
- class le {
548
+ C.FORCE_CAPTURE_ATTR = "data-um-force-capture", C.PREVENT_CAPTURE_ATTR = "data-um-no-capture";
549
+ let S = C;
550
+ class ge {
561
551
  constructor(e) {
562
552
  this.client = e, this.lastPageUrl = window.location.href, this.trackInitialPageview(), this.initializePageviewTracking();
563
553
  }
@@ -586,8 +576,8 @@ class le {
586
576
  }));
587
577
  }
588
578
  }
589
- class ue {
590
- constructor(e, t, s = h()) {
579
+ class de {
580
+ constructor(e, t, s = g()) {
591
581
  this.trackingHost = e, this.logger = s, this.config = t;
592
582
  }
593
583
  async send(e) {
@@ -599,13 +589,13 @@ class ue {
599
589
  }
600
590
  constructUrl(e) {
601
591
  const t = this.config.cookiePolicy !== "keep" ? `&cookie_policy=${this.config.cookiePolicy}` : "", s = this.config.ipPolicy !== "keep" ? `&ip_policy=${this.config.ipPolicy}` : "", n = u() ? "/api/v1/event" : "/api/v1/s2s/event";
602
- return this.config.randomizeUrl ? `${this.trackingHost}/api.${f()}?p_${f()}=${e}${t}${s}` : `${this.trackingHost}${n}?token=${e}${t}${s}`;
592
+ return this.config.randomizeUrl ? `${this.trackingHost}/api.${p()}?p_${p()}=${e}${t}${s}` : `${this.trackingHost}${n}?token=${e}${t}${s}`;
603
593
  }
604
594
  // Note: Beacon API doesn't support custom headers, so we can't use them here.
605
595
  // If custom headers are crucial, you might want to fall back to XHR or Fetch in those cases.
606
596
  }
607
- class U {
608
- constructor(e, t, s = h()) {
597
+ class D {
598
+ constructor(e, t, s = g()) {
609
599
  this.trackingHost = e, this.logger = s, this.config = t;
610
600
  }
611
601
  async send(e) {
@@ -623,7 +613,7 @@ class U {
623
613
  }
624
614
  constructUrl(e) {
625
615
  const t = this.config.cookiePolicy !== "keep" ? `&cookie_policy=${this.config.cookiePolicy}` : "", s = this.config.ipPolicy !== "keep" ? `&ip_policy=${this.config.ipPolicy}` : "", n = u() ? "/api/v1/event" : "/api/v1/s2s/event";
626
- return this.config.randomizeUrl ? `${this.trackingHost}/api.${f()}?p_${f()}=${e}${t}${s}` : `${this.trackingHost}${n}?token=${e}${t}${s}`;
616
+ return this.config.randomizeUrl ? `${this.trackingHost}/api.${p()}?p_${p()}=${e}${t}${s}` : `${this.trackingHost}${n}?token=${e}${t}${s}`;
627
617
  }
628
618
  getCustomHeaders() {
629
619
  return typeof this.config.customHeaders == "function" ? this.config.customHeaders() : this.config.customHeaders ? this.config.customHeaders : {};
@@ -632,8 +622,8 @@ class U {
632
622
  this.logger.debug(`Response received. Status: ${e}, Body: ${t}`);
633
623
  }
634
624
  }
635
- class he {
636
- constructor(e, t, s = h()) {
625
+ class fe {
626
+ constructor(e, t, s = g()) {
637
627
  this.trackingHost = e, this.logger = s, this.config = t;
638
628
  }
639
629
  send(e) {
@@ -652,7 +642,7 @@ class he {
652
642
  }
653
643
  constructUrl(e) {
654
644
  const t = this.config.cookiePolicy !== "keep" ? `&cookie_policy=${this.config.cookiePolicy}` : "", s = this.config.ipPolicy !== "keep" ? `&ip_policy=${this.config.ipPolicy}` : "", n = u() ? "/api/v1/event" : "/api/v1/s2s/event";
655
- return this.config.randomizeUrl ? `${this.trackingHost}/api.${f()}?p_${f()}=${e}${t}${s}` : `${this.trackingHost}${n}?token=${e}${t}${s}`;
645
+ return this.config.randomizeUrl ? `${this.trackingHost}/api.${p()}?p_${p()}=${e}${t}${s}` : `${this.trackingHost}${n}?token=${e}${t}${s}`;
656
646
  }
657
647
  getCustomHeaders() {
658
648
  return typeof this.config.customHeaders == "function" ? this.config.customHeaders() : this.config.customHeaders ? this.config.customHeaders : {};
@@ -661,9 +651,9 @@ class he {
661
651
  this.logger.debug(`Response received. Status: ${e}, Body: ${t}`);
662
652
  }
663
653
  }
664
- class J {
654
+ class V {
665
655
  constructor(e, t) {
666
- this.storage = {}, this.prefix = `usermaven_${e}_`, this.load(), this.logger = t || h();
656
+ this.storage = {}, this.prefix = `usermaven_${e}_`, this.load(), this.logger = t || g();
667
657
  }
668
658
  set(e, t) {
669
659
  this.storage[e] = t, this.save();
@@ -701,7 +691,7 @@ class J {
701
691
  }
702
692
  }
703
693
  }
704
- class ge {
694
+ class pe {
705
695
  constructor() {
706
696
  this.storage = {};
707
697
  }
@@ -720,10 +710,10 @@ class ge {
720
710
  this.storage = {};
721
711
  }
722
712
  }
723
- class D {
713
+ class F {
724
714
  // Default to true for server-side
725
- constructor(e, t = 3, s = 1e3, n = 10, r = 1e3, o = h()) {
726
- this.transport = e, this.maxRetries = t, this.retryInterval = s, this.batchSize = n, this.batchInterval = r, this.logger = o, this.queue = [], this.processing = !1, this.batchTimeoutId = null, this.isOnline = !0, this.persistence = new J("offline_queue"), u() && (this.isOnline = navigator.onLine, this.loadQueueFromStorage(), this.initNetworkListeners(), this.scheduleBatch());
715
+ constructor(e, t = 3, s = 1e3, n = 10, r = 1e3, o = g()) {
716
+ this.transport = e, this.maxRetries = t, this.retryInterval = s, 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());
727
717
  }
728
718
  add(e) {
729
719
  const t = { payload: e, retries: 0, timestamp: Date.now() };
@@ -767,7 +757,7 @@ class D {
767
757
  u() && this.persistence.set("queue", JSON.stringify(this.queue));
768
758
  }
769
759
  }
770
- class de {
760
+ class me {
771
761
  constructor(e) {
772
762
  this.clicks = [], this.threshold = 3, this.timeWindow = 2e3, this.distanceThreshold = 30, this.client = e, this.initializeEventListener(), z(this);
773
763
  }
@@ -801,8 +791,8 @@ class de {
801
791
  }), this.clicks = [];
802
792
  }
803
793
  }
804
- class fe {
805
- constructor(e, t, s = h()) {
794
+ class ye {
795
+ constructor(e, t, s = g()) {
806
796
  this.trackingHost = e, this.logger = s, this.config = t;
807
797
  }
808
798
  async send(e) {
@@ -837,7 +827,7 @@ class fe {
837
827
  return typeof this.config.customHeaders == "function" ? this.config.customHeaders() : this.config.customHeaders ? this.config.customHeaders : {};
838
828
  }
839
829
  }
840
- class m {
830
+ class y {
841
831
  constructor(e, t = "all", s = {}) {
842
832
  this.instance = e, this.trackingType = t, this.options = s, document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", this.initialize.bind(this)) : this.initialize();
843
833
  }
@@ -852,18 +842,18 @@ class m {
852
842
  }
853
843
  handleFormSubmit(e) {
854
844
  const t = e.target, s = this._getFormDetails(t);
855
- this.instance.track("$form", N(s)), this.options.trackFieldChanges && this.trackFieldChanges(t);
845
+ this.instance.track("$form", R(s)), this.options.trackFieldChanges && this.trackFieldChanges(t);
856
846
  }
857
847
  trackFieldChanges(e) {
858
848
  e.querySelectorAll("input, select, textarea").forEach((s) => {
859
849
  s.addEventListener("change", (n) => {
860
850
  const r = this._getFieldProps(n.target, 0);
861
- this.instance.track("$form_field_change", N(r));
851
+ this.instance.track("$form_field_change", R(r));
862
852
  });
863
853
  });
864
854
  }
865
855
  static getInstance(e, t = "all", s = {}) {
866
- return m.instance || (m.instance = new m(e, t, s)), m.instance;
856
+ return y.instance || (y.instance = new y(e, t, s)), y.instance;
867
857
  }
868
858
  _getFormDetails(e) {
869
859
  const t = {
@@ -951,9 +941,9 @@ class m {
951
941
  return e.slice(t, s + 1);
952
942
  }
953
943
  }
954
- class pe {
944
+ class we {
955
945
  constructor(e) {
956
- 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 D(
946
+ this.config = this.mergeConfig(e, U), this.logger = g(this.config.logLevel), this.namespace = e.namespace || "usermaven", this.transport = this.initializeTransport(this.config), this.persistence = this.initializePersistence(), this.retryQueue = new F(
957
947
  this.transport,
958
948
  this.config.maxSendAttempts || 3,
959
949
  this.config.minSendTimeout || 1e3,
@@ -964,13 +954,13 @@ class pe {
964
954
  ), u() && this.initializeBrowserFeatures(), this.anonymousId = this.getOrCreateAnonymousId(), this.logger.info(`Usermaven client initialized for namespace: ${this.namespace}`);
965
955
  }
966
956
  initializeBrowserFeatures() {
967
- 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) {
957
+ if (this.cookieManager = new X(this.config.cookieDomain), this.config.autocapture && S.enabledForProject(this.config.key) && (this.autoCapture = new S(this, this.config, this.logger), this.autoCapture.init()), this.config.formTracking) {
968
958
  const e = this.config.formTracking === !0 ? "all" : this.config.formTracking;
969
- this.formTracking = m.getInstance(this, e || "none", {
959
+ this.formTracking = y.getInstance(this, e || "none", {
970
960
  trackFieldChanges: !1
971
961
  });
972
962
  }
973
- this.config.autoPageview && (this.pageviewTracking = new le(this)), this.config.crossDomainLinking && this.manageCrossDomainLinking(), this.config.rageClick && (this.rageClick = new de(this)), this.setupPageLeaveTracking();
963
+ this.config.autoPageview && (this.pageviewTracking = new ge(this)), this.config.crossDomainLinking && this.manageCrossDomainLinking(), this.config.rageClick && (this.rageClick = new me(this)), this.setupPageLeaveTracking();
974
964
  }
975
965
  /**
976
966
  * Recursively merge the provided configuration with the existing defaultConfig
@@ -985,7 +975,7 @@ class pe {
985
975
  }), n;
986
976
  }
987
977
  init(e) {
988
- 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 D(
978
+ this.config = { ...this.config, ...e }, this.logger = g(this.config.logLevel), this.namespace = e.namespace || this.namespace, this.transport = this.initializeTransport(e), this.persistence = this.initializePersistence(), this.retryQueue = new F(
989
979
  this.transport,
990
980
  this.config.maxSendAttempts || 3,
991
981
  this.config.minSendTimeout || 1e3,
@@ -1019,58 +1009,46 @@ class pe {
1019
1009
  }
1020
1010
  initializeTransport(e) {
1021
1011
  if (!u())
1022
- return new fe(e.trackingHost, e);
1012
+ return new ye(e.trackingHost, e);
1023
1013
  const t = "XMLHttpRequest" in window, s = typeof fetch < "u", n = typeof navigator < "u" && "sendBeacon" in navigator;
1024
1014
  if (e.useBeaconApi && n)
1025
- return new ue(e.trackingHost, e, this.logger);
1015
+ return new de(e.trackingHost, e, this.logger);
1026
1016
  if (e.forceUseFetch && s)
1027
- return new U(e.trackingHost, e, this.logger);
1017
+ return new D(e.trackingHost, e, this.logger);
1028
1018
  if (t)
1029
- return new he(e.trackingHost, e, this.logger);
1019
+ return new fe(e.trackingHost, e, this.logger);
1030
1020
  if (s)
1031
- return new U(e.trackingHost, e, this.logger);
1021
+ return new D(e.trackingHost, e, this.logger);
1032
1022
  throw new Error("No suitable transport method available");
1033
1023
  }
1034
1024
  initializePersistence() {
1035
- return this.config.disableEventPersistence || !u() ? new ge() : new J(`${this.namespace}_${this.config.key}`, this.logger);
1025
+ return this.config.disableEventPersistence || !u() ? new pe() : new V(`${this.namespace}_${this.config.key}`, this.logger);
1036
1026
  }
1037
1027
  getOrCreateAnonymousId() {
1038
1028
  var s, n;
1039
1029
  if (!u())
1040
- return $();
1030
+ return T();
1041
1031
  if (this.config.privacyPolicy === "strict" || this.config.cookiePolicy === "strict")
1042
- return this.generateFingerprint();
1032
+ return "";
1043
1033
  const e = this.config.cookieName || `${this.namespace}_id_${this.config.key}`;
1044
1034
  let t = (s = this.cookieManager) == null ? void 0 : s.get(e);
1045
1035
  if (!t) {
1046
1036
  if (this.config.crossDomainLinking) {
1047
- const c = new URLSearchParams(window.location.search).get("_um"), a = window.location.hash.substring(1).split("~"), g = a.length > 1 ? a[1] : void 0;
1048
- t = c || g || $();
1037
+ const c = new URLSearchParams(window.location.search).get("_um"), a = window.location.hash.substring(1).split("~"), h = a.length > 1 ? a[1] : void 0;
1038
+ t = c || h || T();
1049
1039
  }
1050
- t || (t = $());
1040
+ t || (t = T());
1051
1041
  const r = 365 * 10;
1052
1042
  (n = this.cookieManager) == null || n.set(e, t, r, document.location.protocol !== "http:", !1);
1053
1043
  }
1054
1044
  return t;
1055
1045
  }
1056
- generateFingerprint() {
1057
- const e = navigator.userAgent, t = `${screen.width}x${screen.height}`, s = screen.colorDepth, n = Intl.DateTimeFormat().resolvedOptions().timeZone, r = `${e}|${t}|${s}|${n}`;
1058
- return this.hashString(r);
1059
- }
1060
- hashString(e) {
1061
- let t = 0;
1062
- for (let s = 0; s < e.length; s++) {
1063
- const n = e.charCodeAt(s);
1064
- t = (t << 5) - t + n, t = t & t;
1065
- }
1066
- return t.toString(36);
1067
- }
1068
1046
  async id(e, t = !1) {
1069
1047
  if (!k(e))
1070
1048
  throw new Error("User data must be an object");
1071
- if (e.email && !ne(e.email))
1049
+ if (e.email && !ae(e.email))
1072
1050
  throw new Error("Invalid email provided");
1073
- if (!e.id || !L(e.id))
1051
+ if (!e.id || !I(e.id))
1074
1052
  throw new Error("User ID must be a string");
1075
1053
  const s = e.id;
1076
1054
  if (this.persistence.set("userId", s), this.persistence.set("userProps", e), !t) {
@@ -1086,7 +1064,7 @@ class pe {
1086
1064
  this.trackInternal(e, t, s);
1087
1065
  }
1088
1066
  trackInternal(e, t, s = !1) {
1089
- if (!L(e))
1067
+ if (!I(e))
1090
1068
  throw new Error("Event name must be a string");
1091
1069
  if (t !== void 0 && (typeof t != "object" || t === null || Array.isArray(t)))
1092
1070
  throw new Error("Event payload must be a non-null object and not an array");
@@ -1135,11 +1113,11 @@ class pe {
1135
1113
  ...c
1136
1114
  };
1137
1115
  if (e === "$autocapture") {
1138
- const g = this.processAutocaptureAttributes(t || {});
1139
- a.autocapture_attributes = g;
1116
+ const h = this.processAutocaptureAttributes(t || {});
1117
+ a.autocapture_attributes = h;
1140
1118
  } else
1141
- Array.isArray(this.config.propertyBlacklist) && this.config.propertyBlacklist.forEach((g) => {
1142
- delete l[g];
1119
+ Array.isArray(this.config.propertyBlacklist) && this.config.propertyBlacklist.forEach((h) => {
1120
+ delete l[h];
1143
1121
  }), a.event_attributes = l;
1144
1122
  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;
1145
1123
  }
@@ -1163,7 +1141,7 @@ class pe {
1163
1141
  return e;
1164
1142
  }
1165
1143
  getUtmParams() {
1166
- const e = {}, t = oe(window.location.search);
1144
+ const e = {}, t = le(window.location.search);
1167
1145
  return ["utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content"].forEach((n) => {
1168
1146
  t[n] && (e[n.replace("utm_", "")] = t[n]);
1169
1147
  }), e;
@@ -1244,20 +1222,20 @@ class pe {
1244
1222
  n && this.persistence.save(), this.logger.debug(`Property unset: ${e}`, `Event type: ${s || "global"}`);
1245
1223
  }
1246
1224
  }
1247
- function me(i) {
1248
- const e = JSON.parse(JSON.stringify(i)), t = C(e), s = { ...I, ...t };
1225
+ function ke(i) {
1226
+ const e = JSON.parse(JSON.stringify(i)), t = H(e), s = { ...U, ...t };
1249
1227
  if (!s.key)
1250
1228
  throw new Error("API key is required!");
1251
1229
  if (!s.trackingHost)
1252
1230
  throw new Error("Tracking host is required!");
1253
- return new pe(s);
1231
+ return new we(s);
1254
1232
  }
1255
- function ye(i) {
1233
+ function ve(i) {
1256
1234
  var n;
1257
1235
  const e = {
1258
1236
  key: i.getAttribute("data-key") || void 0,
1259
1237
  trackingHost: i.getAttribute("data-tracking-host") || "https://events.usermaven.com",
1260
- logLevel: ae(i.getAttribute("data-log-level")),
1238
+ logLevel: ue(i.getAttribute("data-log-level")),
1261
1239
  autocapture: i.getAttribute("data-autocapture") === "true",
1262
1240
  formTracking: i.getAttribute("data-form-tracking") === "false" ? !1 : i.getAttribute("data-form-tracking") === "true" ? "all" : i.getAttribute("data-form-tracking"),
1263
1241
  autoPageview: i.getAttribute("data-auto-pageview") === "true",
@@ -1282,10 +1260,10 @@ function ye(i) {
1282
1260
  domains: i.getAttribute("data-domains") || void 0,
1283
1261
  maskAllText: i.getAttribute("data-mask-all-text") === "true",
1284
1262
  maskAllElementAttributes: i.getAttribute("data-mask-all-element-attributes") === "true"
1285
- }, t = me(e), s = e.namespace || "usermaven";
1286
- u() && t.pageview(), we(s, t);
1263
+ }, t = ke(e), s = e.namespace || "usermaven";
1264
+ u() && t.pageview(), _e(s, t);
1287
1265
  }
1288
- function we(i, e) {
1266
+ function _e(i, e) {
1289
1267
  let t = !1;
1290
1268
  const s = [], n = [];
1291
1269
  function r() {
@@ -1298,8 +1276,8 @@ function we(i, e) {
1298
1276
  n.forEach((a) => a()), n.length = 0;
1299
1277
  }
1300
1278
  window[i] = function(...a) {
1301
- const g = a[0];
1302
- if (g === "onLoad") {
1279
+ const h = a[0];
1280
+ if (h === "onLoad") {
1303
1281
  typeof a[1] == "function" && (t ? a[1]() : n.push(a[1]));
1304
1282
  return;
1305
1283
  }
@@ -1307,9 +1285,9 @@ function we(i, e) {
1307
1285
  s.push(a);
1308
1286
  return;
1309
1287
  }
1310
- if (typeof e[g] == "function")
1311
- return e[g].apply(e, a.slice(1));
1312
- console.error(`Method ${g} not found on UsermavenClient`);
1288
+ if (typeof e[h] == "function")
1289
+ return e[h].apply(e, a.slice(1));
1290
+ console.error(`Method ${h} not found on UsermavenClient`);
1313
1291
  };
1314
1292
  const c = `${i}Q`, l = window[c] || [];
1315
1293
  for (window[c] = l, l.push = function(...a) {
@@ -1324,13 +1302,13 @@ function we(i, e) {
1324
1302
  u() && function(i, e) {
1325
1303
  const t = i.currentScript;
1326
1304
  function s() {
1327
- t && t.src.includes("lib.js") && ye(t);
1305
+ t && t.src.includes("lib.js") && ve(t);
1328
1306
  }
1329
1307
  typeof e < "u" && (i.readyState === "loading" ? i.addEventListener("DOMContentLoaded", s) : s());
1330
1308
  }(document, window);
1331
1309
 
1332
1310
  function createClient(params) {
1333
- return me(params);
1311
+ return ke(params);
1334
1312
  }
1335
1313
 
1336
1314
  function useUsermaven() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usermaven/nextjs",
3
- "version": "1.4.1-rc.61",
3
+ "version": "1.4.1-rc.63",
4
4
  "description": "Usermaven JavaScript SDK for NextJS",
5
5
  "author": "Usermaven <hello@usermaven.com>",
6
6
  "license": "MIT",
@@ -18,7 +18,7 @@
18
18
  "access": "public"
19
19
  },
20
20
  "dependencies": {
21
- "@usermaven/sdk-js": "1.4.1-rc.61",
21
+ "@usermaven/sdk-js": "1.4.1-rc.63",
22
22
  "cookie": "^0.5.0"
23
23
  },
24
24
  "peerDependencies": {