@usermaven/react 1.5.8-rc.104 → 1.5.9-rc.105

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 -57
  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, C = oe.forEach, U = {};
108
108
  function ae(n, e, t) {
109
109
  if (Array.isArray(n)) {
110
- if (T && n.forEach === T)
110
+ if (C && n.forEach === C)
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 (C && Array.isArray(n) && n.forEach === C)
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
  }
@@ -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 A = ["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 && A.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 (A.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" && (S.indexOf(r) > -1 || n.getAttribute("contenteditable") === "true");
296
+ return i ? e.type === "click" : e.type === "click" && (A.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) {
@@ -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 A(n) {
354
+ function S(n) {
355
355
  return n !== null && typeof n == "object" && n.constructor === Object;
356
356
  }
357
357
  function ke(n) {
@@ -366,32 +366,54 @@ const ve = () => {
366
366
  };
367
367
  class _e {
368
368
  constructor(e) {
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();
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;
370
381
  }
371
- initializeEventListener() {
372
- window.addEventListener("scroll", this.debouncedHandleScroll);
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));
373
384
  }
374
385
  track() {
375
386
  const e = this.getScrollDepth();
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,
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,
383
395
  window_height: this.getWindowHeight(),
384
396
  document_height: this.getDocumentHeight(),
385
- scroll_distance: this.getScrollDistance()
397
+ scroll_distance: this.getScrollDistance(),
398
+ is_final: e === "$scroll_exit"
386
399
  };
387
- this.client.track(e, t);
400
+ this.client.track(e, s);
388
401
  }
389
402
  handleScroll() {
390
403
  this.track();
391
404
  }
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
+ }
392
411
  getScrollDepth() {
393
- const e = this.getWindowHeight(), t = this.getDocumentHeight(), i = this.getScrollDistance(), s = t - e;
394
- return Math.min(100, Math.floor(i / s * 100));
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)));
395
417
  }
