@usermaven/nextjs 1.5.9 → 1.5.10-rc.108

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 +82 -68
  2. package/package.json +2 -2
package/lib/index.es.js CHANGED
@@ -104,14 +104,14 @@ class ne {
104
104
  return i ? i[0] : "";
105
105
  }
106
106
  }
107
- const se = Object.prototype, re = se.hasOwnProperty, oe = Array.prototype, T = oe.forEach, L = {};
107
+ const se = Object.prototype, re = se.hasOwnProperty, oe = Array.prototype, $ = oe.forEach, U = {};
108
108
  function ae(n, e, t) {
109
109
  if (Array.isArray(n)) {
110
- if (T && n.forEach === T)
110
+ if ($ && n.forEach === $)
111
111
  n.forEach(e, t);
112
112
  else if ("length" in n && n.length === +n.length) {
113
113
  for (let i = 0, s = n.length; i < s; i++)
114
- if (i in n && e.call(t, n[i], i) === L)
114
+ if (i in n && e.call(t, n[i], i) === U)
115
115
  return;
116
116
  }
117
117
  }
@@ -124,15 +124,15 @@ const D = function(n) {
124
124
  };
125
125
  function w(n, e, t) {
126
126
  if (n != null) {
127
- if (T && Array.isArray(n) && n.forEach === T)
127
+ if ($ && Array.isArray(n) && n.forEach === $)
128
128
  n.forEach(e, t);
129
129
  else if ("length" in n && n.length === +n.length) {
130
130
  for (let i = 0, s = n.length; i < s; i++)
131
- if (i in n && e.call(t, n[i], i) === L)
131
+ if (i in n && e.call(t, n[i], i) === U)
132
132
  return;
133
133
  } else
134
134
  for (const i in n)
135
- if (re.call(n, i) && e.call(t, n[i], i) === L)
135
+ if (re.call(n, i) && e.call(t, n[i], i) === U)
136
136
  return;
137
137
  }
138
138
  }
@@ -142,7 +142,7 @@ const le = function(n, ...e) {
142
142
  t[i] !== void 0 && (n[i] = t[i]);
143
143
  }), n;
144
144
  };
