@usermaven/nextjs 1.5.9-rc.105 → 1.5.9

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