@usermaven/react 1.5.9-rc.105 → 1.5.9-rc.106

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 +62 -84
  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, C = oe.forEach, U = {};
107
+ const se = Object.prototype, re = se.hasOwnProperty, oe = Array.prototype, T = oe.forEach, U = {};
108
108
  function ae(n, e, t) {
109
109
  if (Array.isArray(n)) {
110
- if (C && n.forEach === C)
110
+ if (T && n.forEach === T)
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 (C && Array.isArray(n) && n.forEach === C)
127
+ if (T && Array.isArray(n) && n.forEach === T)
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++)
@@ -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(T).join("").replace(/[\r\n]/g, " ").replace(/[ ]+/g, " ").substring(0, 255));
240
+ G(t) && t.textContent && (e += D(t.textContent).split(/(\s+)/).filter(C).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 = ["a", "button", "form", "input", "select", "textarea", "label"];
255
+ const $ = ["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 && A.indexOf(t.tagName.toLowerCase()) > -1 && (i = !0);
268
+ t = t.parentNode.host, t && $.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 (A.indexOf(o.tagName.toLowerCase()) > -1)
273
+ if ($.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" && (A.indexOf(r) > -1 || n.getAttribute("contenteditable") === "true");
296
+ return i ? e.type === "click" : e.type === "click" && ($.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 T(n) {
322
+ function C(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 R() {
328
+ function O() {
329
329
  return v(10);
330
330
  }
331
331
  function me(n) {
@@ -351,7 +351,7 @@ function we(n) {
351
351
  function J(n) {
352
352
  return typeof n == "string" || n instanceof String;
353
353
  }
354
- function S(n) {
354
+ function A(n) {
355
355
  return n !== null && typeof n == "object" && n.constructor === Object;
356
356
  }
357
357
  function ke(n) {
@@ -366,54 +366,32 @@ const ve = () => {
366
366
  };
367
367
  class _e {
368
368
  constructor(e) {
369
- this.maxScrollDepth = 0, this.milestones = /* @__PURE__ */ new Set([25, 50, 75, 90]), this.reachedMilestones = /* @__PURE__ */ new Set(), this.hasSentFinalEvent = !1, this.scrollTimeout = null, this.client = e, this.documentElement = document.documentElement, this.debouncedHandleScroll = this.createDebouncedScroll(250), this.initializeEventListeners();
370
- }
371
- createDebouncedScroll(e) {
372
- ye(this.handleScroll.bind(this), e);
373
- const t = () => {
374
- this.scrollTimeout && clearTimeout(this.scrollTimeout), this.scrollTimeout = setTimeout(() => {
375
- this.handleScroll(), this.scrollTimeout = null;
376
- }, e);
377
- };
378
- return t.cancel = () => {
379
- this.scrollTimeout && (clearTimeout(this.scrollTimeout), this.scrollTimeout = null);
380
- }, t;
369
+ this.maxScrollDepth = 0, this.milestones = [25, 50, 75, 90], this.lastScrollDepth = 0, this.client = e, this.documentElement = document.documentElement, this.debouncedHandleScroll = ye(this.handleScroll.bind(this), 250), this.initializeEventListener();
381
370
  }
382
- initializeEventListeners() {
383
- window.addEventListener("scroll", this.debouncedHandleScroll, { passive: !0 }), window.addEventListener("pagehide", this.handlePageExit.bind(this)), window.addEventListener("beforeunload", this.handlePageExit.bind(this)), document.addEventListener("visibilitychange", this.handleVisibilityChange.bind(this));
371
+ initializeEventListener() {
372
+ window.addEventListener("scroll", this.debouncedHandleScroll);
384
373
  }
385
374
  track() {
386
375
  const e = this.getScrollDepth();
387
- e > this.maxScrollDepth && (this.maxScrollDepth = e, this.checkMilestones(e));
388
- }
389
- send(e = "$scroll", t) {
390
- const i = this.getScrollDepth();
391
- this.maxScrollDepth = Math.max(this.maxScrollDepth, i);
392
- const s = {
393
- percent: t ?? this.maxScrollDepth,
394
- max_percent: this.maxScrollDepth,
376
+ e > this.lastScrollDepth && (this.lastScrollDepth = e, this.checkMilestones(e));
377
+ }
378
+ send(e = "$scroll") {
379
+ if (!this.lastScrollDepth)
380
+ return;
381
+ const t = {
382
+ percent: this.lastScrollDepth,
395
383
  window_height: this.getWindowHeight(),
396
384
  document_height: this.getDocumentHeight(),
397
- scroll_distance: this.getScrollDistance(),
398
- is_final: e === "$scroll_exit"
385
+ scroll_distance: this.getScrollDistance()
399
386
  };
400
- this.client.track(e, s);
387
+ this.client.track(e, t);
401
388
  }
402
389
  handleScroll() {
403
390
  this.track();
404
391
  }
405
- handlePageExit() {
406
- this.hasSentFinalEvent || (this.debouncedHandleScroll.cancel && this.debouncedHandleScroll.cancel(), this.track(), this.send("$scroll_exit"), this.hasSentFinalEvent = !0);
407
- }
408
- handleVisibilityChange() {
409
- document.hidden && (this.track(), this.send("$scroll_checkpoint"));
410
- }
411
392
  getScrollDepth() {
412
- const e = this.getWindowHeight(), t = this.getDocumentHeight(), i = this.getScrollDistance();
413
- if (t <= e)
414
- return 100;
415
- const s = t - e, r = i / s * 100;
416
- return Math.min(100, Math.max(0, Math.round(r)));
393
+ const e = this.getWindowHeight(), t = this.getDocumentHeight(), i = this.getScrollDistance(), s = t - e;
394
+ return Math.min(100, Math.floor(i / s * 100));
417
395
  }
418
396
  getWindowHeight() {
419
397
  return window.innerHeight || this.documentElement.clientHeight || document.body.clientHeight || 0;
@@ -432,15 +410,15 @@ class _e {
432
410
  return window.pageYOffset || this.documentElement.scrollTop || document.body.scrollTop || 0;
433
411
  }
434
412
  checkMilestones(e) {
435
- this.milestones.forEach((t) => {
436
- e >= t && !this.reachedMilestones.has(t) && (this.reachedMilestones.add(t), this.send(`$scroll_milestone_${t}`, t));
413
+ this.milestones.filter((i) => e >= i).forEach((i) => {
414
+ this.send(), this.milestones = this.milestones.filter((s) => s !== i);
437
415
  });
438
416
  }
439
417
  destroy() {
440
- window.removeEventListener("scroll", this.debouncedHandleScroll), window.removeEventListener("pagehide", this.handlePageExit.bind(this)), window.removeEventListener("beforeunload", this.handlePageExit.bind(this)), document.removeEventListener("visibilitychange", this.handleVisibilityChange.bind(this)), this.hasSentFinalEvent || this.handlePageExit();
418
+ window.removeEventListener("scroll", this.debouncedHandleScroll);
441
419
  }
442
420
  }
443
- const L = class L {
421
+ const R = class R {
444
422
  constructor(e, t, i = f()) {
445
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);
446
424
  }
@@ -497,9 +475,9 @@ const L = class L {
497
475
  let l, c = !1;
498
476
  if (w(r, (p) => {
499
477
  const _ = M(p);
500
- p.tagName.toLowerCase() === "a" && (l = p.getAttribute("href"), l = _ && T(l) && l);
478
+ p.tagName.toLowerCase() === "a" && (l = p.getAttribute("href"), l = _ && C(l) && l);
501
479
  const u = x(p).split(" ");
502
- $(u, "ph-no-capture") && (c = !0), a.push(
480
+ S(u, "ph-no-capture") && (c = !0), a.push(
503
481
  this.getPropertiesFromElement(
504
482
  p,
505
483
  this.options.maskAllElementAttributes ?? !1,
@@ -524,7 +502,7 @@ const L = class L {
524
502
  w(i.event_selectors, (s) => {
525
503
  const r = document.querySelectorAll(s);
526
504
  w(r, (o) => {
527
- $(e, o) && M(o) && (t[i.name] = this.extractCustomPropertyValue(i));
505
+ S(e, o) && M(o) && (t[i.name] = this.extractCustomPropertyValue(i));
528
506
  });
529
507
  });
530
508
  }), t;
@@ -533,7 +511,7 @@ const L = class L {
533
511
  const t = [];
534
512
  return w(document.querySelectorAll(e.css_selector), function(i) {
535
513
  let s;
536
- ["input", "select"].indexOf(i.tagName.toLowerCase()) > -1 ? s = i.value : i.textContent && (s = i.textContent), T(s) && t.push(s);
514
+ ["input", "select"].indexOf(i.tagName.toLowerCase()) > -1 ? s = i.value : i.textContent && (s = i.textContent), C(s) && t.push(s);
537
515
  }), t.join(", ");
538
516
  }
539
517
  getEventTarget(e) {
@@ -544,12 +522,12 @@ const L = class L {
544
522
  const s = e.tagName.toLowerCase(), r = {
545
523
  tag_name: s
546
524
  };
547
- A.indexOf(s) > -1 && !i && (r.$el_text = V(e));
525
+ $.indexOf(s) > -1 && !i && (r.$el_text = V(e));
548
526
  const o = x(e);
549
527
  o.length > 0 && (r.classes = o.split(" ").filter(function(d) {
550
528
  return d !== "";
551
529
  })), w(e.attributes, function(d) {
552
- j(e) && ["name", "id", "class"].indexOf(d.name) === -1 || !t && T(d.value) && !pe(d.name) && (r["attr__" + d.name] = d.value);
530
+ j(e) && ["name", "id", "class"].indexOf(d.name) === -1 || !t && C(d.value) && !pe(d.name) && (r["attr__" + d.name] = d.value);
553
531
  });
554
532
  let a = 1, l = 1, c = e;
555
533
  for (; c = this.previousElementSibling(c); )
@@ -585,8 +563,8 @@ const L = class L {
585
563
  return s % t < i;
586
564
  }
587
565
  };
588
- L.FORCE_CAPTURE_ATTR = "data-um-force-capture", L.PREVENT_CAPTURE_ATTR = "data-um-no-capture";
589
- let H = L;
566
+ R.FORCE_CAPTURE_ATTR = "data-um-force-capture", R.PREVENT_CAPTURE_ATTR = "data-um-no-capture";
567
+ let H = R;
590
568
  class be {
591
569
  constructor(e) {
592
570
  this.client = e, this.lastPageUrl = window.location.href, this.trackInitialPageview(), this.initializePageviewTracking();
@@ -731,7 +709,7 @@ class ee {
731
709
  }
732
710
  }
733
711
  }
734
- class Se {
712
+ class Ae {
735
713
  constructor() {
736
714
  this.storage = {};
737
715
  }
@@ -797,7 +775,7 @@ class W {
797
775
  h() && this.persistence.set("queue", JSON.stringify(this.queue));
798
776
  }
799
777
  }
800
- class $e {
778
+ class Se {
801
779
  constructor(e) {
802
780
  this.clicks = [], this.threshold = 3, this.timeWindow = 2e3, this.distanceThreshold = 30, this.client = e, this.initializeEventListener(), Z(this);
803
781
  }
@@ -831,7 +809,7 @@ class $e {
831
809
  }), this.clicks = [];
832
810
  }
833
811
  }
834
- class Ae {
812
+ class $e {
835
813
  constructor(e, t, i = f()) {
836
814
  this.trackingHost = e, this.logger = i, this.config = t;
837
815
  }
@@ -1001,7 +979,7 @@ class N {
1001
979
  trackFieldChanges: !1
1002
980
  });
1003
981
  }
1004
- this.config.autoPageview && (this.pageviewTracking = new be(this)), this.config.crossDomainLinking && this.manageCrossDomainLinking(), this.config.rageClick && (this.rageClick = new $e(this)), this.setupPageLeaveTracking();
982
+ this.config.autoPageview && (this.pageviewTracking = new be(this)), this.config.crossDomainLinking && this.manageCrossDomainLinking(), this.config.rageClick && (this.rageClick = new Se(this)), this.setupPageLeaveTracking();
1005
983
  }
1006
984
  /**
1007
985
  * Recursively merge the provided configuration with the existing defaultConfig
@@ -1012,7 +990,7 @@ class N {
1012
990
  const i = JSON.parse(JSON.stringify(e));
1013
991
  let s = { ...t, ...i };
1014
992
  return Object.keys(t).forEach((r) => {
1015
- S(t[r]) && (s[r] = this.mergeConfig(e[r], t[r]));
993
+ A(t[r]) && (s[r] = this.mergeConfig(e[r], t[r]));
1016
994
  }), s;
1017
995
  }
1018
996
  init(e) {
@@ -1052,7 +1030,7 @@ class N {
1052
1030
  initializeTransport(e) {
1053
1031
  const t = "https://events.usermaven.com";
1054
1032
  if (!h())
1055
- return new Ae(e.trackingHost || t, e);
1033
+ return new $e(e.trackingHost || t, e);
1056
1034
  const i = "XMLHttpRequest" in window, s = typeof fetch < "u", r = typeof navigator < "u" && "sendBeacon" in navigator;
1057
1035
  if (e.useBeaconApi && r)
1058
1036
  return new Ee(e.trackingHost || t, e, this.logger);
@@ -1065,12 +1043,12 @@ class N {
1065
1043
  throw new Error("No suitable transport method available");
1066
1044
  }
1067
1045
  initializePersistence() {
1068
- return this.config.disableEventPersistence || !h() ? new Se() : new ee(`${this.namespace}_${this.config.key}`, this.logger);
1046
+ return this.config.disableEventPersistence || !h() ? new Ae() : new ee(`${this.namespace}_${this.config.key}`, this.logger);
1069
1047
  }
1070
1048
  getOrCreateAnonymousId() {
1071
1049
  var i, s;
1072
1050
  if (!h())
1073
- return R();
1051
+ return O();
1074
1052
  if (this.config.privacyPolicy === "strict" || this.config.cookiePolicy === "strict")
1075
1053
  return "";
1076
1054
  const e = this.config.cookieName || `__eventn_id_${this.config.key}`;
@@ -1078,16 +1056,16 @@ class N {
1078
1056
  if (!t) {
1079
1057
  if (this.config.crossDomainLinking) {
1080
1058
  const a = new URLSearchParams(window.location.search).get("_um"), c = window.location.hash.substring(1).split("~"), d = c.length > 1 ? c[1] : void 0;
1081
- t = a || d || R();
1059
+ t = a || d || O();
1082
1060
  }
1083
- t || (t = R());
1061
+ t || (t = O());
1084
1062
  const r = 365 * 10;
1085
1063
  (s = this.cookieManager) == null || s.set(e, t, r, document.location.protocol !== "http:", !1);
1086
1064
  }
1087
1065
  return t;
1088
1066
  }
1089
1067
  async id(e, t = !1) {
1090
- if (!S(e))
1068
+ if (!A(e))
1091
1069
  throw new Error("User data must be an object");
1092
1070
  if (e.email && !me(e.email))
1093
1071
  throw new Error("Invalid email provided");
@@ -1127,12 +1105,12 @@ class N {
1127
1105
  }
1128
1106
  }
1129
1107
  rawTrack(e) {
1130
- if (!S(e))
1108
+ if (!A(e))
1131
1109
  throw new Error("Event payload must be an object");
1132
1110
  this.track("raw", e);
1133
1111
  }
1134
1112
  async group(e, t = !1) {
1135
- if (!S(e))
1113
+ if (!A(e))
1136
1114
  throw new Error("Company properties must be an object");
1137
1115
  if (!e.id || !e.name || !e.created_at)
1138
1116
  throw new Error("Company properties must include id, name, and created_at");
@@ -1235,7 +1213,7 @@ class N {
1235
1213
  this.logger.info("core state reset", { resetAnonId: e, namespace: this.namespace });
1236
1214
  }
1237
1215
  set(e, t) {
1238
- if (!S(e))
1216
+ if (!A(e))
1239
1217
  throw new Error("Properties must be an object");
1240
1218
  const i = t == null ? void 0 : t.eventType, s = (t == null ? void 0 : t.persist) ?? !0;
1241
1219
  if (i) {
@@ -1271,17 +1249,17 @@ class N {
1271
1249
  function te() {
1272
1250
  return typeof window < "u" && typeof window.define == "function" && window.define.amd;
1273
1251
  }
1274
- function Te() {
1252
+ function Ce() {
1275
1253
  return te() ? window.define : void 0;
1276
1254
  }
1277
- const Ce = "__USERMAVEN_AUTOCAPTURE_INITIALIZED__";
1255
+ const Te = "__USERMAVEN_AUTOCAPTURE_INITIALIZED__";
1278
1256
  function I(n) {
1279
1257
  const e = JSON.parse(JSON.stringify(n)), t = F(e), i = { ...X, ...t };
1280
1258
  if (!i.key)
1281
1259
  throw new Error("API key is required!");
1282
1260
  if (!i.trackingHost)
1283
1261
  throw new Error("Tracking host is required!");
1284
- const s = i.key || "", r = `${Ce}${s}`;
1262
+ const s = i.key || "", r = `${Te}${s}`;
1285
1263
  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);
1286
1264
  }
1287
1265
  function xe(n) {
@@ -1388,24 +1366,24 @@ function He(n, e) {
1388
1366
  u && i.push(u);
1389
1367
  }
1390
1368
  }
1391
- let K = !1, O = null;
1369
+ let K = !1, L = null;
1392
1370
  if (h()) {
1393
- const n = Te();
1371
+ const n = Ce();
1394
1372
  n && n("usermaven", [], function() {
1395
1373
  return {
1396
1374
  usermavenClient: I,
1397
1375
  UsermavenClient: N,
1398
1376
  LogLevel: k,
1399
1377
  // Expose the script tag client if it exists
1400
- getScriptTagClient: () => O
1378
+ getScriptTagClient: () => L
1401
1379
  };
1402
- }), typeof window < "u" && (window.usermavenClient = I, window.UsermavenClient = N, window.usermavenScriptTagClient = () => O), function(e, t) {
1380
+ }), typeof window < "u" && (window.usermavenClient = I, window.UsermavenClient = N, window.usermavenScriptTagClient = () => L), function(e, t) {
1403
1381
  const i = e.currentScript;
1404
1382
  function s() {
1405
1383
  return K || !i || !i.hasAttribute("data-key") || i.getAttribute("data-no-auto-init") === "true" ? !1 : i.src.includes("lib.js");
1406
1384
  }
1407
1385
  function r() {
1408
- s() && (console.log("[Usermaven] Auto-initializing from script tag"), O = xe(i), K = !0);
1386
+ s() && (console.log("[Usermaven] Auto-initializing from script tag"), L = xe(i), K = !0);
1409
1387
  }
1410
1388
  typeof t < "u" && i && (e.readyState === "loading" ? e.addEventListener("DOMContentLoaded", r) : r());
1411
1389
  }(document, window);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usermaven/react",
3
- "version": "1.5.9-rc.105",
3
+ "version": "1.5.9-rc.106",
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.105"
21
+ "@usermaven/sdk-js": "1.5.9-rc.106"
22
22
  },
23
23
  "peerDependencies": {
24
24
  "react": "15.x || 16.x || 17.x || 18.x || 19.x",