145
- function $(n, e) {
145
+ function S(n, e) {
146
146
  return n.indexOf(e) !== -1;
147
147
  }
148
148
  const ue = function(n) {
@@ -237,7 +237,7 @@ function x(n) {
237
237
  function V(n) {
238
238
  let e = "";
239
239
  return M(n) && !j(n) && n.childNodes && n.childNodes.length && w(n.childNodes, function(t) {
240
- G(t) && t.textContent && (e += D(t.textContent).split(/(\s+)/).filter(C).join("").replace(/[\r\n]/g, " ").replace(/[ ]+/g, " ").substring(0, 255));
240
+ G(t) && t.textContent && (e += D(t.textContent).split(/(\s+)/).filter(T).join("").replace(/[\r\n]/g, " ").replace(/[ ]+/g, " ").substring(0, 255));
241
241
  }), D(e);
242
242
  }
243
243
  function Y(n) {
@@ -252,7 +252,7 @@ function G(n) {
252
252
  function z(n) {
253
253
  return !!n && n.nodeType === 11;
254
254
  }
255
- const S = ["a", "button", "form", "input", "select", "textarea", "label"];
255
+ const C = ["a", "button", "form", "input", "select", "textarea", "label"];
256
256
  function ge(n, e) {
257
257
  if (!n || y(n, "html") || !Y(n))
258
258
  return !1;
@@ -265,12 +265,12 @@ function ge(n, e) {
265
265
  let i = !1;
266
266
  for (t = n; t && !y(t, "body"); ) {
267
267
  if (t.parentNode && z(t.parentNode)) {
268
- t = t.parentNode.host, t && S.indexOf(t.tagName.toLowerCase()) > -1 && (i = !0);
268
+ t = t.parentNode.host, t && C.indexOf(t.tagName.toLowerCase()) > -1 && (i = !0);
269
269
  continue;
270
270
  }
271
271
  const o = t.parentNode;
272
272
  if (!o) break;
273
- if (S.indexOf(o.tagName.toLowerCase()) > -1)
273
+ if (C.indexOf(o.tagName.toLowerCase()) > -1)
274
274
  i = !0;
275
275
  else {
276
276
  const a = window.getComputedStyle(o);
@@ -293,16 +293,16 @@ function ge(n, e) {
293
293
  case "textarea":
294
294
  return e.type === "change" || e.type === "click";
295
295
  default:
296
- return i ? e.type === "click" : e.type === "click" && (S.indexOf(r) > -1 || n.getAttribute("contenteditable") === "true");
296
+ return i ? e.type === "click" : e.type === "click" && (C.indexOf(r) > -1 || n.getAttribute("contenteditable") === "true");
297
297
  }
298
298
  }
299
299
  function M(n) {
300
300
  for (let i = n; i.parentNode && !y(i, "body"); i = i.parentNode) {
301
301
  const s = x(i).split(" ");
302
- if ($(s, "ph-sensitive") || $(s, "ph-no-capture"))
302
+ if (S(s, "ph-sensitive") || S(s, "ph-no-capture"))
303
303
  return !1;
304
304
  }
305
- if ($(x(n).split(" "), "ph-include"))
305
+ if (S(x(n).split(" "), "ph-include"))
306
306
  return !0;
307
307
  const e = n.type || "";
308
308
  if (typeof e == "string")
@@ -319,13 +319,13 @@ function j(n) {
319
319
  const e = ["button", "checkbox", "submit", "reset"];
320
320
  return !!(y(n, "input") && !e.includes(n.type) || y(n, "select") || y(n, "textarea") || n.getAttribute("contenteditable") === "true");
321
321
  }
322
- function C(n) {
322
+ function T(n) {
323
323
  return !(n === null || he(n) || typeof n == "string" && (n = D(n), /^(?:(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((n || "").replace(/[- ]/g, "")) || /(^\d{3}-?\d{2}-?\d{4}$)/.test(n)));
324
324
  }
325
325
  function pe(n) {
326
326
  return typeof n == "string" ? n.substring(0, 10) === "_ngcontent" || n.substring(0, 7) === "_nghost" : !1;
327
327
  }
328
- function O() {
328
+ function R() {
329
329
  return v(10);
330
330
  }
331
331
  function me(n) {
@@ -348,7 +348,7 @@ function we(n) {
348
348
  }
349
349
  return e;
350
350
  }
351
- function J(n) {
351
+ function Q(n) {
352
352
  return typeof n == "string" || n instanceof String;
353
353
  }
354
354
  function A(n) {
@@ -414,8 +414,11 @@ class _e {
414
414
  this.send(), this.milestones = this.milestones.filter((s) => s !== i);
415
415
  });
416
416
  }
417
+ destroy() {
418
+ window.removeEventListener("scroll", this.debouncedHandleScroll);
419
+ }
417
420
  }
418
- const R = class R {
421
+ const I = class I {
419
422
  constructor(e, t, i = f()) {
420
423
  this.logger = i, this.scrollDepth = null, this.customProperties = [], this.domHandlersAttached = !1, this.client = e, this.options = t, this.scrollDepth = new _e(e), ce(this), Z(this);
421
424
  }
@@ -472,9 +475,9 @@ const R = class R {
472
475
  let l, c = !1;
473
476
  if (w(r, (p) => {
474
477
  const _ = M(p);
475
- p.tagName.toLowerCase() === "a" && (l = p.getAttribute("href"), l = _ && C(l) && l);
478
+ p.tagName.toLowerCase() === "a" && (l = p.getAttribute("href"), l = _ && T(l) && l);
476
479
  const u = x(p).split(" ");
477
- $(u, "ph-no-capture") && (c = !0), a.push(
480
+ S(u, "ph-no-capture") && (c = !0), a.push(
478
481
  this.getPropertiesFromElement(
479
482
  p,
480
483
  this.options.maskAllElementAttributes ?? !1,
@@ -499,7 +502,7 @@ const R = class R {
499
502
  w(i.event_selectors, (s) => {
500
503
  const r = document.querySelectorAll(s);
501
504
  w(r, (o) => {
502
- $(e, o) && M(o) && (t[i.name] = this.extractCustomPropertyValue(i));
505
+ S(e, o) && M(o) && (t[i.name] = this.extractCustomPropertyValue(i));
503
506
  });
504
507
  });
505
508
  }), t;
@@ -508,7 +511,7 @@ const R = class R {
508
511
  const t = [];
509
512
  return w(document.querySelectorAll(e.css_selector), function(i) {
510
513
  let s;
511
- ["input", "select"].indexOf(i.tagName.toLowerCase()) > -1 ? s = i.value : i.textContent && (s = i.textContent), C(s) && t.push(s);
514
+ ["input", "select"].indexOf(i.tagName.toLowerCase()) > -1 ? s = i.value : i.textContent && (s = i.textContent), T(s) && t.push(s);
512
515
  }), t.join(", ");
513
516
  }
514
517
  getEventTarget(e) {
@@ -519,12 +522,12 @@ const R = class R {
519
522
  const s = e.tagName.toLowerCase(), r = {
520
523
  tag_name: s
521
524
  };
522
- S.indexOf(s) > -1 && !i && (r.$el_text = V(e));
525
+ C.indexOf(s) > -1 && !i && (r.$el_text = V(e));
523
526
  const o = x(e);
524
527
  o.length > 0 && (r.classes = o.split(" ").filter(function(d) {
525
528
  return d !== "";
526
529
  })), w(e.attributes, function(d) {
527
- j(e) && ["name", "id", "class"].indexOf(d.name) === -1 || !t && C(d.value) && !pe(d.name) && (r["attr__" + d.name] = d.value);
530
+ j(e) && ["name", "id", "class"].indexOf(d.name) === -1 || !t && T(d.value) && !pe(d.name) && (r["attr__" + d.name] = d.value);
528
531
  });
529
532
  let a = 1, l = 1, c = e;
530
533
  for (; c = this.previousElementSibling(c); )
@@ -560,8 +563,8 @@ const R = class R {
560
563
  return s % t < i;
561
564
  }
562
565
  };
563
- R.FORCE_CAPTURE_ATTR = "data-um-force-capture", R.PREVENT_CAPTURE_ATTR = "data-um-no-capture";
564
- let H = R;
566
+ I.FORCE_CAPTURE_ATTR = "data-um-force-capture", I.PREVENT_CAPTURE_ATTR = "data-um-no-capture";
567
+ let H = I;
565
568
  class be {
566
569
  constructor(e) {
567
570
  this.client = e, this.lastPageUrl = window.location.href, this.trackInitialPageview(), this.initializePageviewTracking();
@@ -609,7 +612,7 @@ class Ee {
609
612
  // Note: Beacon API doesn't support custom headers, so we can't use them here.
610
613
  // If custom headers are crucial, you might want to fall back to XHR or Fetch in those cases.
611
614
  }
612
- class Q {
615
+ class J {
613
616
  constructor(e, t, i = f()) {
614
617
  this.trackingHost = e, this.logger = i, this.config = t;
615
618
  }
@@ -772,7 +775,7 @@ class W {
772
775
  h() && this.persistence.set("queue", JSON.stringify(this.queue));
773
776
  }
774
777
  }
775
- class $e {
778
+ class Se {
776
779
  constructor(e) {
777
780
  this.clicks = [], this.threshold = 3, this.timeWindow = 2e3, this.distanceThreshold = 30, this.client = e, this.initializeEventListener(), Z(this);
778
781
  }
@@ -806,7 +809,7 @@ class $e {
806
809
  }), this.clicks = [];
807
810
  }
808
811
  }
809
- class Se {
812
+ class Ce {
810
813
  constructor(e, t, i = f()) {
811
814
  this.trackingHost = e, this.logger = i, this.config = t;
812
815
  }
@@ -862,8 +865,12 @@ class P {
862
865
  trackFieldChanges(e) {
863
866
  e.querySelectorAll("input, select, textarea").forEach((i) => {
864
867
  i.addEventListener("change", (s) => {
865
- const r = this._getFieldProps(s.target, 0);
866
- this.instance.track("$form_field_change", q(r));
868
+ const r = this._getFieldProps(s.target);
869
+ this.instance.track("$form_field_change", q({
870
+ form_id: e.id,
871
+ form_name: e.name || "",
872
+ field: r
873
+ }));
867
874
  });
868
875
  });
869
876
  }
@@ -877,28 +884,35 @@ class P {
877
884
  form_action: e.action,
878
885
  form_method: e.method,
879
886
  form_class: e.className,
880
- form_attributes: this._getElementAttributes(e)
887
+ form_attributes: this._getElementAttributes(e),
888
+ fields: []
881
889
  }, i = e.querySelectorAll("input, select, textarea");
882
- return Array.from(i).filter((r) => !r.classList.contains("um-no-capture")).forEach((r, o) => {
883
- const a = this._getFieldProps(r, o);
884
- Object.assign(t, a);
890
+ return Array.from(i).filter((r) => !r.classList.contains("um-no-capture")).forEach((r) => {
891
+ const o = this._getFieldProps(r);
892
+ t.fields.push(o);
885
893
  }), t;
886
894
  }
887
- _getFieldProps(e, t) {
888
- const i = Object.keys(e.dataset).length ? JSON.stringify(e.dataset) : void 0, s = this.getSafeText(e);
895
+ _getFieldProps(e) {
896
+ const t = Object.keys(e.dataset).length ? this._convertDOMStringMapToObject(e.dataset) : void 0, i = this.getSafeText(e);
889
897
  return {
890
- [`field_${t + 1}_tag`]: e.tagName.toLowerCase(),
891
- [`field_${t + 1}_type`]: e instanceof HTMLInputElement ? e.type : void 0,
892
- [`field_${t + 1}_data_attributes`]: i,
893
- [`field_${t + 1}_id`]: e.id,
894
- [`field_${t + 1}_value`]: s,
895
- [`field_${t + 1}_class`]: e.className,
896
- [`field_${t + 1}_name`]: e.name,
897
- [`field_${t + 1}_attributes`]: this._getElementAttributes(e)
898
+ tag: e.tagName.toLowerCase(),
899
+ type: e instanceof HTMLInputElement ? e.type : void 0,
900
+ data_attributes: t,
901
+ id: e.id,
902
+ value: i,
903
+ class: e.className,
904
+ name: e.name,
905
+ attributes: this._getElementAttributes(e)
898
906
  };
899
907
  }
900
908
  _getElementAttributes(e) {
901
- return Object.keys(e.dataset).length ? JSON.parse(JSON.stringify(e.dataset)) : {};
909
+ return Object.keys(e.dataset).length ? this._convertDOMStringMapToObject(e.dataset) : {};
910
+ }
911
+ _convertDOMStringMapToObject(e) {
912
+ const t = {};
913
+ for (const i in e)
914
+ e.hasOwnProperty(i) && e[i] !== void 0 && (t[i] = e[i]);
915
+ return t;
902
916
  }
903
917
  getSafeText(e) {
904
918
  let t = "";
@@ -976,7 +990,7 @@ class N {
976
990
  trackFieldChanges: !1
977
991
  });
978
992
  }
979
- this.config.autoPageview && (this.pageviewTracking = new be(this)), this.config.crossDomainLinking && this.manageCrossDomainLinking(), this.config.rageClick && (this.rageClick = new $e(this)), this.setupPageLeaveTracking();
993
+ this.config.autoPageview && (this.pageviewTracking = new be(this)), this.config.crossDomainLinking && this.manageCrossDomainLinking(), this.config.rageClick && (this.rageClick = new Se(this)), this.setupPageLeaveTracking();
980
994
  }
981
995
  /**
982
996
  * Recursively merge the provided configuration with the existing defaultConfig
@@ -1027,16 +1041,16 @@ class N {
1027
1041
  initializeTransport(e) {
1028
1042
  const t = "https://events.usermaven.com";
1029
1043
  if (!h())
1030
- return new Se(e.trackingHost || t, e);
1044
+ return new Ce(e.trackingHost || t, e);
1031
1045
  const i = "XMLHttpRequest" in window, s = typeof fetch < "u", r = typeof navigator < "u" && "sendBeacon" in navigator;
1032
1046
  if (e.useBeaconApi && r)
1033
1047
  return new Ee(e.trackingHost || t, e, this.logger);
1034
1048
  if (e.forceUseFetch && s)
1035
- return new Q(e.trackingHost || t, e, this.logger);
1049
+ return new J(e.trackingHost || t, e, this.logger);
1036
1050
  if (i)
1037
1051
  return new Pe(e.trackingHost || t, e, this.logger);
1038
1052
  if (s)
1039
- return new Q(e.trackingHost || t, e, this.logger);
1053
+ return new J(e.trackingHost || t, e, this.logger);
1040
1054
  throw new Error("No suitable transport method available");
1041
1055
  }
1042
1056
  initializePersistence() {
@@ -1045,7 +1059,7 @@ class N {
1045
1059
  getOrCreateAnonymousId() {
1046
1060
  var i, s;
1047
1061
  if (!h())
1048
- return O();
1062
+ return R();
1049
1063
  if (this.config.privacyPolicy === "strict" || this.config.cookiePolicy === "strict")
1050
1064
  return "";
1051
1065
  const e = this.config.cookieName || `__eventn_id_${this.config.key}`;
@@ -1053,9 +1067,9 @@ class N {
1053
1067
  if (!t) {
1054
1068
  if (this.config.crossDomainLinking) {
1055
1069
  const a = new URLSearchParams(window.location.search).get("_um"), c = window.location.hash.substring(1).split("~"), d = c.length > 1 ? c[1] : void 0;
1056
- t = a || d || O();
1070
+ t = a || d || R();
1057
1071
  }
1058
- t || (t = O());
1072
+ t || (t = R());
1059
1073
  const r = 365 * 10;
1060
1074
  (s = this.cookieManager) == null || s.set(e, t, r, document.location.protocol !== "http:", !1);
1061
1075
  }
@@ -1066,7 +1080,7 @@ class N {
1066
1080
  throw new Error("User data must be an object");
1067
1081
  if (e.email && !me(e.email))
1068
1082
  throw new Error("Invalid email provided");
1069
- if (!e.id || !J(e.id))
1083
+ if (!e.id || !Q(e.id))
1070
1084
  throw new Error("User ID must be a string");
1071
1085
  const i = e.id;
1072
1086
  if (this.persistence.set("userId", i), this.persistence.set("userProps", e), !t) {
@@ -1086,7 +1100,7 @@ class N {
1086
1100
  this.logger.debug("Tracking disabled due to um_exclusion setting");
1087
1101
  return;
1088
1102
  }
1089
- if (!J(e))
1103
+ if (!Q(e))
1090
1104
  throw new Error("Event name must be a string");
1091
1105
  if (t !== void 0 && (typeof t != "object" || t === null || Array.isArray(t)))
1092
1106
  throw new Error("Event payload must be a non-null object and not an array");
@@ -1246,17 +1260,17 @@ class N {
1246
1260
  function te() {
1247
1261
  return typeof window < "u" && typeof window.define == "function" && window.define.amd;
1248
1262
  }
1249
- function Ce() {
1263
+ function Te() {
1250
1264
  return te() ? window.define : void 0;
1251
1265
  }
1252
- const Te = "__USERMAVEN_AUTOCAPTURE_INITIALIZED__";
1253
- function I(n) {
1266
+ const $e = "__USERMAVEN_AUTOCAPTURE_INITIALIZED__";
1267
+ function O(n) {
1254
1268
  const e = JSON.parse(JSON.stringify(n)), t = F(e), i = { ...X, ...t };
1255
1269
  if (!i.key)
1256
1270
  throw new Error("API key is required!");
1257
1271
  if (!i.trackingHost)
1258
1272
  throw new Error("Tracking host is required!");
1259
- const s = i.key || "", r = `${Te}${s}`;
1273
+ const s = i.key || "", r = `${$e}${s}`;
1260
1274
  return h() && i.autocapture && window[r] && (console.warn("Usermaven: Autocapture already initialized in another instance, skipping duplicate initialization."), i.disableAutocaptureListenerRegistration = !0), h() && i.autocapture && !i.disableAutocaptureListenerRegistration && (window[r] = !0), new N(i);
1261
1275
  }
1262
1276
  function xe(n) {
@@ -1291,7 +1305,7 @@ function xe(n) {
1291
1305
  maskAllElementAttributes: n.getAttribute("data-mask-all-element-attributes") === "true"
1292
1306
  };
1293
1307
  e.privacyPolicy === "strict" && (e.cookiePolicy = "strict", e.ipPolicy = "strict"), e.cookiePolicy === "comply" && e.useBeaconApi && (e.cookiePolicy = "strict");
1294
- const t = I(e), i = e.namespace || "usermaven";
1308
+ const t = O(e), i = e.namespace || "usermaven";
1295
1309
  return h() && t.pageview(), He(i, t), t;
1296
1310
  }
1297
1311
  function He(n, e) {
@@ -1363,30 +1377,30 @@ function He(n, e) {
1363
1377
  u && i.push(u);
1364
1378
  }
1365
1379
  }
1366
- let K = !1, U = null;
1380
+ let K = !1, L = null;
1367
1381
  if (h()) {
1368
- const n = Ce();
1382
+ const n = Te();
1369
1383
  n && n("usermaven", [], function() {
1370
1384
  return {
1371
- usermavenClient: I,
1385
+ usermavenClient: O,
1372
1386
  UsermavenClient: N,
1373
1387
  LogLevel: k,
1374
1388
  // Expose the script tag client if it exists
1375
- getScriptTagClient: () => U
1389
+ getScriptTagClient: () => L
1376
1390
  };
1377
- }), typeof window < "u" && (window.usermavenClient = I, window.UsermavenClient = N, window.usermavenScriptTagClient = () => U), function(e, t) {
1391
+ }), typeof window < "u" && (window.usermavenClient = O, window.UsermavenClient = N, window.usermavenScriptTagClient = () => L), function(e, t) {
1378
1392
  const i = e.currentScript;
1379
1393
  function s() {
1380
1394
  return K || !i || !i.hasAttribute("data-key") || i.getAttribute("data-no-auto-init") === "true" ? !1 : i.src.includes("lib.js");
1381
1395
  }
1382
1396
  function r() {
1383
- s() && (console.log("[Usermaven] Auto-initializing from script tag"), U = xe(i), K = !0);
1397
+ s() && (console.log("[Usermaven] Auto-initializing from script tag"), L = xe(i), K = !0);
1384
1398
  }
1385
1399
  typeof t < "u" && i && (e.readyState === "loading" ? e.addEventListener("DOMContentLoaded", r) : r());
1386
1400
  }(document, window);
1387
1401
  }
1388
1402
  typeof module < "u" && module.exports && !te() && (module.exports = {
1389
- usermavenClient: I,
1403
+ usermavenClient: O,
1390
1404
  UsermavenClient: N,
1391
1405
  Config: void 0,
1392
1406
  UserProps: void 0,
@@ -1399,7 +1413,7 @@ function createClient(params) {
1399
1413
  if (typeof window === 'undefined') {
1400
1414
  return null;
1401
1415
  }
1402
- return I(params);
1416
+ return O(params);
1403
1417
  }
1404
1418
 
1405
1419
  /******************************************************************************
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usermaven/nextjs",
3
- "version": "1.5.9",
3
+ "version": "1.5.10-rc.108",
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.5.9",
21
+ "@usermaven/sdk-js": "1.5.10-rc.108",
22
22
  "cookie": "^0.5.0"
23
23
  },
24
24
  "peerDependencies": {