396
418
  getWindowHeight() {
397
419
  return window.innerHeight || this.documentElement.clientHeight || document.body.clientHeight || 0;
@@ -410,12 +432,15 @@ class _e {
410
432
  return window.pageYOffset || this.documentElement.scrollTop || document.body.scrollTop || 0;
411
433
  }
412
434
  checkMilestones(e) {
413
- this.milestones.filter((i) => e >= i).forEach((i) => {
414
- this.send(), this.milestones = this.milestones.filter((s) => s !== i);
435
+ this.milestones.forEach((t) => {
436
+ e >= t && !this.reachedMilestones.has(t) && (this.reachedMilestones.add(t), this.send(`$scroll_milestone_${t}`, t));
415
437
  });
416
438
  }
439
+ 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();
441
+ }
417
442
  }
418
- const R = class R {
443
+ const L = class L {
419
444
  constructor(e, t, i = f()) {
420
445
  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
446
  }
@@ -472,7 +497,7 @@ const R = class R {
472
497
  let l, c = !1;
473
498
  if (w(r, (p) => {
474
499
  const _ = M(p);
475
- p.tagName.toLowerCase() === "a" && (l = p.getAttribute("href"), l = _ && C(l) && l);
500
+ p.tagName.toLowerCase() === "a" && (l = p.getAttribute("href"), l = _ && T(l) && l);
476
501
  const u = x(p).split(" ");
477
502
  $(u, "ph-no-capture") && (c = !0), a.push(
478
503
  this.getPropertiesFromElement(
@@ -508,7 +533,7 @@ const R = class R {
508
533
  const t = [];
509
534
  return w(document.querySelectorAll(e.css_selector), function(i) {
510
535
  let s;
511
- ["input", "select"].indexOf(i.tagName.toLowerCase()) > -1 ? s = i.value : i.textContent && (s = i.textContent), C(s) && t.push(s);
536
+ ["input", "select"].indexOf(i.tagName.toLowerCase()) > -1 ? s = i.value : i.textContent && (s = i.textContent), T(s) && t.push(s);
512
537
  }), t.join(", ");
513
538
  }
514
539
  getEventTarget(e) {
@@ -519,12 +544,12 @@ const R = class R {
519
544
  const s = e.tagName.toLowerCase(), r = {
520
545
  tag_name: s
521
546
  };
522
- S.indexOf(s) > -1 && !i && (r.$el_text = V(e));
547
+ A.indexOf(s) > -1 && !i && (r.$el_text = V(e));
523
548
  const o = x(e);
524
549
  o.length > 0 && (r.classes = o.split(" ").filter(function(d) {
525
550
  return d !== "";
526
551
  })), 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);
552
+ j(e) && ["name", "id", "class"].indexOf(d.name) === -1 || !t && T(d.value) && !pe(d.name) && (r["attr__" + d.name] = d.value);
528
553
  });
529
554
  let a = 1, l = 1, c = e;
530
555
  for (; c = this.previousElementSibling(c); )
@@ -560,8 +585,8 @@ const R = class R {
560
585
  return s % t < i;
561
586
  }
562
587
  };
563
- R.FORCE_CAPTURE_ATTR = "data-um-force-capture", R.PREVENT_CAPTURE_ATTR = "data-um-no-capture";
564
- let H = R;
588
+ L.FORCE_CAPTURE_ATTR = "data-um-force-capture", L.PREVENT_CAPTURE_ATTR = "data-um-no-capture";
589
+ let H = L;
565
590
  class be {
566
591
  constructor(e) {
567
592
  this.client = e, this.lastPageUrl = window.location.href, this.trackInitialPageview(), this.initializePageviewTracking();
@@ -706,7 +731,7 @@ class ee {
706
731
  }
707
732
  }
708
733
  }
709
- class Ae {
734
+ class Se {
710
735
  constructor() {
711
736
  this.storage = {};
712
737
  }
@@ -806,7 +831,7 @@ class $e {
806
831
  }), this.clicks = [];
807
832
  }
808
833
  }
809
- class Se {
834
+ class Ae {
810
835
  constructor(e, t, i = f()) {
811
836
  this.trackingHost = e, this.logger = i, this.config = t;
812
837
  }
@@ -987,7 +1012,7 @@ class N {
987
1012
  const i = JSON.parse(JSON.stringify(e));
988
1013
  let s = { ...t, ...i };
989
1014
  return Object.keys(t).forEach((r) => {
990
- A(t[r]) && (s[r] = this.mergeConfig(e[r], t[r]));
1015
+ S(t[r]) && (s[r] = this.mergeConfig(e[r], t[r]));
991
1016
  }), s;
992
1017
  }
993
1018
  init(e) {
@@ -1027,7 +1052,7 @@ class N {
1027
1052
  initializeTransport(e) {
1028
1053
  const t = "https://events.usermaven.com";
1029
1054
  if (!h())
1030
- return new Se(e.trackingHost || t, e);
1055
+ return new Ae(e.trackingHost || t, e);
1031
1056
  const i = "XMLHttpRequest" in window, s = typeof fetch < "u", r = typeof navigator < "u" && "sendBeacon" in navigator;
1032
1057
  if (e.useBeaconApi && r)
1033
1058
  return new Ee(e.trackingHost || t, e, this.logger);
@@ -1040,12 +1065,12 @@ class N {
1040
1065
  throw new Error("No suitable transport method available");
1041
1066
  }
1042
1067
  initializePersistence() {
1043
- return this.config.disableEventPersistence || !h() ? new Ae() : new ee(`${this.namespace}_${this.config.key}`, this.logger);
1068
+ return this.config.disableEventPersistence || !h() ? new Se() : new ee(`${this.namespace}_${this.config.key}`, this.logger);
1044
1069
  }
1045
1070
  getOrCreateAnonymousId() {
1046
1071
  var i, s;
1047
1072
  if (!h())
1048
- return O();
1073
+ return R();
1049
1074
  if (this.config.privacyPolicy === "strict" || this.config.cookiePolicy === "strict")
1050
1075
  return "";
1051
1076
  const e = this.config.cookieName || `__eventn_id_${this.config.key}`;
@@ -1053,16 +1078,16 @@ class N {
1053
1078
  if (!t) {
1054
1079
  if (this.config.crossDomainLinking) {
1055
1080
  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();
1081
+ t = a || d || R();
1057
1082
  }
1058
- t || (t = O());
1083
+ t || (t = R());
1059
1084
  const r = 365 * 10;
1060
1085
  (s = this.cookieManager) == null || s.set(e, t, r, document.location.protocol !== "http:", !1);
1061
1086
  }
1062
1087
  return t;
1063
1088
  }
1064
1089
  async id(e, t = !1) {
1065
- if (!A(e))
1090
+ if (!S(e))
1066
1091
  throw new Error("User data must be an object");
1067
1092
  if (e.email && !me(e.email))
1068
1093
  throw new Error("Invalid email provided");
@@ -1102,12 +1127,12 @@ class N {
1102
1127
  }
1103
1128
  }
1104
1129
  rawTrack(e) {
1105
- if (!A(e))
1130
+ if (!S(e))
1106
1131
  throw new Error("Event payload must be an object");
1107
1132
  this.track("raw", e);
1108
1133
  }
1109
1134
  async group(e, t = !1) {
1110
- if (!A(e))
1135
+ if (!S(e))
1111
1136
  throw new Error("Company properties must be an object");
1112
1137
  if (!e.id || !e.name || !e.created_at)
1113
1138
  throw new Error("Company properties must include id, name, and created_at");
@@ -1210,7 +1235,7 @@ class N {
1210
1235
  this.logger.info("core state reset", { resetAnonId: e, namespace: this.namespace });
1211
1236
  }
1212
1237
  set(e, t) {
1213
- if (!A(e))
1238
+ if (!S(e))
1214
1239
  throw new Error("Properties must be an object");
1215
1240
  const i = t == null ? void 0 : t.eventType, s = (t == null ? void 0 : t.persist) ?? !0;
1216
1241
  if (i) {
@@ -1246,17 +1271,17 @@ class N {
1246
1271
  function te() {
1247
1272
  return typeof window < "u" && typeof window.define == "function" && window.define.amd;
1248
1273
  }
1249
- function Ce() {
1274
+ function Te() {
1250
1275
  return te() ? window.define : void 0;
1251
1276
  }
1252
- const Te = "__USERMAVEN_AUTOCAPTURE_INITIALIZED__";
1277
+ const Ce = "__USERMAVEN_AUTOCAPTURE_INITIALIZED__";
1253
1278
  function I(n) {
1254
1279
  const e = JSON.parse(JSON.stringify(n)), t = F(e), i = { ...X, ...t };
1255
1280
  if (!i.key)
1256
1281
  throw new Error("API key is required!");
1257
1282
  if (!i.trackingHost)
1258
1283
  throw new Error("Tracking host is required!");
1259
- const s = i.key || "", r = `${Te}${s}`;
1284
+ const s = i.key || "", r = `${Ce}${s}`;
1260
1285
  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
1286
  }
1262
1287
  function xe(n) {
@@ -1363,24 +1388,24 @@ function He(n, e) {
1363
1388
  u && i.push(u);
1364
1389
  }
1365
1390
  }
1366
- let K = !1, U = null;
1391
+ let K = !1, O = null;
1367
1392
  if (h()) {
1368
- const n = Ce();
1393
+ const n = Te();
1369
1394
  n && n("usermaven", [], function() {
1370
1395
  return {
1371
1396
  usermavenClient: I,
1372
1397
  UsermavenClient: N,
1373
1398
  LogLevel: k,
1374
1399
  // Expose the script tag client if it exists
1375
- getScriptTagClient: () => U
1400
+ getScriptTagClient: () => O
1376
1401
  };
1377
- }), typeof window < "u" && (window.usermavenClient = I, window.UsermavenClient = N, window.usermavenScriptTagClient = () => U), function(e, t) {
1402
+ }), typeof window < "u" && (window.usermavenClient = I, window.UsermavenClient = N, window.usermavenScriptTagClient = () => O), function(e, t) {
1378
1403
  const i = e.currentScript;
1379
1404
  function s() {
1380
1405
  return K || !i || !i.hasAttribute("data-key") || i.getAttribute("data-no-auto-init") === "true" ? !1 : i.src.includes("lib.js");
1381
1406
  }
1382
1407
  function r() {
1383
- s() && (console.log("[Usermaven] Auto-initializing from script tag"), U = xe(i), K = !0);
1408
+ s() && (console.log("[Usermaven] Auto-initializing from script tag"), O = xe(i), K = !0);
1384
1409
  }
1385
1410
  typeof t < "u" && i && (e.readyState === "loading" ? e.addEventListener("DOMContentLoaded", r) : r());
1386
1411
  }(document, window);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usermaven/react",
3
- "version": "1.5.8-rc.104",
3
+ "version": "1.5.9-rc.105",
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.8-rc.104"
21
+ "@usermaven/sdk-js": "1.5.9-rc.105"
22
22
  },
23
23
  "peerDependencies": {
24
24
  "react": "15.x || 16.x || 17.x || 18.x || 19.x",