@usermaven/nextjs 1.5.10-rc.109 → 1.5.10-rc.111
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.
- package/lib/UsermavenContext.d.ts +1 -1
- package/lib/UsermavenProvider.d.ts +2 -2
- package/lib/client.d.ts +1 -1
- package/lib/index.es.js +318 -155
- package/lib/middlewareEnv.d.ts +3 -3
- package/lib/middlewareEnv.js +23 -17
- package/lib/usePageView.d.ts +1 -1
- package/lib/useUsermaven.d.ts +2 -1
- package/lib/useUsermaven.js +3 -0
- package/package.json +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { UsermavenClient } from
|
|
3
|
-
import { PropsWithChildren } from
|
|
2
|
+
import { UsermavenClient } from '@usermaven/sdk-js';
|
|
3
|
+
import { PropsWithChildren } from 'react';
|
|
4
4
|
export interface UsermavenProviderProps {
|
|
5
5
|
client: UsermavenClient | null;
|
|
6
6
|
}
|
package/lib/client.d.ts
CHANGED
package/lib/index.es.js
CHANGED
|
@@ -9,7 +9,7 @@ const UsermavenProvider = function ({ children, client }) {
|
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
var k = /* @__PURE__ */ ((n) => (n[n.DEBUG = 0] = "DEBUG", n[n.INFO = 1] = "INFO", n[n.WARN = 2] = "WARN", n[n.ERROR = 3] = "ERROR", n))(k || {});
|
|
12
|
-
class
|
|
12
|
+
class ne {
|
|
13
13
|
constructor(e) {
|
|
14
14
|
this.level = e;
|
|
15
15
|
}
|
|
@@ -27,9 +27,9 @@ class ie {
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
function f(n = 0) {
|
|
30
|
-
return new
|
|
30
|
+
return new ne(n);
|
|
31
31
|
}
|
|
32
|
-
const
|
|
32
|
+
const Z = {
|
|
33
33
|
logLevel: k.ERROR,
|
|
34
34
|
useBeaconApi: !1,
|
|
35
35
|
forceUseFetch: !1,
|
|
@@ -42,7 +42,13 @@ const X = {
|
|
|
42
42
|
gaHook: !1,
|
|
43
43
|
segmentHook: !1,
|
|
44
44
|
randomizeUrl: !1,
|
|
45
|
-
capture3rdPartyCookies: [
|
|
45
|
+
capture3rdPartyCookies: [
|
|
46
|
+
"_ga",
|
|
47
|
+
"_fbp",
|
|
48
|
+
"_ym_uid",
|
|
49
|
+
"ajs_user_id",
|
|
50
|
+
"ajs_anonymous_id"
|
|
51
|
+
],
|
|
46
52
|
idMethod: "cookie",
|
|
47
53
|
ipPolicy: "keep",
|
|
48
54
|
cookiePolicy: "keep",
|
|
@@ -55,7 +61,7 @@ const X = {
|
|
|
55
61
|
maskAllText: !1,
|
|
56
62
|
maskAllElementAttributes: !1
|
|
57
63
|
};
|
|
58
|
-
class
|
|
64
|
+
class se {
|
|
59
65
|
constructor(e) {
|
|
60
66
|
this.domain = e, this.cookieDomain = this.getCookieDomain();
|
|
61
67
|
}
|
|
@@ -104,21 +110,21 @@ class ne {
|
|
|
104
110
|
return i ? i[0] : "";
|
|
105
111
|
}
|
|
106
112
|
}
|
|
107
|
-
const
|
|
108
|
-
function
|
|
113
|
+
const re = Object.prototype, oe = re.hasOwnProperty, ae = Array.prototype, $ = ae.forEach, D = {};
|
|
114
|
+
function ce(n, e, t) {
|
|
109
115
|
if (Array.isArray(n)) {
|
|
110
116
|
if ($ && n.forEach === $)
|
|
111
117
|
n.forEach(e, t);
|
|
112
118
|
else if ("length" in n && n.length === +n.length) {
|
|
113
119
|
for (let i = 0, s = n.length; i < s; i++)
|
|
114
|
-
if (i in n && e.call(t, n[i], i) ===
|
|
120
|
+
if (i in n && e.call(t, n[i], i) === D)
|
|
115
121
|
return;
|
|
116
122
|
}
|
|
117
123
|
}
|
|
118
124
|
}
|
|
119
|
-
const
|
|
125
|
+
const F = function(n) {
|
|
120
126
|
return n.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, "");
|
|
121
|
-
},
|
|
127
|
+
}, le = function(n) {
|
|
122
128
|
for (const e in n)
|
|
123
129
|
typeof n[e] == "function" && (n[e] = n[e].bind(n));
|
|
124
130
|
};
|
|
@@ -128,16 +134,16 @@ function w(n, e, t) {
|
|
|
128
134
|
n.forEach(e, t);
|
|
129
135
|
else if ("length" in n && n.length === +n.length) {
|
|
130
136
|
for (let i = 0, s = n.length; i < s; i++)
|
|
131
|
-
if (i in n && e.call(t, n[i], i) ===
|
|
137
|
+
if (i in n && e.call(t, n[i], i) === D)
|
|
132
138
|
return;
|
|
133
139
|
} else
|
|
134
140
|
for (const i in n)
|
|
135
|
-
if (
|
|
141
|
+
if (oe.call(n, i) && e.call(t, n[i], i) === D)
|
|
136
142
|
return;
|
|
137
143
|
}
|
|
138
144
|
}
|
|
139
|
-
const
|
|
140
|
-
return
|
|
145
|
+
const ue = function(n, ...e) {
|
|
146
|
+
return ce(e, function(t) {
|
|
141
147
|
for (const i in t)
|
|
142
148
|
t[i] !== void 0 && (n[i] = t[i]);
|
|
143
149
|
}), n;
|
|
@@ -145,13 +151,13 @@ const le = function(n, ...e) {
|
|
|
145
151
|
function S(n, e) {
|
|
146
152
|
return n.indexOf(e) !== -1;
|
|
147
153
|
}
|
|
148
|
-
const
|
|
154
|
+
const he = function(n) {
|
|
149
155
|
try {
|
|
150
156
|
return /^\s*\bfunction\b/.test(n);
|
|
151
157
|
} catch {
|
|
152
158
|
return !1;
|
|
153
159
|
}
|
|
154
|
-
},
|
|
160
|
+
}, de = function(n) {
|
|
155
161
|
return n === void 0;
|
|
156
162
|
}, E = function() {
|
|
157
163
|
const n = function(i, s, r, o, a) {
|
|
@@ -171,7 +177,7 @@ const ue = function(n) {
|
|
|
171
177
|
if (o = o || t(window.event), !o)
|
|
172
178
|
return;
|
|
173
179
|
let a = !0, l;
|
|
174
|
-
|
|
180
|
+
he(r) && (l = r(o));
|
|
175
181
|
const c = s.call(i, o);
|
|
176
182
|
return (l === !1 || c === !1) && (a = !1), a;
|
|
177
183
|
};
|
|
@@ -184,19 +190,22 @@ const ue = function(n) {
|
|
|
184
190
|
}, t.stopPropagation = function() {
|
|
185
191
|
this.cancelBubble = !0;
|
|
186
192
|
}, n;
|
|
187
|
-
}(),
|
|
193
|
+
}(), fe = function(n) {
|
|
188
194
|
return function(...e) {
|
|
189
195
|
try {
|
|
190
196
|
return n.apply(this, e);
|
|
191
197
|
} catch (t) {
|
|
192
|
-
f().error(
|
|
198
|
+
f().error(
|
|
199
|
+
"Implementation error. Please turn on debug and contact support@usermaven.com.",
|
|
200
|
+
t
|
|
201
|
+
);
|
|
193
202
|
}
|
|
194
203
|
};
|
|
195
|
-
},
|
|
204
|
+
}, Y = function(n) {
|
|
196
205
|
for (const e in n)
|
|
197
|
-
typeof n[e] == "function" && (n[e] =
|
|
206
|
+
typeof n[e] == "function" && (n[e] = fe(n[e]));
|
|
198
207
|
};
|
|
199
|
-
function
|
|
208
|
+
function V(n) {
|
|
200
209
|
for (let e in n)
|
|
201
210
|
(n[e] === "" || n[e] === null || n[e] === void 0 || typeof n[e] == "object" && Object.keys(n[e]).length === 0) && delete n[e];
|
|
202
211
|
return n;
|
|
@@ -212,17 +221,20 @@ function v(n = 5) {
|
|
|
212
221
|
const e = new Uint8Array(n);
|
|
213
222
|
return crypto.getRandomValues(e), Array.from(e, (t) => t.toString(36).padStart(2, "0")).join("").slice(0, n);
|
|
214
223
|
}
|
|
215
|
-
function
|
|
224
|
+
function ge(n) {
|
|
216
225
|
return n.replace(
|
|
217
226
|
/([-_][a-z])/g,
|
|
218
227
|
(e) => e.toUpperCase().replace("-", "").replace("_", "")
|
|
219
228
|
);
|
|
220
229
|
}
|
|
221
|
-
function
|
|
222
|
-
return typeof n != "object" || n === null ? n : Array.isArray(n) ? n.map(
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
230
|
+
function z(n) {
|
|
231
|
+
return typeof n != "object" || n === null ? n : Array.isArray(n) ? n.map(z) : Object.keys(n).reduce(
|
|
232
|
+
(e, t) => {
|
|
233
|
+
const i = ge(t);
|
|
234
|
+
return e[i] = z(n[t]), e;
|
|
235
|
+
},
|
|
236
|
+
{}
|
|
237
|
+
);
|
|
226
238
|
}
|
|
227
239
|
function x(n) {
|
|
228
240
|
switch (typeof n.className) {
|
|
@@ -234,37 +246,45 @@ function x(n) {
|
|
|
234
246
|
return "";
|
|
235
247
|
}
|
|
236
248
|
}
|
|
237
|
-
function
|
|
249
|
+
function Q(n) {
|
|
238
250
|
let e = "";
|
|
239
|
-
return
|
|
240
|
-
|
|
241
|
-
}),
|
|
251
|
+
return B(n) && !ee(n) && n.childNodes && n.childNodes.length && w(n.childNodes, function(t) {
|
|
252
|
+
j(t) && t.textContent && (e += F(t.textContent).split(/(\s+)/).filter(T).join("").replace(/[\r\n]/g, " ").replace(/[ ]+/g, " ").substring(0, 255));
|
|
253
|
+
}), F(e);
|
|
242
254
|
}
|
|
243
|
-
function
|
|
255
|
+
function G(n) {
|
|
244
256
|
return !!n && n.nodeType === 1;
|
|
245
257
|
}
|
|
246
258
|
function y(n, e) {
|
|
247
259
|
return !!n && !!n.tagName && n.tagName.toLowerCase() === e.toLowerCase();
|
|
248
260
|
}
|
|
249
|
-
function
|
|
261
|
+
function j(n) {
|
|
250
262
|
return !!n && n.nodeType === 3;
|
|
251
263
|
}
|
|
252
|
-
function
|
|
264
|
+
function M(n) {
|
|
253
265
|
return !!n && n.nodeType === 11;
|
|
254
266
|
}
|
|
255
|
-
const C = [
|
|
256
|
-
|
|
257
|
-
|
|
267
|
+
const C = [
|
|
268
|
+
"a",
|
|
269
|
+
"button",
|
|
270
|
+
"form",
|
|
271
|
+
"input",
|
|
272
|
+
"select",
|
|
273
|
+
"textarea",
|
|
274
|
+
"label"
|
|
275
|
+
];
|
|
276
|
+
function pe(n, e) {
|
|
277
|
+
if (!n || y(n, "html") || !G(n))
|
|
258
278
|
return !1;
|
|
259
279
|
let t = n;
|
|
260
280
|
for (; t && !y(t, "body"); ) {
|
|
261
281
|
if (t.classList && t.classList.contains("um-no-capture"))
|
|
262
282
|
return !1;
|
|
263
|
-
t.parentNode &&
|
|
283
|
+
t.parentNode && M(t.parentNode) ? t = t.parentNode.host : t = t.parentNode;
|
|
264
284
|
}
|
|
265
285
|
let i = !1;
|
|
266
286
|
for (t = n; t && !y(t, "body"); ) {
|
|
267
|
-
if (t.parentNode &&
|
|
287
|
+
if (t.parentNode && M(t.parentNode)) {
|
|
268
288
|
t = t.parentNode.host, t && C.indexOf(t.tagName.toLowerCase()) > -1 && (i = !0);
|
|
269
289
|
continue;
|
|
270
290
|
}
|
|
@@ -296,7 +316,7 @@ function ge(n, e) {
|
|
|
296
316
|
return i ? e.type === "click" : e.type === "click" && (C.indexOf(r) > -1 || n.getAttribute("contenteditable") === "true");
|
|
297
317
|
}
|
|
298
318
|
}
|
|
299
|
-
function
|
|
319
|
+
function B(n) {
|
|
300
320
|
for (let i = n; i.parentNode && !y(i, "body"); i = i.parentNode) {
|
|
301
321
|
const s = x(i).split(" ");
|
|
302
322
|
if (S(s, "ph-sensitive") || S(s, "ph-no-capture"))
|
|
@@ -315,20 +335,20 @@ function M(n) {
|
|
|
315
335
|
const t = n.name || n.id || "";
|
|
316
336
|
return !(typeof t == "string" && /^cc|cardnum|ccnum|creditcard|csc|cvc|cvv|exp|pass|pwd|routing|seccode|securitycode|securitynum|socialsec|socsec|ssn/i.test(t.replace(/[^a-zA-Z0-9]/g, "")));
|
|
317
337
|
}
|
|
318
|
-
function
|
|
338
|
+
function ee(n) {
|
|
319
339
|
const e = ["button", "checkbox", "submit", "reset"];
|
|
320
340
|
return !!(y(n, "input") && !e.includes(n.type) || y(n, "select") || y(n, "textarea") || n.getAttribute("contenteditable") === "true");
|
|
321
341
|
}
|
|
322
342
|
function T(n) {
|
|
323
|
-
return !(n === null ||
|
|
343
|
+
return !(n === null || de(n) || typeof n == "string" && (n = F(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
344
|
}
|
|
325
|
-
function
|
|
345
|
+
function me(n) {
|
|
326
346
|
return typeof n == "string" ? n.substring(0, 10) === "_ngcontent" || n.substring(0, 7) === "_nghost" : !1;
|
|
327
347
|
}
|
|
328
348
|
function R() {
|
|
329
349
|
return v(10);
|
|
330
350
|
}
|
|
331
|
-
function
|
|
351
|
+
function J(n) {
|
|
332
352
|
return /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(String(n).toLowerCase());
|
|
333
353
|
}
|
|
334
354
|
function ye(n, e) {
|
|
@@ -348,10 +368,10 @@ function we(n) {
|
|
|
348
368
|
}
|
|
349
369
|
return e;
|
|
350
370
|
}
|
|
351
|
-
function
|
|
371
|
+
function L(n) {
|
|
352
372
|
return typeof n == "string" || n instanceof String;
|
|
353
373
|
}
|
|
354
|
-
function
|
|
374
|
+
function P(n) {
|
|
355
375
|
return n !== null && typeof n == "object" && n.constructor === Object;
|
|
356
376
|
}
|
|
357
377
|
function ke(n) {
|
|
@@ -410,7 +430,9 @@ class _e {
|
|
|
410
430
|
return window.pageYOffset || this.documentElement.scrollTop || document.body.scrollTop || 0;
|
|
411
431
|
}
|
|
412
432
|
checkMilestones(e) {
|
|
413
|
-
this.milestones.filter(
|
|
433
|
+
this.milestones.filter(
|
|
434
|
+
(i) => e >= i
|
|
435
|
+
).forEach((i) => {
|
|
414
436
|
this.send(), this.milestones = this.milestones.filter((s) => s !== i);
|
|
415
437
|
});
|
|
416
438
|
}
|
|
@@ -420,7 +442,7 @@ class _e {
|
|
|
420
442
|
}
|
|
421
443
|
const I = class I {
|
|
422
444
|
constructor(e, t, i = f()) {
|
|
423
|
-
this.logger = i, this.scrollDepth = null, this.customProperties = [], this.domHandlersAttached = !1, this.client = e, this.options = t, this.scrollDepth = new _e(e),
|
|
445
|
+
this.logger = i, this.scrollDepth = null, this.customProperties = [], this.domHandlersAttached = !1, this.client = e, this.options = t, this.scrollDepth = new _e(e), le(this), Y(this);
|
|
424
446
|
}
|
|
425
447
|
isBrowserSupported() {
|
|
426
448
|
return typeof document < "u" && typeof document.addEventListener == "function";
|
|
@@ -435,7 +457,9 @@ const I = class I {
|
|
|
435
457
|
return;
|
|
436
458
|
}
|
|
437
459
|
if (!(document && document.body)) {
|
|
438
|
-
this.logger.debug(
|
|
460
|
+
this.logger.debug(
|
|
461
|
+
"Document not ready yet, trying again in 500 milliseconds..."
|
|
462
|
+
), setTimeout(() => this.init(), 500);
|
|
439
463
|
return;
|
|
440
464
|
}
|
|
441
465
|
this.addDomEventHandlers(), this.domHandlersAttached = !0;
|
|
@@ -457,15 +481,15 @@ const I = class I {
|
|
|
457
481
|
captureEvent(e) {
|
|
458
482
|
var i, s;
|
|
459
483
|
let t = this.getEventTarget(e);
|
|
460
|
-
if (
|
|
484
|
+
if (j(t) && (t = t.parentNode || null), e.type === "scroll")
|
|
461
485
|
return (i = this.scrollDepth) == null || i.track(), !0;
|
|
462
486
|
if (e.type === "visibilitychange" && document.visibilityState === "hidden" || e.type === "popstate")
|
|
463
487
|
return this.isPageRefresh() || (s = this.scrollDepth) == null || s.send(), !0;
|
|
464
|
-
if (t &&
|
|
488
|
+
if (t && pe(t, e)) {
|
|
465
489
|
const r = [t];
|
|
466
490
|
let o = t;
|
|
467
491
|
for (; o.parentNode && !y(o, "body"); ) {
|
|
468
|
-
if (
|
|
492
|
+
if (M(o.parentNode)) {
|
|
469
493
|
r.push(o.parentNode.host), o = o.parentNode.host;
|
|
470
494
|
continue;
|
|
471
495
|
}
|
|
@@ -474,7 +498,7 @@ const I = class I {
|
|
|
474
498
|
const a = [];
|
|
475
499
|
let l, c = !1;
|
|
476
500
|
if (w(r, (p) => {
|
|
477
|
-
const _ =
|
|
501
|
+
const _ = B(p);
|
|
478
502
|
p.tagName.toLowerCase() === "a" && (l = p.getAttribute("href"), l = _ && T(l) && l);
|
|
479
503
|
const u = x(p).split(" ");
|
|
480
504
|
S(u, "ph-no-capture") && (c = !0), a.push(
|
|
@@ -484,9 +508,9 @@ const I = class I {
|
|
|
484
508
|
this.options.maskAllText ?? !1
|
|
485
509
|
)
|
|
486
510
|
);
|
|
487
|
-
}), this.options.maskAllText || (a[0].$el_text =
|
|
511
|
+
}), this.options.maskAllText || (a[0].$el_text = Q(t)), l && (a[0].attr__href = l), c)
|
|
488
512
|
return !1;
|
|
489
|
-
const d =
|
|
513
|
+
const d = ue(
|
|
490
514
|
this.getDefaultProperties(e.type),
|
|
491
515
|
{
|
|
492
516
|
$elements: a
|
|
@@ -502,17 +526,20 @@ const I = class I {
|
|
|
502
526
|
w(i.event_selectors, (s) => {
|
|
503
527
|
const r = document.querySelectorAll(s);
|
|
504
528
|
w(r, (o) => {
|
|
505
|
-
S(e, o) &&
|
|
529
|
+
S(e, o) && B(o) && (t[i.name] = this.extractCustomPropertyValue(i));
|
|
506
530
|
});
|
|
507
531
|
});
|
|
508
532
|
}), t;
|
|
509
533
|
}
|
|
510
534
|
extractCustomPropertyValue(e) {
|
|
511
535
|
const t = [];
|
|
512
|
-
return w(
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
536
|
+
return w(
|
|
537
|
+
document.querySelectorAll(e.css_selector),
|
|
538
|
+
function(i) {
|
|
539
|
+
let s;
|
|
540
|
+
["input", "select"].indexOf(i.tagName.toLowerCase()) > -1 ? s = i.value : i.textContent && (s = i.textContent), T(s) && t.push(s);
|
|
541
|
+
}
|
|
542
|
+
), t.join(", ");
|
|
516
543
|
}
|
|
517
544
|
getEventTarget(e) {
|
|
518
545
|
var t;
|
|
@@ -522,12 +549,12 @@ const I = class I {
|
|
|
522
549
|
const s = e.tagName.toLowerCase(), r = {
|
|
523
550
|
tag_name: s
|
|
524
551
|
};
|
|
525
|
-
C.indexOf(s) > -1 && !i && (r.$el_text =
|
|
552
|
+
C.indexOf(s) > -1 && !i && (r.$el_text = Q(e));
|
|
526
553
|
const o = x(e);
|
|
527
554
|
o.length > 0 && (r.classes = o.split(" ").filter(function(d) {
|
|
528
555
|
return d !== "";
|
|
529
556
|
})), w(e.attributes, function(d) {
|
|
530
|
-
|
|
557
|
+
ee(e) && ["name", "id", "class"].indexOf(d.name) === -1 || !t && T(d.value) && !me(d.name) && (r["attr__" + d.name] = d.value);
|
|
531
558
|
});
|
|
532
559
|
let a = 1, l = 1, c = e;
|
|
533
560
|
for (; c = this.previousElementSibling(c); )
|
|
@@ -541,7 +568,7 @@ const I = class I {
|
|
|
541
568
|
let t = e;
|
|
542
569
|
do
|
|
543
570
|
t = t.previousSibling;
|
|
544
|
-
while (t && !
|
|
571
|
+
while (t && !G(t));
|
|
545
572
|
return t;
|
|
546
573
|
}
|
|
547
574
|
}
|
|
@@ -599,9 +626,13 @@ class Ee {
|
|
|
599
626
|
this.trackingHost = e, this.logger = i, this.config = t;
|
|
600
627
|
}
|
|
601
628
|
async send(e) {
|
|
602
|
-
const t = this.config.key, i = this.constructUrl(t), s = new Blob([JSON.stringify(e)], {
|
|
629
|
+
const t = this.config.key, i = this.constructUrl(t), s = new Blob([JSON.stringify(e)], {
|
|
630
|
+
type: "application/json"
|
|
631
|
+
});
|
|
603
632
|
if (navigator.sendBeacon(i, s))
|
|
604
|
-
this.logger.debug(
|
|
633
|
+
this.logger.debug(
|
|
634
|
+
`Successfully queued ${e.length} event(s) via Beacon API`
|
|
635
|
+
);
|
|
605
636
|
else
|
|
606
637
|
throw new Error("Failed to queue events via Beacon API");
|
|
607
638
|
}
|
|
@@ -612,7 +643,7 @@ class Ee {
|
|
|
612
643
|
// Note: Beacon API doesn't support custom headers, so we can't use them here.
|
|
613
644
|
// If custom headers are crucial, you might want to fall back to XHR or Fetch in those cases.
|
|
614
645
|
}
|
|
615
|
-
class
|
|
646
|
+
class W {
|
|
616
647
|
constructor(e, t, i = f()) {
|
|
617
648
|
this.trackingHost = e, this.logger = i, this.config = t;
|
|
618
649
|
}
|
|
@@ -669,7 +700,7 @@ class Pe {
|
|
|
669
700
|
this.logger.debug(`Response received. Status: ${e}, Body: ${t}`);
|
|
670
701
|
}
|
|
671
702
|
}
|
|
672
|
-
class
|
|
703
|
+
class te {
|
|
673
704
|
constructor(e, t) {
|
|
674
705
|
this.storage = {}, this.prefix = `usermaven_${e}_`, this.load(), this.logger = t || f();
|
|
675
706
|
}
|
|
@@ -728,10 +759,12 @@ class Ae {
|
|
|
728
759
|
this.storage = {};
|
|
729
760
|
}
|
|
730
761
|
}
|
|
731
|
-
class
|
|
762
|
+
class K {
|
|
732
763
|
// Default to true for server-side
|
|
733
764
|
constructor(e, t = 3, i = 1e3, s = 10, r = 1e3, o = f(), a = "default") {
|
|
734
|
-
this.transport = e, this.maxRetries = t, this.retryInterval = i, this.batchSize = s, this.batchInterval = r, this.logger = o, this.queue = [], this.processing = !1, this.batchTimeoutId = null, this.isOnline = !0, this.persistence = new
|
|
765
|
+
this.transport = e, this.maxRetries = t, this.retryInterval = i, this.batchSize = s, this.batchInterval = r, this.logger = o, this.queue = [], this.processing = !1, this.batchTimeoutId = null, this.isOnline = !0, this.persistence = new te(
|
|
766
|
+
`offline_queue_${a}`
|
|
767
|
+
), h() && (this.isOnline = navigator.onLine, this.loadQueueFromStorage(), this.initNetworkListeners(), this.scheduleBatch());
|
|
735
768
|
}
|
|
736
769
|
add(e) {
|
|
737
770
|
const t = { payload: e, retries: 0, timestamp: Date.now() };
|
|
@@ -745,14 +778,19 @@ class W {
|
|
|
745
778
|
}));
|
|
746
779
|
}
|
|
747
780
|
scheduleBatch() {
|
|
748
|
-
h() && (this.batchTimeoutId !== null && clearTimeout(this.batchTimeoutId), this.batchTimeoutId = window.setTimeout(
|
|
781
|
+
h() && (this.batchTimeoutId !== null && clearTimeout(this.batchTimeoutId), this.batchTimeoutId = window.setTimeout(
|
|
782
|
+
() => this.processBatch(),
|
|
783
|
+
this.batchInterval
|
|
784
|
+
));
|
|
749
785
|
}
|
|
750
786
|
async processBatch() {
|
|
751
787
|
if ((!h() || this.isOnline) && !this.processing && this.queue.length > 0) {
|
|
752
788
|
this.processing = !0;
|
|
753
789
|
const e = this.queue.splice(0, this.batchSize), t = e.map((i) => i.payload);
|
|
754
790
|
try {
|
|
755
|
-
await this.transport.send(t), this.logger.debug(
|
|
791
|
+
await this.transport.send(t), this.logger.debug(
|
|
792
|
+
`Successfully sent batch of ${e.length} payloads`
|
|
793
|
+
), h() && this.saveQueueToStorage();
|
|
756
794
|
} catch (i) {
|
|
757
795
|
this.logger.error("Failed to send batch", i), await this.handleBatchFailure(e);
|
|
758
796
|
}
|
|
@@ -762,7 +800,10 @@ class W {
|
|
|
762
800
|
}
|
|
763
801
|
async handleBatchFailure(e) {
|
|
764
802
|
for (const t of e)
|
|
765
|
-
t.retries < this.maxRetries ? (t.retries++, this.queue.unshift(t), this.logger.warn(`Retry attempt ${t.retries} for payload`)) : this.logger.error(
|
|
803
|
+
t.retries < this.maxRetries ? (t.retries++, this.queue.unshift(t), this.logger.warn(`Retry attempt ${t.retries} for payload`)) : this.logger.error(
|
|
804
|
+
"Max retries reached, discarding payload",
|
|
805
|
+
t.payload
|
|
806
|
+
);
|
|
766
807
|
h() && (this.saveQueueToStorage(), await new Promise((t) => setTimeout(t, this.retryInterval)));
|
|
767
808
|
}
|
|
768
809
|
loadQueueFromStorage() {
|
|
@@ -777,7 +818,7 @@ class W {
|
|
|
777
818
|
}
|
|
778
819
|
class Se {
|
|
779
820
|
constructor(e) {
|
|
780
|
-
this.clicks = [], this.threshold = 3, this.timeWindow = 2e3, this.distanceThreshold = 30, this.client = e, this.initializeEventListener(),
|
|
821
|
+
this.clicks = [], this.threshold = 3, this.timeWindow = 2e3, this.distanceThreshold = 30, this.client = e, this.initializeEventListener(), Y(this);
|
|
781
822
|
}
|
|
782
823
|
initializeEventListener() {
|
|
783
824
|
document.addEventListener("click", this.handleClick.bind(this));
|
|
@@ -791,14 +832,18 @@ class Se {
|
|
|
791
832
|
}
|
|
792
833
|
click(e, t, i) {
|
|
793
834
|
const s = { x: e, y: t, timestamp: i };
|
|
794
|
-
this.clicks.push(s), this.clicks = this.clicks.filter(
|
|
835
|
+
this.clicks.push(s), this.clicks = this.clicks.filter(
|
|
836
|
+
(r) => i - r.timestamp < this.timeWindow
|
|
837
|
+
), this.clicks.length >= this.threshold && this.checkRageClick();
|
|
795
838
|
}
|
|
796
839
|
checkRageClick() {
|
|
797
840
|
const e = this.clicks[0], i = (this.clicks[this.clicks.length - 1].timestamp - e.timestamp) / 1e3;
|
|
798
841
|
this.clicks.every((r, o) => {
|
|
799
842
|
if (o === 0) return !0;
|
|
800
843
|
const a = this.clicks[o - 1];
|
|
801
|
-
return Math.sqrt(
|
|
844
|
+
return Math.sqrt(
|
|
845
|
+
Math.pow(r.x - a.x, 2) + Math.pow(r.y - a.y, 2)
|
|
846
|
+
) < this.distanceThreshold;
|
|
802
847
|
}) && this.sendRageClickEvent(i);
|
|
803
848
|
}
|
|
804
849
|
sendRageClickEvent(e) {
|
|
@@ -845,7 +890,7 @@ class Ce {
|
|
|
845
890
|
return typeof this.config.customHeaders == "function" ? this.config.customHeaders() : this.config.customHeaders ? this.config.customHeaders : {};
|
|
846
891
|
}
|
|
847
892
|
}
|
|
848
|
-
class
|
|
893
|
+
class A {
|
|
849
894
|
constructor(e, t = "all", i = {}) {
|
|
850
895
|
this.instance = e, this.trackingType = t, this.options = i, document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", this.initialize.bind(this)) : this.initialize();
|
|
851
896
|
}
|
|
@@ -860,22 +905,27 @@ class P {
|
|
|
860
905
|
}
|
|
861
906
|
handleFormSubmit(e) {
|
|
862
907
|
const t = e.target, i = this._getFormDetails(t);
|
|
863
|
-
this.instance.track("$form",
|
|
908
|
+
this.instance.track("$form", V(i)), this.options.trackFieldChanges && this.trackFieldChanges(t);
|
|
864
909
|
}
|
|
865
910
|
trackFieldChanges(e) {
|
|
866
911
|
e.querySelectorAll("input, select, textarea").forEach((i) => {
|
|
867
912
|
i.addEventListener("change", (s) => {
|
|
868
|
-
const r = this._getFieldProps(
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
913
|
+
const r = this._getFieldProps(
|
|
914
|
+
s.target
|
|
915
|
+
);
|
|
916
|
+
this.instance.track(
|
|
917
|
+
"$form_field_change",
|
|
918
|
+
V({
|
|
919
|
+
form_id: e.id,
|
|
920
|
+
form_name: e.name || "",
|
|
921
|
+
field: r
|
|
922
|
+
})
|
|
923
|
+
);
|
|
874
924
|
});
|
|
875
925
|
});
|
|
876
926
|
}
|
|
877
927
|
static getInstance(e, t = "all", i = {}) {
|
|
878
|
-
return
|
|
928
|
+
return A.instance || (A.instance = new A(e, t, i)), A.instance;
|
|
879
929
|
}
|
|
880
930
|
_getFormDetails(e) {
|
|
881
931
|
const t = {
|
|
@@ -886,11 +936,17 @@ class P {
|
|
|
886
936
|
form_class: e.className,
|
|
887
937
|
form_attributes: this._getElementAttributes(e),
|
|
888
938
|
fields: []
|
|
889
|
-
}, i = e.querySelectorAll(
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
939
|
+
}, i = e.querySelectorAll(
|
|
940
|
+
"input, select, textarea"
|
|
941
|
+
);
|
|
942
|
+
return Array.from(i).filter(
|
|
943
|
+
(r) => !r.classList.contains("um-no-capture")
|
|
944
|
+
).forEach(
|
|
945
|
+
(r) => {
|
|
946
|
+
const o = this._getFieldProps(r);
|
|
947
|
+
t.fields.push(o);
|
|
948
|
+
}
|
|
949
|
+
), t;
|
|
894
950
|
}
|
|
895
951
|
_getFieldProps(e) {
|
|
896
952
|
const t = Object.keys(e.dataset).length ? this._convertDOMStringMapToObject(e.dataset) : void 0, i = this.getSafeText(e);
|
|
@@ -972,7 +1028,7 @@ class P {
|
|
|
972
1028
|
}
|
|
973
1029
|
class N {
|
|
974
1030
|
constructor(e) {
|
|
975
|
-
this.config = this.mergeConfig(e,
|
|
1031
|
+
this.config = this.mergeConfig(e, Z), this.logger = f(this.config.logLevel), this.namespace = e.namespace || "default", this.transport = this.initializeTransport(this.config), this.persistence = this.initializePersistence(), this.retryQueue = new K(
|
|
976
1032
|
this.transport,
|
|
977
1033
|
this.config.maxSendAttempts || 3,
|
|
978
1034
|
this.config.minSendTimeout || 1e3,
|
|
@@ -981,14 +1037,20 @@ class N {
|
|
|
981
1037
|
// Reduced interval to .2 second
|
|
982
1038
|
this.logger,
|
|
983
1039
|
this.namespace
|
|
984
|
-
), h() && this.initializeBrowserFeatures(), this.anonymousId = this.getOrCreateAnonymousId(), this.logger.info(
|
|
1040
|
+
), h() && this.initializeBrowserFeatures(), this.anonymousId = this.getOrCreateAnonymousId(), this.logger.info(
|
|
1041
|
+
`Usermaven client initialized for namespace: ${this.namespace}`
|
|
1042
|
+
);
|
|
985
1043
|
}
|
|
986
1044
|
initializeBrowserFeatures() {
|
|
987
|
-
if (this.cookieManager = new
|
|
1045
|
+
if (this.cookieManager = new se(this.config.cookieDomain), this.config.autocapture && H.enabledForProject(this.config.key) && !this.config.disableAutocaptureListenerRegistration && (this.autoCapture = new H(this, this.config, this.logger), this.autoCapture.init()), this.config.formTracking) {
|
|
988
1046
|
const e = this.config.formTracking === !0 ? "all" : this.config.formTracking;
|
|
989
|
-
this.formTracking =
|
|
990
|
-
|
|
991
|
-
|
|
1047
|
+
this.formTracking = A.getInstance(
|
|
1048
|
+
this,
|
|
1049
|
+
e || "none",
|
|
1050
|
+
{
|
|
1051
|
+
trackFieldChanges: !1
|
|
1052
|
+
}
|
|
1053
|
+
);
|
|
992
1054
|
}
|
|
993
1055
|
this.config.autoPageview && (this.pageviewTracking = new be(this)), this.config.crossDomainLinking && this.manageCrossDomainLinking(), this.config.rageClick && (this.rageClick = new Se(this)), this.setupPageLeaveTracking();
|
|
994
1056
|
}
|
|
@@ -1001,11 +1063,11 @@ class N {
|
|
|
1001
1063
|
const i = JSON.parse(JSON.stringify(e));
|
|
1002
1064
|
let s = { ...t, ...i };
|
|
1003
1065
|
return Object.keys(t).forEach((r) => {
|
|
1004
|
-
|
|
1066
|
+
P(t[r]) && (s[r] = this.mergeConfig(e[r], t[r]));
|
|
1005
1067
|
}), s;
|
|
1006
1068
|
}
|
|
1007
1069
|
init(e) {
|
|
1008
|
-
this.config = { ...this.config, ...e }, this.logger = f(this.config.logLevel), this.namespace = e.namespace || this.namespace, this.transport = this.initializeTransport(e), this.persistence = this.initializePersistence(), this.retryQueue = new
|
|
1070
|
+
this.config = { ...this.config, ...e }, this.logger = f(this.config.logLevel), this.namespace = e.namespace || this.namespace, this.transport = this.initializeTransport(e), this.persistence = this.initializePersistence(), this.retryQueue = new K(
|
|
1009
1071
|
this.transport,
|
|
1010
1072
|
this.config.maxSendAttempts || 3,
|
|
1011
1073
|
this.config.minSendTimeout || 1e3,
|
|
@@ -1014,7 +1076,9 @@ class N {
|
|
|
1014
1076
|
// Reduced interval to .25 second
|
|
1015
1077
|
this.logger,
|
|
1016
1078
|
this.namespace
|
|
1017
|
-
), h() && this.initializeBrowserFeatures(), this.anonymousId = this.getOrCreateAnonymousId(), this.logger.info(
|
|
1079
|
+
), h() && this.initializeBrowserFeatures(), this.anonymousId = this.getOrCreateAnonymousId(), this.logger.info(
|
|
1080
|
+
`Usermaven client reinitialized for namespace: ${this.namespace}`
|
|
1081
|
+
);
|
|
1018
1082
|
}
|
|
1019
1083
|
manageCrossDomainLinking() {
|
|
1020
1084
|
if (!this.config.crossDomainLinking || !this.config.domains)
|
|
@@ -1044,17 +1108,36 @@ class N {
|
|
|
1044
1108
|
return new Ce(e.trackingHost || t, e);
|
|
1045
1109
|
const i = "XMLHttpRequest" in window, s = typeof fetch < "u", r = typeof navigator < "u" && "sendBeacon" in navigator;
|
|
1046
1110
|
if (e.useBeaconApi && r)
|
|
1047
|
-
return new Ee(
|
|
1111
|
+
return new Ee(
|
|
1112
|
+
e.trackingHost || t,
|
|
1113
|
+
e,
|
|
1114
|
+
this.logger
|
|
1115
|
+
);
|
|
1048
1116
|
if (e.forceUseFetch && s)
|
|
1049
|
-
return new
|
|
1117
|
+
return new W(
|
|
1118
|
+
e.trackingHost || t,
|
|
1119
|
+
e,
|
|
1120
|
+
this.logger
|
|
1121
|
+
);
|
|
1050
1122
|
if (i)
|
|
1051
|
-
return new Pe(
|
|
1123
|
+
return new Pe(
|
|
1124
|
+
e.trackingHost || t,
|
|
1125
|
+
e,
|
|
1126
|
+
this.logger
|
|
1127
|
+
);
|
|
1052
1128
|
if (s)
|
|
1053
|
-
return new
|
|
1129
|
+
return new W(
|
|
1130
|
+
e.trackingHost || t,
|
|
1131
|
+
e,
|
|
1132
|
+
this.logger
|
|
1133
|
+
);
|
|
1054
1134
|
throw new Error("No suitable transport method available");
|
|
1055
1135
|
}
|
|
1056
1136
|
initializePersistence() {
|
|
1057
|
-
return this.config.disableEventPersistence || !h() ? new Ae() : new
|
|
1137
|
+
return this.config.disableEventPersistence || !h() ? new Ae() : new te(
|
|
1138
|
+
`${this.namespace}_${this.config.key}`,
|
|
1139
|
+
this.logger
|
|
1140
|
+
);
|
|
1058
1141
|
}
|
|
1059
1142
|
getOrCreateAnonymousId() {
|
|
1060
1143
|
var i, s;
|
|
@@ -1071,16 +1154,22 @@ class N {
|
|
|
1071
1154
|
}
|
|
1072
1155
|
t || (t = R());
|
|
1073
1156
|
const r = 365 * 10;
|
|
1074
|
-
(s = this.cookieManager) == null || s.set(
|
|
1157
|
+
(s = this.cookieManager) == null || s.set(
|
|
1158
|
+
e,
|
|
1159
|
+
t,
|
|
1160
|
+
r,
|
|
1161
|
+
document.location.protocol !== "http:",
|
|
1162
|
+
!1
|
|
1163
|
+
);
|
|
1075
1164
|
}
|
|
1076
1165
|
return t;
|
|
1077
1166
|
}
|
|
1078
1167
|
async id(e, t = !1) {
|
|
1079
|
-
if (!
|
|
1168
|
+
if (!P(e))
|
|
1080
1169
|
throw new Error("User data must be an object");
|
|
1081
|
-
if (e.email && !
|
|
1170
|
+
if (e.email && !J(e.email))
|
|
1082
1171
|
throw new Error("Invalid email provided");
|
|
1083
|
-
if (!e.id || !
|
|
1172
|
+
if (!e.id || !L(e.id))
|
|
1084
1173
|
throw new Error("User ID must be a string");
|
|
1085
1174
|
const i = e.id;
|
|
1086
1175
|
if (this.persistence.set("userId", i), this.persistence.set("userProps", e), !t) {
|
|
@@ -1095,15 +1184,34 @@ class N {
|
|
|
1095
1184
|
track(e, t, i = !1) {
|
|
1096
1185
|
this.trackInternal(e, t, i);
|
|
1097
1186
|
}
|
|
1187
|
+
lead(e, t = !1) {
|
|
1188
|
+
if (!P(e))
|
|
1189
|
+
throw new Error(
|
|
1190
|
+
"Lead payload must be a non-null object and not an array"
|
|
1191
|
+
);
|
|
1192
|
+
const i = e.email;
|
|
1193
|
+
if (!L(i)) {
|
|
1194
|
+
this.logger.error("Lead event requires a valid email attribute");
|
|
1195
|
+
return;
|
|
1196
|
+
}
|
|
1197
|
+
const s = i.trim();
|
|
1198
|
+
if (!s || !J(s)) {
|
|
1199
|
+
this.logger.error("Lead event requires a valid email attribute");
|
|
1200
|
+
return;
|
|
1201
|
+
}
|
|
1202
|
+
e.email = s, this.track("lead", e, t);
|
|
1203
|
+
}
|
|
1098
1204
|
trackInternal(e, t, i = !1) {
|
|
1099
1205
|
if (ve()) {
|
|
1100
1206
|
this.logger.debug("Tracking disabled due to um_exclusion setting");
|
|
1101
1207
|
return;
|
|
1102
1208
|
}
|
|
1103
|
-
if (!
|
|
1209
|
+
if (!L(e))
|
|
1104
1210
|
throw new Error("Event name must be a string");
|
|
1105
1211
|
if (t !== void 0 && (typeof t != "object" || t === null || Array.isArray(t)))
|
|
1106
|
-
throw new Error(
|
|
1212
|
+
throw new Error(
|
|
1213
|
+
"Event payload must be a non-null object and not an array"
|
|
1214
|
+
);
|
|
1107
1215
|
const r = this.createEventPayload(e, t);
|
|
1108
1216
|
try {
|
|
1109
1217
|
if (i) {
|
|
@@ -1116,15 +1224,17 @@ class N {
|
|
|
1116
1224
|
}
|
|
1117
1225
|
}
|
|
1118
1226
|
rawTrack(e) {
|
|
1119
|
-
if (!
|
|
1227
|
+
if (!P(e))
|
|
1120
1228
|
throw new Error("Event payload must be an object");
|
|
1121
1229
|
this.track("raw", e);
|
|
1122
1230
|
}
|
|
1123
1231
|
async group(e, t = !1) {
|
|
1124
|
-
if (!
|
|
1232
|
+
if (!P(e))
|
|
1125
1233
|
throw new Error("Company properties must be an object");
|
|
1126
1234
|
if (!e.id || !e.name || !e.created_at)
|
|
1127
|
-
throw new Error(
|
|
1235
|
+
throw new Error(
|
|
1236
|
+
"Company properties must include id, name, and created_at"
|
|
1237
|
+
);
|
|
1128
1238
|
this.persistence.set("companyProps", e), t || await this.track("group", e), this.logger.info("Company identified:", e);
|
|
1129
1239
|
}
|
|
1130
1240
|
createEventPayload(e, t) {
|
|
@@ -1149,7 +1259,9 @@ class N {
|
|
|
1149
1259
|
...a
|
|
1150
1260
|
};
|
|
1151
1261
|
if (e === "$autocapture") {
|
|
1152
|
-
const d = this.processAutocaptureAttributes(
|
|
1262
|
+
const d = this.processAutocaptureAttributes(
|
|
1263
|
+
t || {}
|
|
1264
|
+
);
|
|
1153
1265
|
c.autocapture_attributes = d;
|
|
1154
1266
|
} else e !== "user_identify" && e !== "group" && (Array.isArray(this.config.propertyBlacklist) && this.config.propertyBlacklist.forEach((d) => {
|
|
1155
1267
|
delete l[d];
|
|
@@ -1159,7 +1271,15 @@ class N {
|
|
|
1159
1271
|
processAutocaptureAttributes(e) {
|
|
1160
1272
|
let t = {};
|
|
1161
1273
|
const i = e.$elements || [];
|
|
1162
|
-
return i.length && (t = { ...i[0] }), t.el_text = t.$el_text || "", t.event_type = e.$event_type || "", [
|
|
1274
|
+
return i.length && (t = { ...i[0] }), t.el_text = t.$el_text || "", t.event_type = e.$event_type || "", [
|
|
1275
|
+
"$ce_version",
|
|
1276
|
+
"$event_type",
|
|
1277
|
+
"$initial_referrer",
|
|
1278
|
+
"$initial_referring_domain",
|
|
1279
|
+
"$referrer",
|
|
1280
|
+
"$referring_domain",
|
|
1281
|
+
"$elements"
|
|
1282
|
+
].forEach((s) => {
|
|
1163
1283
|
delete t[s];
|
|
1164
1284
|
}), delete t.$el_text, delete t.nth_child, delete t.nth_of_type, t;
|
|
1165
1285
|
}
|
|
@@ -1177,16 +1297,28 @@ class N {
|
|
|
1177
1297
|
}
|
|
1178
1298
|
getUtmParams() {
|
|
1179
1299
|
const e = {}, t = we(window.location.search);
|
|
1180
|
-
return [
|
|
1300
|
+
return [
|
|
1301
|
+
"utm_source",
|
|
1302
|
+
"utm_medium",
|
|
1303
|
+
"utm_campaign",
|
|
1304
|
+
"utm_term",
|
|
1305
|
+
"utm_content"
|
|
1306
|
+
].forEach((s) => {
|
|
1181
1307
|
t[s] && (e[s.replace("utm_", "")] = t[s]);
|
|
1182
1308
|
}), e;
|
|
1183
1309
|
}
|
|
1184
1310
|
pageview() {
|
|
1185
|
-
h() ? this.track(
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1311
|
+
h() ? this.track(
|
|
1312
|
+
"pageview",
|
|
1313
|
+
{
|
|
1314
|
+
url: window.location.href,
|
|
1315
|
+
referrer: document.referrer,
|
|
1316
|
+
title: document.title
|
|
1317
|
+
},
|
|
1318
|
+
!0
|
|
1319
|
+
) : this.logger.warn(
|
|
1320
|
+
"Pageview tracking is not available in server-side environments"
|
|
1321
|
+
);
|
|
1190
1322
|
}
|
|
1191
1323
|
setupPageLeaveTracking() {
|
|
1192
1324
|
if (!h()) return;
|
|
@@ -1221,10 +1353,13 @@ class N {
|
|
|
1221
1353
|
const t = this.config.cookieName || `__eventn_id_${this.config.key}`;
|
|
1222
1354
|
this.cookieManager.delete(t), this.anonymousId = this.getOrCreateAnonymousId();
|
|
1223
1355
|
}
|
|
1224
|
-
this.logger.info("core state reset", {
|
|
1356
|
+
this.logger.info("core state reset", {
|
|
1357
|
+
resetAnonId: e,
|
|
1358
|
+
namespace: this.namespace
|
|
1359
|
+
});
|
|
1225
1360
|
}
|
|
1226
1361
|
set(e, t) {
|
|
1227
|
-
if (!
|
|
1362
|
+
if (!P(e))
|
|
1228
1363
|
throw new Error("Properties must be an object");
|
|
1229
1364
|
const i = t == null ? void 0 : t.eventType, s = (t == null ? void 0 : t.persist) ?? !0;
|
|
1230
1365
|
if (i) {
|
|
@@ -1254,24 +1389,32 @@ class N {
|
|
|
1254
1389
|
let r = this.persistence.get("global_props") || {};
|
|
1255
1390
|
delete r[e], this.persistence.set("global_props", r);
|
|
1256
1391
|
}
|
|
1257
|
-
s && this.persistence.save(), this.logger.debug(
|
|
1392
|
+
s && this.persistence.save(), this.logger.debug(
|
|
1393
|
+
`Property unset: ${e}`,
|
|
1394
|
+
`Event type: ${i || "global"}`
|
|
1395
|
+
);
|
|
1258
1396
|
}
|
|
1259
1397
|
}
|
|
1260
|
-
function
|
|
1398
|
+
function ie() {
|
|
1261
1399
|
return typeof window < "u" && typeof window.define == "function" && window.define.amd;
|
|
1262
1400
|
}
|
|
1263
1401
|
function Te() {
|
|
1264
|
-
return
|
|
1402
|
+
return ie() ? window.define : void 0;
|
|
1265
1403
|
}
|
|
1266
1404
|
const $e = "__USERMAVEN_AUTOCAPTURE_INITIALIZED__";
|
|
1267
1405
|
function O(n) {
|
|
1268
|
-
const e = JSON.parse(JSON.stringify(n)), t =
|
|
1406
|
+
const e = JSON.parse(JSON.stringify(n)), t = z(e), i = {
|
|
1407
|
+
...Z,
|
|
1408
|
+
...t
|
|
1409
|
+
};
|
|
1269
1410
|
if (!i.key)
|
|
1270
1411
|
throw new Error("API key is required!");
|
|
1271
1412
|
if (!i.trackingHost)
|
|
1272
1413
|
throw new Error("Tracking host is required!");
|
|
1273
1414
|
const s = i.key || "", r = `${$e}${s}`;
|
|
1274
|
-
return h() && i.autocapture && window[r] && (console.warn(
|
|
1415
|
+
return h() && i.autocapture && window[r] && (console.warn(
|
|
1416
|
+
"Usermaven: Autocapture already initialized in another instance, skipping duplicate initialization."
|
|
1417
|
+
), i.disableAutocaptureListenerRegistration = !0), h() && i.autocapture && !i.disableAutocaptureListenerRegistration && (window[r] = !0), new N(i);
|
|
1275
1418
|
}
|
|
1276
1419
|
function xe(n) {
|
|
1277
1420
|
var s;
|
|
@@ -1295,7 +1438,10 @@ function xe(n) {
|
|
|
1295
1438
|
minSendTimeout: parseInt(n.getAttribute("data-min-send-timeout") || "", 10) || void 0,
|
|
1296
1439
|
maxSendTimeout: parseInt(n.getAttribute("data-max-send-timeout") || "", 10) || void 0,
|
|
1297
1440
|
maxSendAttempts: parseInt(n.getAttribute("data-max-send-attempts") || "", 10) || void 0,
|
|
1298
|
-
propertiesStringMaxLength: parseInt(
|
|
1441
|
+
propertiesStringMaxLength: parseInt(
|
|
1442
|
+
n.getAttribute("data-properties-string-max-length") || "",
|
|
1443
|
+
10
|
|
1444
|
+
) || null,
|
|
1299
1445
|
propertyBlacklist: ((s = n.getAttribute("data-property-blacklist")) == null ? void 0 : s.split(",")) || void 0,
|
|
1300
1446
|
exclude: n.getAttribute("data-exclude") || void 0,
|
|
1301
1447
|
namespace: n.getAttribute("data-namespace") || void 0,
|
|
@@ -1350,13 +1496,21 @@ function He(n, e) {
|
|
|
1350
1496
|
return e[g].apply(e, u.slice(1));
|
|
1351
1497
|
console.error(`Method ${g} not found on UsermavenClient`);
|
|
1352
1498
|
}
|
|
1353
|
-
const l = ["id", "group", "reset"], c = [
|
|
1499
|
+
const l = ["id", "group", "reset"], c = [
|
|
1500
|
+
"track",
|
|
1501
|
+
"lead",
|
|
1502
|
+
"pageview",
|
|
1503
|
+
"set",
|
|
1504
|
+
"unset",
|
|
1505
|
+
"rawTrack",
|
|
1506
|
+
"setUserId"
|
|
1507
|
+
];
|
|
1354
1508
|
[...l, ...c].forEach((u) => {
|
|
1355
1509
|
a[u] = function(...g) {
|
|
1356
1510
|
if (!t) {
|
|
1357
1511
|
if (l.includes(u))
|
|
1358
|
-
return new Promise((
|
|
1359
|
-
i.push([u, ...g, { resolve:
|
|
1512
|
+
return new Promise((q, m) => {
|
|
1513
|
+
i.push([u, ...g, { resolve: q, reject: m }]);
|
|
1360
1514
|
});
|
|
1361
1515
|
i.push([u, ...g]);
|
|
1362
1516
|
return;
|
|
@@ -1377,7 +1531,7 @@ function He(n, e) {
|
|
|
1377
1531
|
u && i.push(u);
|
|
1378
1532
|
}
|
|
1379
1533
|
}
|
|
1380
|
-
let
|
|
1534
|
+
let X = !1, U = null;
|
|
1381
1535
|
if (h()) {
|
|
1382
1536
|
const n = Te();
|
|
1383
1537
|
n && n("usermaven", [], function() {
|
|
@@ -1386,20 +1540,20 @@ if (h()) {
|
|
|
1386
1540
|
UsermavenClient: N,
|
|
1387
1541
|
LogLevel: k,
|
|
1388
1542
|
// Expose the script tag client if it exists
|
|
1389
|
-
getScriptTagClient: () =>
|
|
1543
|
+
getScriptTagClient: () => U
|
|
1390
1544
|
};
|
|
1391
|
-
}), typeof window < "u" && (window.usermavenClient = O, window.UsermavenClient = N, window.usermavenScriptTagClient = () =>
|
|
1545
|
+
}), typeof window < "u" && (window.usermavenClient = O, window.UsermavenClient = N, window.usermavenScriptTagClient = () => U), function(e, t) {
|
|
1392
1546
|
const i = e.currentScript;
|
|
1393
1547
|
function s() {
|
|
1394
|
-
return
|
|
1548
|
+
return X || !i || !i.hasAttribute("data-key") || i.getAttribute("data-no-auto-init") === "true" ? !1 : i.src.includes("lib.js");
|
|
1395
1549
|
}
|
|
1396
1550
|
function r() {
|
|
1397
|
-
s() && (console.log("[Usermaven] Auto-initializing from script tag"),
|
|
1551
|
+
s() && (console.log("[Usermaven] Auto-initializing from script tag"), U = xe(i), X = !0);
|
|
1398
1552
|
}
|
|
1399
1553
|
typeof t < "u" && i && (e.readyState === "loading" ? e.addEventListener("DOMContentLoaded", r) : r());
|
|
1400
1554
|
}(document, window);
|
|
1401
1555
|
}
|
|
1402
|
-
typeof module < "u" && module.exports && !
|
|
1556
|
+
typeof module < "u" && module.exports && !ie() && (module.exports = {
|
|
1403
1557
|
usermavenClient: O,
|
|
1404
1558
|
UsermavenClient: N,
|
|
1405
1559
|
Config: void 0,
|
|
@@ -1450,6 +1604,7 @@ const createNoopClient = () => ({
|
|
|
1450
1604
|
trackPageView: () => { },
|
|
1451
1605
|
id: () => __awaiter(void 0, void 0, void 0, function* () { }),
|
|
1452
1606
|
track: () => { },
|
|
1607
|
+
lead: () => { },
|
|
1453
1608
|
rawTrack: () => { },
|
|
1454
1609
|
set: () => { },
|
|
1455
1610
|
unset: () => { },
|
|
@@ -1462,11 +1617,13 @@ function useUsermaven() {
|
|
|
1462
1617
|
const id = useCallback((userData, doNotSendEvent) => client.id(userData, doNotSendEvent), [client]);
|
|
1463
1618
|
const trackPageView = useCallback(() => client.track('pageview'), [client]);
|
|
1464
1619
|
const track = useCallback((typeName, payload) => client.track(typeName, payload), [client]);
|
|
1620
|
+
const lead = useCallback((payload, directSend) => client.lead(payload, directSend), [client]);
|
|
1465
1621
|
const rawTrack = useCallback((payload) => client.rawTrack(payload), [client]);
|
|
1466
1622
|
const set = useCallback((properties, opts) => client.set(properties, opts), [client]);
|
|
1467
1623
|
const unset = useCallback((propertyName, opts) => client.unset(propertyName, opts), [client]);
|
|
1468
1624
|
return Object.assign(Object.assign({}, client), { id,
|
|
1469
1625
|
track,
|
|
1626
|
+
lead,
|
|
1470
1627
|
trackPageView,
|
|
1471
1628
|
rawTrack,
|
|
1472
1629
|
set,
|
|
@@ -1714,9 +1871,9 @@ function hasSetMethod(cookies) {
|
|
|
1714
1871
|
}
|
|
1715
1872
|
function middlewareEnv(req, res, opts = {}) {
|
|
1716
1873
|
return {
|
|
1717
|
-
getAnonymousId({ name, domain }) {
|
|
1874
|
+
getAnonymousId({ name, domain, }) {
|
|
1718
1875
|
if (opts === null || opts === void 0 ? void 0 : opts.disableCookies) {
|
|
1719
|
-
return
|
|
1876
|
+
return '';
|
|
1720
1877
|
}
|
|
1721
1878
|
let cookie;
|
|
1722
1879
|
if (hasGetMethod(req.cookies)) {
|
|
@@ -1732,7 +1889,7 @@ function middlewareEnv(req, res, opts = {}) {
|
|
|
1732
1889
|
const cookieOpts = {
|
|
1733
1890
|
maxAge: 31622400 * 10,
|
|
1734
1891
|
httpOnly: false,
|
|
1735
|
-
path:
|
|
1892
|
+
path: '/',
|
|
1736
1893
|
};
|
|
1737
1894
|
if (domain) {
|
|
1738
1895
|
cookieOpts.domain = domain;
|
|
@@ -1744,36 +1901,42 @@ function middlewareEnv(req, res, opts = {}) {
|
|
|
1744
1901
|
value: newId,
|
|
1745
1902
|
maxAge: cookieOpts.maxAge,
|
|
1746
1903
|
domain: cookieOpts.domain,
|
|
1747
|
-
httpOnly: cookieOpts.httpOnly
|
|
1904
|
+
httpOnly: cookieOpts.httpOnly,
|
|
1748
1905
|
});
|
|
1749
1906
|
}
|
|
1750
1907
|
else {
|
|
1751
|
-
res.headers.set(
|
|
1908
|
+
res.headers.set('Set-Cookie', serialize_1(name, newId, cookieOpts));
|
|
1752
1909
|
}
|
|
1753
1910
|
return newId;
|
|
1754
1911
|
},
|
|
1755
1912
|
getSourceIp() {
|
|
1756
|
-
let ip = req.headers.get(
|
|
1757
|
-
|
|
1913
|
+
let ip = req.headers.get('x-forwarded-for') ||
|
|
1914
|
+
req.headers.get('x-real-ip') ||
|
|
1915
|
+
'';
|
|
1916
|
+
return ip && ip.split(',')[0].trim();
|
|
1758
1917
|
},
|
|
1759
1918
|
describeClient() {
|
|
1760
1919
|
var _a;
|
|
1761
|
-
const requestHost = req.headers.get(
|
|
1762
|
-
|
|
1920
|
+
const requestHost = req.headers.get('x-forwarded-host') ||
|
|
1921
|
+
req.headers.get('host') ||
|
|
1922
|
+
req.nextUrl.hostname;
|
|
1923
|
+
const proto = req.headers.get('x-forwarded-proto') ||
|
|
1924
|
+
((_a = req.nextUrl.protocol) === null || _a === void 0 ? void 0 : _a.replace(':', ''));
|
|
1763
1925
|
let query = req.nextUrl.search;
|
|
1764
1926
|
let path = req.nextUrl.pathname;
|
|
1765
1927
|
return {
|
|
1766
|
-
doc_encoding:
|
|
1928
|
+
doc_encoding: '',
|
|
1767
1929
|
doc_host: requestHost,
|
|
1768
1930
|
doc_path: req.url,
|
|
1769
1931
|
doc_search: query,
|
|
1770
|
-
page_title:
|
|
1771
|
-
referer: req.headers.get(
|
|
1772
|
-
screen_resolution:
|
|
1773
|
-
url: `${proto}://${requestHost}${path ||
|
|
1774
|
-
user_agent: req.headers.get(
|
|
1775
|
-
user_language: req.headers.get(
|
|
1776
|
-
|
|
1932
|
+
page_title: '',
|
|
1933
|
+
referer: req.headers.get('referrer'),
|
|
1934
|
+
screen_resolution: '',
|
|
1935
|
+
url: `${proto}://${requestHost}${path || ''}${query || ''}`,
|
|
1936
|
+
user_agent: req.headers.get('user-agent'),
|
|
1937
|
+
user_language: req.headers.get('accept-language') &&
|
|
1938
|
+
req.headers.get('accept-language').split(',')[0],
|
|
1939
|
+
vp_size: '',
|
|
1777
1940
|
};
|
|
1778
1941
|
},
|
|
1779
1942
|
};
|
package/lib/middlewareEnv.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { NextRequest, NextResponse } from
|
|
2
|
-
import { ClientProperties } from
|
|
1
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
+
import { ClientProperties } from '@usermaven/sdk-js';
|
|
3
3
|
declare function middlewareEnv(req: NextRequest, res: NextResponse, opts?: {
|
|
4
4
|
disableCookies?: boolean;
|
|
5
5
|
}): {
|
|
6
|
-
getAnonymousId({ name, domain }: {
|
|
6
|
+
getAnonymousId({ name, domain, }: {
|
|
7
7
|
name: string;
|
|
8
8
|
domain?: string;
|
|
9
9
|
}): string;
|
package/lib/middlewareEnv.js
CHANGED
|
@@ -9,9 +9,9 @@ function hasSetMethod(cookies) {
|
|
|
9
9
|
}
|
|
10
10
|
function middlewareEnv(req, res, opts = {}) {
|
|
11
11
|
return {
|
|
12
|
-
getAnonymousId({ name, domain }) {
|
|
12
|
+
getAnonymousId({ name, domain, }) {
|
|
13
13
|
if (opts === null || opts === void 0 ? void 0 : opts.disableCookies) {
|
|
14
|
-
return
|
|
14
|
+
return '';
|
|
15
15
|
}
|
|
16
16
|
let cookie;
|
|
17
17
|
if (hasGetMethod(req.cookies)) {
|
|
@@ -27,7 +27,7 @@ function middlewareEnv(req, res, opts = {}) {
|
|
|
27
27
|
const cookieOpts = {
|
|
28
28
|
maxAge: 31622400 * 10,
|
|
29
29
|
httpOnly: false,
|
|
30
|
-
path:
|
|
30
|
+
path: '/',
|
|
31
31
|
};
|
|
32
32
|
if (domain) {
|
|
33
33
|
cookieOpts.domain = domain;
|
|
@@ -39,36 +39,42 @@ function middlewareEnv(req, res, opts = {}) {
|
|
|
39
39
|
value: newId,
|
|
40
40
|
maxAge: cookieOpts.maxAge,
|
|
41
41
|
domain: cookieOpts.domain,
|
|
42
|
-
httpOnly: cookieOpts.httpOnly
|
|
42
|
+
httpOnly: cookieOpts.httpOnly,
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
45
|
else {
|
|
46
|
-
res.headers.set(
|
|
46
|
+
res.headers.set('Set-Cookie', (0, cookie_1.serialize)(name, newId, cookieOpts));
|
|
47
47
|
}
|
|
48
48
|
return newId;
|
|
49
49
|
},
|
|
50
50
|
getSourceIp() {
|
|
51
|
-
let ip = req.headers.get(
|
|
52
|
-
|
|
51
|
+
let ip = req.headers.get('x-forwarded-for') ||
|
|
52
|
+
req.headers.get('x-real-ip') ||
|
|
53
|
+
'';
|
|
54
|
+
return ip && ip.split(',')[0].trim();
|
|
53
55
|
},
|
|
54
56
|
describeClient() {
|
|
55
57
|
var _a;
|
|
56
|
-
const requestHost = req.headers.get(
|
|
57
|
-
|
|
58
|
+
const requestHost = req.headers.get('x-forwarded-host') ||
|
|
59
|
+
req.headers.get('host') ||
|
|
60
|
+
req.nextUrl.hostname;
|
|
61
|
+
const proto = req.headers.get('x-forwarded-proto') ||
|
|
62
|
+
((_a = req.nextUrl.protocol) === null || _a === void 0 ? void 0 : _a.replace(':', ''));
|
|
58
63
|
let query = req.nextUrl.search;
|
|
59
64
|
let path = req.nextUrl.pathname;
|
|
60
65
|
return {
|
|
61
|
-
doc_encoding:
|
|
66
|
+
doc_encoding: '',
|
|
62
67
|
doc_host: requestHost,
|
|
63
68
|
doc_path: req.url,
|
|
64
69
|
doc_search: query,
|
|
65
|
-
page_title:
|
|
66
|
-
referer: req.headers.get(
|
|
67
|
-
screen_resolution:
|
|
68
|
-
url: `${proto}://${requestHost}${path ||
|
|
69
|
-
user_agent: req.headers.get(
|
|
70
|
-
user_language: req.headers.get(
|
|
71
|
-
|
|
70
|
+
page_title: '',
|
|
71
|
+
referer: req.headers.get('referrer'),
|
|
72
|
+
screen_resolution: '',
|
|
73
|
+
url: `${proto}://${requestHost}${path || ''}${query || ''}`,
|
|
74
|
+
user_agent: req.headers.get('user-agent'),
|
|
75
|
+
user_language: req.headers.get('accept-language') &&
|
|
76
|
+
req.headers.get('accept-language').split(',')[0],
|
|
77
|
+
vp_size: '',
|
|
72
78
|
};
|
|
73
79
|
},
|
|
74
80
|
};
|
package/lib/usePageView.d.ts
CHANGED
package/lib/useUsermaven.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { EventPayload, UserProps } from
|
|
1
|
+
import { EventPayload, UserProps } from '@usermaven/sdk-js';
|
|
2
2
|
export type UsermavenClient = {
|
|
3
3
|
trackPageView: () => void;
|
|
4
4
|
id: (userData: UserProps, doNotSendEvent?: boolean) => Promise<void>;
|
|
5
5
|
track: (typeName: string, payload?: EventPayload) => void;
|
|
6
|
+
lead: (payload: EventPayload, directSend?: boolean) => void;
|
|
6
7
|
rawTrack: (payload: any) => void;
|
|
7
8
|
set: (properties: Record<string, any>, opts?: {
|
|
8
9
|
eventType?: string;
|
package/lib/useUsermaven.js
CHANGED
|
@@ -15,6 +15,7 @@ const createNoopClient = () => ({
|
|
|
15
15
|
trackPageView: () => { },
|
|
16
16
|
id: () => __awaiter(void 0, void 0, void 0, function* () { }),
|
|
17
17
|
track: () => { },
|
|
18
|
+
lead: () => { },
|
|
18
19
|
rawTrack: () => { },
|
|
19
20
|
set: () => { },
|
|
20
21
|
unset: () => { },
|
|
@@ -27,11 +28,13 @@ function useUsermaven() {
|
|
|
27
28
|
const id = (0, react_1.useCallback)((userData, doNotSendEvent) => client.id(userData, doNotSendEvent), [client]);
|
|
28
29
|
const trackPageView = (0, react_1.useCallback)(() => client.track('pageview'), [client]);
|
|
29
30
|
const track = (0, react_1.useCallback)((typeName, payload) => client.track(typeName, payload), [client]);
|
|
31
|
+
const lead = (0, react_1.useCallback)((payload, directSend) => client.lead(payload, directSend), [client]);
|
|
30
32
|
const rawTrack = (0, react_1.useCallback)((payload) => client.rawTrack(payload), [client]);
|
|
31
33
|
const set = (0, react_1.useCallback)((properties, opts) => client.set(properties, opts), [client]);
|
|
32
34
|
const unset = (0, react_1.useCallback)((propertyName, opts) => client.unset(propertyName, opts), [client]);
|
|
33
35
|
return Object.assign(Object.assign({}, client), { id,
|
|
34
36
|
track,
|
|
37
|
+
lead,
|
|
35
38
|
trackPageView,
|
|
36
39
|
rawTrack,
|
|
37
40
|
set,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usermaven/nextjs",
|
|
3
|
-
"version": "1.5.10-rc.
|
|
3
|
+
"version": "1.5.10-rc.111",
|
|
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.10-rc.
|
|
21
|
+
"@usermaven/sdk-js": "1.5.10-rc.111",
|
|
22
22
|
"cookie": "^0.5.0"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|