@usermaven/react 1.5.9-rc.106 → 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 +66 -55
  2. package/package.json +2 -2
package/lib/index.es.js CHANGED
@@ -104,10 +104,10 @@ 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, U = {};
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++)
@@ -124,7 +124,7 @@ 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++)
@@ -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 $ = ["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 && $.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 ($.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,7 +293,7 @@ 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" && ($.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) {
@@ -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) {
@@ -418,7 +418,7 @@ class _e {
418
418
  window.removeEventListener("scroll", this.debouncedHandleScroll);
419
419
  }
420
420
  }
421
- const R = class R {
421
+ const I = class I {
422
422
  constructor(e, t, i = f()) {
423
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);
424
424
  }
@@ -475,7 +475,7 @@ const R = class R {
475
475
  let l, c = !1;
476
476
  if (w(r, (p) => {
477
477
  const _ = M(p);
478
- 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);
479
479
  const u = x(p).split(" ");
480
480
  S(u, "ph-no-capture") && (c = !0), a.push(
481
481
  this.getPropertiesFromElement(
@@ -511,7 +511,7 @@ const R = class R {
511
511
  const t = [];
512
512
  return w(document.querySelectorAll(e.css_selector), function(i) {
513
513
  let s;
514
- ["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);
515
515
  }), t.join(", ");
516
516
  }
517
517
  getEventTarget(e) {
@@ -522,12 +522,12 @@ const R = class R {
522
522
  const s = e.tagName.toLowerCase(), r = {
523
523
  tag_name: s
524
524
  };
525
- $.indexOf(s) > -1 && !i && (r.$el_text = V(e));
525
+ C.indexOf(s) > -1 && !i && (r.$el_text = V(e));
526
526
  const o = x(e);
527
527
  o.length > 0 && (r.classes = o.split(" ").filter(function(d) {
528
528
  return d !== "";
529
529
  })), w(e.attributes, function(d) {
530
- 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);
531
531
  });
532
532
  let a = 1, l = 1, c = e;
533
533
  for (; c = this.previousElementSibling(c); )
@@ -563,8 +563,8 @@ const R = class R {
563
563
  return s % t < i;
564
564
  }
565
565
  };
566
- R.FORCE_CAPTURE_ATTR = "data-um-force-capture", R.PREVENT_CAPTURE_ATTR = "data-um-no-capture";
567
- let H = R;
566
+ I.FORCE_CAPTURE_ATTR = "data-um-force-capture", I.PREVENT_CAPTURE_ATTR = "data-um-no-capture";
567
+ let H = I;
568
568
  class be {
569
569
  constructor(e) {
570
570
  this.client = e, this.lastPageUrl = window.location.href, this.trackInitialPageview(), this.initializePageviewTracking();
@@ -612,7 +612,7 @@ class Ee {
612
612
  // Note: Beacon API doesn't support custom headers, so we can't use them here.
613
613
  // If custom headers are crucial, you might want to fall back to XHR or Fetch in those cases.
614
614
  }
615
- class Q {
615
+ class J {
616
616
  constructor(e, t, i = f()) {
617
617
  this.trackingHost = e, this.logger = i, this.config = t;
618
618
  }
@@ -809,7 +809,7 @@ class Se {
809
809
  }), this.clicks = [];
810
810
  }
811
811
  }
812
- class $e {
812
+ class Ce {
813
813
  constructor(e, t, i = f()) {
814
814
  this.trackingHost = e, this.logger = i, this.config = t;
815
815
  }
@@ -865,8 +865,12 @@ class P {
865
865
  trackFieldChanges(e) {
866
866
  e.querySelectorAll("input, select, textarea").forEach((i) => {
867
867
  i.addEventListener("change", (s) => {
868
- const r = this._getFieldProps(s.target, 0);
869
- 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
+ }));
870
874
  });
871
875
  });
872
876
  }
@@ -880,28 +884,35 @@ class P {
880
884
  form_action: e.action,
881
885
  form_method: e.method,
882
886
  form_class: e.className,
883
- form_attributes: this._getElementAttributes(e)
887
+ form_attributes: this._getElementAttributes(e),
888
+ fields: []
884
889
  }, i = e.querySelectorAll("input, select, textarea");
885
- return Array.from(i).filter((r) => !r.classList.contains("um-no-capture")).forEach((r, o) => {
886
- const a = this._getFieldProps(r, o);
887
- 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);
888
893
  }), t;
889
894
  }
890
- _getFieldProps(e, t) {
891
- 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);
892
897
  return {
893
- [`field_${t + 1}_tag`]: e.tagName.toLowerCase(),
894
- [`field_${t + 1}_type`]: e instanceof HTMLInputElement ? e.type : void 0,
895
- [`field_${t + 1}_data_attributes`]: i,
896
- [`field_${t + 1}_id`]: e.id,
897
- [`field_${t + 1}_value`]: s,
898
- [`field_${t + 1}_class`]: e.className,
899
- [`field_${t + 1}_name`]: e.name,
900
- [`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)
901
906
  };
902
907
  }
903
908
  _getElementAttributes(e) {
904
- 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;
905
916
  }
906
917
  getSafeText(e) {
907
918
  let t = "";
@@ -1030,16 +1041,16 @@ class N {
1030
1041
  initializeTransport(e) {
1031
1042
  const t = "https://events.usermaven.com";
1032
1043
  if (!h())
1033
- return new $e(e.trackingHost || t, e);
1044
+ return new Ce(e.trackingHost || t, e);
1034
1045
  const i = "XMLHttpRequest" in window, s = typeof fetch < "u", r = typeof navigator < "u" && "sendBeacon" in navigator;
1035
1046
  if (e.useBeaconApi && r)
1036
1047
  return new Ee(e.trackingHost || t, e, this.logger);
1037
1048
  if (e.forceUseFetch && s)
1038
- return new Q(e.trackingHost || t, e, this.logger);
1049
+ return new J(e.trackingHost || t, e, this.logger);
1039
1050
  if (i)
1040
1051
  return new Pe(e.trackingHost || t, e, this.logger);
1041
1052
  if (s)
1042
- return new Q(e.trackingHost || t, e, this.logger);
1053
+ return new J(e.trackingHost || t, e, this.logger);
1043
1054
  throw new Error("No suitable transport method available");
1044
1055
  }
1045
1056
  initializePersistence() {
@@ -1048,7 +1059,7 @@ class N {
1048
1059
  getOrCreateAnonymousId() {
1049
1060
  var i, s;
1050
1061
  if (!h())
1051
- return O();
1062
+ return R();
1052
1063
  if (this.config.privacyPolicy === "strict" || this.config.cookiePolicy === "strict")
1053
1064
  return "";
1054
1065
  const e = this.config.cookieName || `__eventn_id_${this.config.key}`;
@@ -1056,9 +1067,9 @@ class N {
1056
1067
  if (!t) {
1057
1068
  if (this.config.crossDomainLinking) {
1058
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;
1059
- t = a || d || O();
1070
+ t = a || d || R();
1060
1071
  }
1061
- t || (t = O());
1072
+ t || (t = R());
1062
1073
  const r = 365 * 10;
1063
1074
  (s = this.cookieManager) == null || s.set(e, t, r, document.location.protocol !== "http:", !1);
1064
1075
  }
@@ -1069,7 +1080,7 @@ class N {
1069
1080
  throw new Error("User data must be an object");
1070
1081
  if (e.email && !me(e.email))
1071
1082
  throw new Error("Invalid email provided");
1072
- if (!e.id || !J(e.id))
1083
+ if (!e.id || !Q(e.id))
1073
1084
  throw new Error("User ID must be a string");
1074
1085
  const i = e.id;
1075
1086
  if (this.persistence.set("userId", i), this.persistence.set("userProps", e), !t) {
@@ -1089,7 +1100,7 @@ class N {
1089
1100
  this.logger.debug("Tracking disabled due to um_exclusion setting");
1090
1101
  return;
1091
1102
  }
1092
- if (!J(e))
1103
+ if (!Q(e))
1093
1104
  throw new Error("Event name must be a string");
1094
1105
  if (t !== void 0 && (typeof t != "object" || t === null || Array.isArray(t)))
1095
1106
  throw new Error("Event payload must be a non-null object and not an array");
@@ -1249,17 +1260,17 @@ class N {
1249
1260
  function te() {
1250
1261
  return typeof window < "u" && typeof window.define == "function" && window.define.amd;
1251
1262
  }
1252
- function Ce() {
1263
+ function Te() {
1253
1264
  return te() ? window.define : void 0;
1254
1265
  }
1255
- const Te = "__USERMAVEN_AUTOCAPTURE_INITIALIZED__";
1256
- function I(n) {
1266
+ const $e = "__USERMAVEN_AUTOCAPTURE_INITIALIZED__";
1267
+ function O(n) {
1257
1268
  const e = JSON.parse(JSON.stringify(n)), t = F(e), i = { ...X, ...t };
1258
1269
  if (!i.key)
1259
1270
  throw new Error("API key is required!");
1260
1271
  if (!i.trackingHost)
1261
1272
  throw new Error("Tracking host is required!");
1262
- const s = i.key || "", r = `${Te}${s}`;
1273
+ const s = i.key || "", r = `${$e}${s}`;
1263
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);
1264
1275
  }
1265
1276
  function xe(n) {
@@ -1294,7 +1305,7 @@ function xe(n) {
1294
1305
  maskAllElementAttributes: n.getAttribute("data-mask-all-element-attributes") === "true"
1295
1306
  };
1296
1307
  e.privacyPolicy === "strict" && (e.cookiePolicy = "strict", e.ipPolicy = "strict"), e.cookiePolicy === "comply" && e.useBeaconApi && (e.cookiePolicy = "strict");
1297
- const t = I(e), i = e.namespace || "usermaven";
1308
+ const t = O(e), i = e.namespace || "usermaven";
1298
1309
  return h() && t.pageview(), He(i, t), t;
1299
1310
  }
1300
1311
  function He(n, e) {
@@ -1368,16 +1379,16 @@ function He(n, e) {
1368
1379
  }
1369
1380
  let K = !1, L = null;
1370
1381
  if (h()) {
1371
- const n = Ce();
1382
+ const n = Te();
1372
1383
  n && n("usermaven", [], function() {
1373
1384
  return {
1374
- usermavenClient: I,
1385
+ usermavenClient: O,
1375
1386
  UsermavenClient: N,
1376
1387
  LogLevel: k,
1377
1388
  // Expose the script tag client if it exists
1378
1389
  getScriptTagClient: () => L
1379
1390
  };
1380
- }), typeof window < "u" && (window.usermavenClient = I, window.UsermavenClient = N, window.usermavenScriptTagClient = () => L), function(e, t) {
1391
+ }), typeof window < "u" && (window.usermavenClient = O, window.UsermavenClient = N, window.usermavenScriptTagClient = () => L), function(e, t) {
1381
1392
  const i = e.currentScript;
1382
1393
  function s() {
1383
1394
  return K || !i || !i.hasAttribute("data-key") || i.getAttribute("data-no-auto-init") === "true" ? !1 : i.src.includes("lib.js");
@@ -1389,7 +1400,7 @@ if (h()) {
1389
1400
  }(document, window);
1390
1401
  }
1391
1402
  typeof module < "u" && module.exports && !te() && (module.exports = {
1392
- usermavenClient: I,
1403
+ usermavenClient: O,
1393
1404
  UsermavenClient: N,
1394
1405
  Config: void 0,
1395
1406
  UserProps: void 0,
@@ -1399,7 +1410,7 @@ typeof module < "u" && module.exports && !te() && (module.exports = {
1399
1410
  });
1400
1411
 
1401
1412
  function createClient(params) {
1402
- return I(params);
1413
+ return O(params);
1403
1414
  }
1404
1415
 
1405
1416
  function useUsermaven() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usermaven/react",
3
- "version": "1.5.9-rc.106",
3
+ "version": "1.5.10-rc.108",
4
4
  "description": "Usermaven JavaScript SDK for React",
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-rc.106"
21
+ "@usermaven/sdk-js": "1.5.10-rc.108"
22
22
  },
23
23
  "peerDependencies": {
24
24
  "react": "15.x || 16.x || 17.x || 18.x || 19.x",