@usermaven/nextjs 1.4.4 → 1.5.0-rc.90

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/index.es.js CHANGED
@@ -1,2668 +1,1379 @@
1
1
  import * as React from 'react';
2
- import { createContext, useContext, useCallback, useEffect } from 'react';
3
- import { useRouter } from 'next/router';
2
+ import { createContext, useContext, useCallback, useEffect, useState } from 'react';
4
3
 
5
4
  const UsermavenContext = createContext(null);
6
5
 
7
- const JitsuProvider = function ({ children, client }) {
6
+ const UsermavenProvider = function ({ children, client }) {
8
7
  const Context = UsermavenContext;
9
8
  return React.createElement(Context.Provider, { value: client }, children);
10
9
  };
11
10
 
12
- /******************************************************************************
13
- Copyright (c) Microsoft Corporation.
14
-
15
- Permission to use, copy, modify, and/or distribute this software for any
16
- purpose with or without fee is hereby granted.
17
-
18
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
19
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
20
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
21
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
22
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
23
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
24
- PERFORMANCE OF THIS SOFTWARE.
25
- ***************************************************************************** */
26
-
27
- var __assign = function() {
28
- __assign = Object.assign || function __assign(t) {
29
- for (var s, i = 1, n = arguments.length; i < n; i++) {
30
- s = arguments[i];
31
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
32
- }
33
- return t;
34
- };
35
- return __assign.apply(this, arguments);
36
- };
37
-
38
- function __rest(s, e) {
39
- var t = {};
40
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
41
- t[p] = s[p];
42
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
43
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
44
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
45
- t[p[i]] = s[p[i]];
46
- }
47
- return t;
48
- }
49
-
50
- function __awaiter(thisArg, _arguments, P, generator) {
51
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
52
- return new (P || (P = Promise))(function (resolve, reject) {
53
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
54
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
55
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
56
- step((generator = generator.apply(thisArg, _arguments || [])).next());
57
- });
58
- }
59
-
60
- function __generator(thisArg, body) {
61
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
62
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
63
- function verb(n) { return function (v) { return step([n, v]); }; }
64
- function step(op) {
65
- if (f) throw new TypeError("Generator is already executing.");
66
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
67
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
68
- if (y = 0, t) op = [op[0] & 2, t.value];
69
- switch (op[0]) {
70
- case 0: case 1: t = op; break;
71
- case 4: _.label++; return { value: op[1], done: false };
72
- case 5: _.label++; y = op[1]; op = [0]; continue;
73
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
74
- default:
75
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
76
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
77
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
78
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
79
- if (t[2]) _.ops.pop();
80
- _.trys.pop(); continue;
81
- }
82
- op = body.call(thisArg, _);
83
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
84
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
85
- }
86
- }
87
-
88
- function __spreadArray(to, from, pack) {
89
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
90
- if (ar || !(i in from)) {
91
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
92
- ar[i] = from[i];
93
- }
94
- }
95
- return to.concat(ar || Array.prototype.slice.call(from));
96
- }
97
-
98
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
99
- var e = new Error(message);
100
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
101
- };
102
-
103
- var LogLevels = {
104
- DEBUG: { name: "DEBUG", severity: 10 },
105
- INFO: { name: "INFO", severity: 100 },
106
- WARN: { name: "WARN", severity: 1000 },
107
- ERROR: { name: "ERROR", severity: 10000 },
108
- NONE: { name: "NONE", severity: 10000 }
109
- };
110
- var rootLogger = null;
111
- /**
112
- * Create logger or return cached instance
113
- */
114
- function getLogger() {
115
- if (rootLogger) {
116
- return rootLogger;
117
- }
118
- else {
119
- return rootLogger = createLogger();
120
- }
11
+ var v = /* @__PURE__ */ ((i) => (i[i.DEBUG = 0] = "DEBUG", i[i.INFO = 1] = "INFO", i[i.WARN = 2] = "WARN", i[i.ERROR = 3] = "ERROR", i))(v || {});
12
+ class W {
13
+ constructor(e) {
14
+ this.level = e;
15
+ }
16
+ debug(e, ...t) {
17
+ this.level <= 0 && console.debug("[Usermaven Debug]:", e, ...t);
18
+ }
19
+ info(e, ...t) {
20
+ this.level <= 1 && console.info("[Usermaven Info]:", e, ...t);
21
+ }
22
+ warn(e, ...t) {
23
+ this.level <= 2 && console.warn("[Usermaven Warning]:", e, ...t);
24
+ }
25
+ error(e, ...t) {
26
+ this.level <= 3 && console.error("[Usermaven Error]:", e, ...t);
27
+ }
121
28
  }
122
- function setRootLogLevel(logLevelName) {
123
- var logLevel = LogLevels[logLevelName.toLocaleUpperCase()];
124
- if (!logLevel) {
125
- console.warn("Can't find log level with name " + logLevelName.toLocaleUpperCase() + ", defaulting to INFO");
126
- logLevel = LogLevels.INFO;
127
- }
128
- rootLogger = createLogger(logLevel);
129
- return rootLogger;
29
+ function d(i = 0) {
30
+ return new W(i);
130
31
  }
131
- function setDebugVar(name, val) {
132
- if (!isWindowAvailable()) {
133
- return;
134
- }
135
- var win = window;
136
- if (!win.__usermavenDebug) {
137
- win.__usermavenDebug = {};
32
+ const U = {
33
+ logLevel: v.ERROR,
34
+ useBeaconApi: !1,
35
+ forceUseFetch: !1,
36
+ trackingHost: "t.usermaven.com",
37
+ autocapture: !1,
38
+ rageClick: !1,
39
+ formTracking: !1,
40
+ autoPageview: !1,
41
+ disableEventPersistence: !1,
42
+ gaHook: !1,
43
+ segmentHook: !1,
44
+ randomizeUrl: !1,
45
+ capture3rdPartyCookies: ["_ga", "_fbp", "_ym_uid", "ajs_user_id", "ajs_anonymous_id"],
46
+ idMethod: "cookie",
47
+ ipPolicy: "keep",
48
+ cookiePolicy: "keep",
49
+ minSendTimeout: 0,
50
+ maxSendTimeout: 2e3,
51
+ maxSendAttempts: 4,
52
+ propertiesStringMaxLength: null,
53
+ propertyBlacklist: [],
54
+ crossDomainLinking: !0,
55
+ maskAllText: !1,
56
+ maskAllElementAttributes: !1
57
+ };
58
+ class X {
59
+ constructor(e) {
60
+ this.domain = e, this.cookieDomain = this.getCookieDomain();
61
+ }
62
+ set(e, t, s = 365, n = !0, r = !1) {
63
+ const o = /* @__PURE__ */ new Date();
64
+ o.setTime(o.getTime() + s * 24 * 60 * 60 * 1e3);
65
+ const c = `expires=${o.toUTCString()}`, l = n ? "; Secure" : "", a = r ? "; HttpOnly" : "";
66
+ document.cookie = `${e}=${t};${c};path=/;domain=${this.cookieDomain}${l}${a}`;
67
+ }
68
+ get(e) {
69
+ const t = e + "=", s = document.cookie.split(";");
70
+ for (let n = 0; n < s.length; n++) {
71
+ let r = s[n].trim();
72
+ if (r.indexOf(t) === 0)
73
+ return decodeURIComponent(r.substring(t.length));
138
74
  }
139
- win.__usermavenDebug[name] = val;
75
+ return null;
76
+ }
77
+ delete(e, t = "/") {
78
+ document.cookie = `${e}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${t};domain=${this.cookieDomain}`;
79
+ }
80
+ getCookieDomain() {
81
+ return typeof window > "u" || this.domain ? this.domain || "" : this.extractRoot(window.location.hostname);
82
+ }
83
+ extractRoot(e) {
84
+ if (this.isIpAddress(e) || e === "localhost")
85
+ return e;
86
+ let t = this.extractTopLevelDomain(e);
87
+ return t || (t = this.extractRootDomain(e)), "." + t;
88
+ }
89
+ isIpAddress(e) {
90
+ const t = e.split(".");
91
+ return t.length === 4 && t.every((s) => !isNaN(Number(s)));
92
+ }
93
+ extractHostname(e) {
94
+ let t;
95
+ return e.indexOf("//") > -1 ? t = e.split("/")[2] : t = e.split("/")[0], t = t.split(":")[0], t = t.split("?")[0], t;
96
+ }
97
+ extractRootDomain(e) {
98
+ let t = this.extractHostname(e);
99
+ const s = t.split("."), n = s.length;
100
+ return n > 2 && (s[n - 1].length == 2 ? (t = s[n - 2] + "." + s[n - 1], s[n - 2].length == 2 && (t = s[n - 3] + "." + t)) : t = s[n - 2] + "." + s[n - 1]), t;
101
+ }
102
+ extractTopLevelDomain(e) {
103
+ const t = /[a-z0-9][a-z0-9-]+\.[a-z.]{2,6}$/i, s = e.match(t);
104
+ return s ? s[0] : "";
105
+ }
140
106
  }
141
- /**
142
- * Creates a loggger with given log-level
143
- * @param logLevel
144
- */
145
- function createLogger(logLevel) {
146
- var globalLogLevel = isWindowAvailable() && window['__eventNLogLevel'];
147
- var minLogLevel = LogLevels.WARN;
148
- if (globalLogLevel) {
149
- var level = LogLevels[globalLogLevel.toUpperCase()];
150
- if (level && level > 0) {
151
- minLogLevel = level;
152
- }
153
- }
154
- else if (logLevel) {
155
- minLogLevel = logLevel;
107
+ const K = Object.prototype, G = K.hasOwnProperty, Y = Array.prototype, E = Y.forEach, A = {};
108
+ function Z(i, e, t) {
109
+ if (Array.isArray(i)) {
110
+ if (E && i.forEach === E)
111
+ i.forEach(e, t);
112
+ else if ("length" in i && i.length === +i.length) {
113
+ for (let s = 0, n = i.length; s < n; s++)
114
+ if (s in i && e.call(t, i[s], s) === A)
115
+ return;
156
116
  }
157
- var logger = { minLogLevel: minLogLevel };
158
- Object.values(LogLevels).forEach(function (_a) {
159
- var name = _a.name, severity = _a.severity;
160
- logger[name.toLowerCase()] = function () {
161
- var args = [];
162
- for (var _i = 0; _i < arguments.length; _i++) {
163
- args[_i] = arguments[_i];
164
- }
165
- if (severity >= minLogLevel.severity && args.length > 0) {
166
- var message = args[0];
167
- var msgArgs = args.splice(1);
168
- var msgFormatted = "[J-" + name + "] " + message;
169
- if (name === 'DEBUG' || name === 'INFO') {
170
- console.log.apply(console, __spreadArray([msgFormatted], msgArgs, false));
171
- }
172
- else if (name === 'WARN') {
173
- console.warn.apply(console, __spreadArray([msgFormatted], msgArgs, false));
174
- }
175
- else {
176
- console.error.apply(console, __spreadArray([msgFormatted], msgArgs, false));
177
- }
178
- }
179
- };
180
- });
181
- setDebugVar("logger", logger);
182
- return logger;
183
- }
184
-
185
- /**
186
- * Checks if global variable 'window' is available. If it's available,
187
- * code runs in browser environment
188
- */
189
-
190
- function isWindowAvailable(warnMsg = undefined) {
191
- //here we check not only of window object is globally available, but also if it's not a fake one
192
- //react-native do have a window object, but it's not a real one: https://stackoverflow.com/questions/49911424/what-does-the-variable-window-represent-in-react-native
193
- const windowAvailable = !!globalThis.window && !!globalThis.window.document && !!globalThis.window.location;
194
-
195
- if (!windowAvailable && warnMsg) {
196
- getLogger().warn(warnMsg);
197
117
  }
198
- return windowAvailable;
199
118
  }
200
-
201
-
202
- /**
203
- * @param msg
204
- * @return {Window}
205
- */
206
- function requireWindow(msg = undefined) {
207
- if (!isWindowAvailable()) {
208
- throw new Error(msg || "window' is not available. Seems like this code runs outside browser environment. It shouldn't happen")
119
+ const x = function(i) {
120
+ return i.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, "");
121
+ }, j = function(i) {
122
+ for (const e in i)
123
+ typeof i[e] == "function" && (i[e] = i[e].bind(i));
124
+ };
125
+ function f(i, e, t) {
126
+ if (i != null) {
127
+ if (E && Array.isArray(i) && i.forEach === E)
128
+ i.forEach(e, t);
129
+ else if ("length" in i && i.length === +i.length) {
130
+ for (let s = 0, n = i.length; s < n; s++)
131
+ if (s in i && e.call(t, i[s], s) === A)
132
+ return;
133
+ } else
134
+ for (const s in i)
135
+ if (G.call(i, s) && e.call(t, i[s], s) === A)
136
+ return;
209
137
  }
210
- return window;
211
138
  }
212
-
213
- // Note: updated this method to test on staging (Ref:: https://github.com/PostHog/posthog-js/blob/master/src/storage.ts#L42)
214
- // Commented out some jitsu cookies setters that are not bring used in posthog-js
215
- function serializeCookie(name, val, opt) {
216
- if (opt === void 0) { opt = {}; }
217
- try {
218
- var maxAge = opt.maxAge, domain = opt.domain, path = opt.path, expires = opt.expires, httpOnly = opt.httpOnly, secure = opt.secure, sameSite = opt.sameSite;
219
- var new_cookie_val = name + "=" + encodeURIComponent(val);
220
- if (domain) {
221
- new_cookie_val += "; domain=" + domain;
222
- }
223
- if (path) {
224
- new_cookie_val += "; path=" + path;
225
- }
226
- else {
227
- new_cookie_val += "; path=/";
228
- }
229
- if (expires) {
230
- new_cookie_val += "; expires=" + expires.toUTCString();
231
- }
232
- if (maxAge) {
233
- new_cookie_val += "; max-age=" + maxAge;
234
- }
235
- if (httpOnly) {
236
- new_cookie_val += "; httponly";
237
- }
238
- if (secure) {
239
- new_cookie_val += "; secure";
240
- }
241
- if (sameSite) {
242
- var sameSiteAttr = typeof sameSite === "string"
243
- ? sameSite.toLowerCase()
244
- : sameSite;
245
- switch (sameSiteAttr) {
246
- case true:
247
- new_cookie_val += "; SameSite=Strict";
248
- break;
249
- case "lax":
250
- new_cookie_val += "; SameSite=Lax";
251
- break;
252
- case "strict":
253
- new_cookie_val += "; SameSite=Strict";
254
- break;
255
- case "none":
256
- new_cookie_val += "; SameSite=None";
257
- break;
258
- }
259
- }
260
- else if (secure) {
261
- /**
262
- * SameSite=None - means that the browser sends the cookie with both cross-site and same-site requests.
263
- * The Secure attribute must also be set when setting this value, like so SameSite=None; Secure.
264
- * If Secure is missing an error will be logged.
265
- *
266
- * https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#samesitesamesite-value
267
- */
268
- new_cookie_val += "; SameSite=None";
269
- }
270
- return new_cookie_val;
271
- }
272
- catch (e) {
273
- getLogger().error("serializeCookie", e);
274
- return '';
275
- }
139
+ const ee = function(i, ...e) {
140
+ return Z(e, function(t) {
141
+ for (const s in t)
142
+ t[s] !== void 0 && (i[s] = t[s]);
143
+ }), i;
144
+ };
145
+ function _(i, e) {
146
+ return i.indexOf(e) !== -1;
276
147
  }
277
-
278
- // Courtesy: https://stackoverflow.com/a/23945027
279
- function extractHostname(url) {
280
- var hostname;
281
- //find & remove protocol (http, ftp, etc.) and get hostname
282
- if (url.indexOf("//") > -1) {
283
- hostname = url.split('/')[2];
284
- }
148
+ const te = function(i) {
149
+ try {
150
+ return /^\s*\bfunction\b/.test(i);
151
+ } catch {
152
+ return !1;
153
+ }
154
+ }, ie = function(i) {
155
+ return i === void 0;
156
+ }, m = function() {
157
+ const i = function(s, n, r, o, c) {
158
+ if (!s) {
159
+ d().error("No valid element provided to register_event");
160
+ return;
161
+ }
162
+ if (s.addEventListener && !o)
163
+ s.addEventListener(n, r, !!c);
285
164
  else {
286
- hostname = url.split('/')[0];
287
- }
288
- //find & remove port number
289
- hostname = hostname.split(':')[0];
290
- //find & remove "?"
291
- hostname = hostname.split('?')[0];
292
- return hostname;
293
- }
294
- // Warning: you can use this function to extract the "root" domain, but it will not be as accurate as using the psl package.
295
- // https://www.npmjs.com/package/psl
296
- var extractRootDomain = function (url) {
297
- var domain = extractHostname(url), splitArr = domain.split('.'), arrLen = splitArr.length;
298
- // extracting the root domain here
299
- // if there is a subdomain
300
- if (arrLen > 2) {
301
- if (splitArr[arrLen - 1].length == 2) {
302
- // likely a ccTLD
303
- domain = splitArr[arrLen - 2] + '.' + splitArr[arrLen - 1];
304
- // if the second level domain is also two letters (like co.uk), include the next part up
305
- if (splitArr[arrLen - 2].length == 2) {
306
- domain = splitArr[arrLen - 3] + '.' + domain;
307
- }
308
- }
309
- else {
310
- // likely a gTLD
311
- domain = splitArr[arrLen - 2] + '.' + splitArr[arrLen - 1];
312
- }
313
- }
314
- return domain;
315
- };
316
- var extractTopLevelDomain = function (url) {
317
- var DOMAIN_MATCH_REGEX = /[a-z0-9][a-z0-9-]+\.[a-z.]{2,6}$/i;
318
- var matches = url.match(DOMAIN_MATCH_REGEX), domain = matches ? matches[0] : '';
319
- return domain;
320
- };
321
- var extractRoot = function (url) {
322
- var domainParts = url.split(".");
323
- var domainLength = domainParts.length;
324
- // Check if it's an IP address
325
- if (domainLength === 4 && domainParts.every(function (part) { return !isNaN(part); })) {
326
- return url;
327
- }
328
- var rootDomain = extractTopLevelDomain(url);
329
- if (!rootDomain) { // If it's not a top level domain, use a fallback method
330
- rootDomain = extractRootDomain(url);
331
- }
332
- return rootDomain;
333
- };
334
- var getCookieDomain = function () {
335
- if (isWindowAvailable()) {
336
- // const domain = window.location.hostname.replace("www.", "")
337
- //
338
- // // Check if subdomain is set, if yes, we remove the subdomain from the cookie domain and return the root domain with a leading dot
339
- // // This is to ensure that cookies are set correctly for cross domain tracking
340
- // const subdomain = domain.split('.')[0]
341
- // if (subdomain) {
342
- // return '.' + extractRootDomain(domain)
343
- // }
344
- return extractRoot(window.location.hostname);
165
+ const l = "on" + n, a = s[l];
166
+ s[l] = e(s, r, a);
345
167
  }
346
- return undefined;
168
+ };
169
+ function e(s, n, r) {
170
+ return function(o) {
171
+ if (o = o || t(window.event), !o)
172
+ return;
173
+ let c = !0, l;
174
+ te(r) && (l = r(o));
175
+ const a = n.call(s, o);
176
+ return (l === !1 || a === !1) && (c = !1), c;
177
+ };
178
+ }
179
+ function t(s) {
180
+ return s && (s.preventDefault = t.preventDefault, s.stopPropagation = t.stopPropagation), s;
181
+ }
182
+ return t.preventDefault = function() {
183
+ this.returnValue = !1;
184
+ }, t.stopPropagation = function() {
185
+ this.cancelBubble = !0;
186
+ }, i;
187
+ }(), se = function(i) {
188
+ return function(...e) {
189
+ try {
190
+ return i.apply(this, e);
191
+ } catch (t) {
192
+ d().error("Implementation error. Please turn on debug and contact support@usermaven.com.", t);
193
+ }
194
+ };
195
+ }, z = function(i) {
196
+ for (const e in i)
197
+ typeof i[e] == "function" && (i[e] = se(i[e]));
347
198
  };
348
- var cookieParsingCache;
349
- function parseCookieString(cookieStr) {
350
- if (!cookieStr) {
351
- return {};
352
- }
353
- var res = {};
354
- var cookies = cookieStr.split(";");
355
- for (var i = 0; i < cookies.length; i++) {
356
- var cookie = cookies[i];
357
- var idx = cookie.indexOf("=");
358
- if (idx > 0) {
359
- res[cookie.substr(i > 0 ? 1 : 0, i > 0 ? idx - 1 : idx)] = cookie.substr(idx + 1);
360
- }
361
- }
362
- return res;
199
+ function R(i) {
200
+ for (let e in i)
201
+ (i[e] === "" || i[e] === null || i[e] === void 0 || typeof i[e] == "object" && Object.keys(i[e]).length === 0) && delete i[e];
202
+ return i;
363
203
  }
364
- function copyAttributes(source, target) {
365
- return Array.from(source.attributes).forEach(function (attribute) {
366
- target.setAttribute(attribute.nodeName, attribute.nodeValue);
367
- });
204
+ function u() {
205
+ try {
206
+ return typeof window < "u" && window.document !== void 0 && window.document.createElement !== void 0;
207
+ } catch {
208
+ return d().warn("window is not available"), !1;
209
+ }
368
210
  }
369
- function insertAndExecute(element, html) {
370
- element.innerHTML = html;
371
- var scripts = element.getElementsByTagName("script");
372
- var index;
373
- for (index = scripts.length - 1; index >= 0; index--) {
374
- var script = scripts[index];
375
- var tag = document.createElement("script");
376
- copyAttributes(script, tag);
377
- if (script.innerHTML) {
378
- tag.innerHTML = script.innerHTML;
379
- }
380
- tag.setAttribute("data-usermaven-tag-id", element.id);
381
- document.getElementsByTagName("head")[0].appendChild(tag);
382
- scripts[index].parentNode.removeChild(scripts[index]);
383
- }
211
+ function p(i = 5) {
212
+ const e = new Uint8Array(i);
213
+ return crypto.getRandomValues(e), Array.from(e, (t) => t.toString(36).padStart(2, "0")).join("").slice(0, i);
384
214
  }
385
- var getCookies = function (useCache) {
386
- if (useCache === void 0) { useCache = false; }
387
- if (useCache && cookieParsingCache) {
388
- return cookieParsingCache;
389
- }
390
- var res = parseCookieString(document.cookie);
391
- cookieParsingCache = res;
392
- return res;
393
- };
394
- // Methods partially borrowed from quirksmode.org/js/cookies.html
395
- var getCookie = function (name) {
396
- if (!name) {
397
- return null;
398
- }
399
- try {
400
- var nameEQ = name + '=';
401
- var ca = requireWindow().document.cookie.split(';');
402
- for (var i = 0; i < ca.length; i++) {
403
- var c = ca[i];
404
- while (c.charAt(0) == ' ') {
405
- c = c.substring(1, c.length);
406
- }
407
- if (c.indexOf(nameEQ) === 0) {
408
- return decodeURIComponent(c.substring(nameEQ.length, c.length));
409
- }
410
- }
411
- }
412
- catch (err) {
413
- getLogger().error("getCookies", err);
414
- }
415
- return null;
416
- };
417
- var setCookie = function (name, value, opts) {
418
- if (opts === void 0) { opts = {}; }
419
- requireWindow().document.cookie = serializeCookie(name, value, opts);
420
- };
421
- var deleteCookie = function (name, path) {
422
- if (path === void 0) { path = "/"; }
423
- document.cookie = name + "= ; SameSite=Strict; expires = Thu, 01 Jan 1970 00:00:00 GMT" + (path ? ("; path = " + path) : "");
424
- };
425
- var generateId = function () { return Math.random().toString(36).substring(2, 12); };
426
- var getUmExclusionState = function () {
427
- var state = "false";
428
- if (typeof window !== 'undefined' && window.localStorage) {
429
- state = localStorage.getItem("um_exclusion");
430
- }
431
- return state === undefined || state === null || state === "false" ? false : true;
432
- };
433
- var generateRandom = function () { return Math.random().toString(36).substring(2, 7); };
434
- var parseQuery = function (qs) {
435
- if (!qs) {
436
- return {};
437
- }
438
- var queryString = qs.length > 0 && qs.charAt(0) === "?" ? qs.substring(1) : qs;
439
- var query = {};
440
- var pairs = (queryString[0] === "?" ? queryString.substr(1) : queryString).split("&");
441
- for (var i = 0; i < pairs.length; i++) {
442
- var pair = pairs[i].split("=");
443
- query[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1] || "");
444
- }
445
- return query;
446
- };
447
- var UTM_TYPES = {
448
- utm_source: "source",
449
- utm_medium: "medium",
450
- utm_campaign: "campaign",
451
- utm_term: "term",
452
- utm_content: "content"
453
- };
454
- var CLICK_IDS = {
455
- gclid: true,
456
- fbclid: true,
457
- dclid: true
458
- };
459
- var getDataFromParams = function (params) {
460
- var result = {
461
- utm: {},
462
- click_id: {},
463
- };
464
- for (var name in params) {
465
- if (!params.hasOwnProperty(name)) {
466
- continue;
467
- }
468
- var val = params[name];
469
- var utm = UTM_TYPES[name];
470
- if (utm) {
471
- result.utm[utm] = val;
472
- }
473
- else if (CLICK_IDS[name]) {
474
- result.click_id[name] = val;
475
- }
476
- }
477
- return result;
478
- };
479
- //2020-08-24T13:42:16.439Z -> 2020-08-24T13:42:16.439123Z
480
- var reformatDate = function (strDate) {
481
- var end = strDate.split(".")[1];
482
- if (!end) {
483
- return strDate;
484
- }
485
- if (end.length >= 7) {
486
- return strDate;
487
- }
488
- return strDate.slice(0, -1) + "0".repeat(7 - end.length) + "Z";
489
- };
490
- function endsWith(str, suffix) {
491
- return str.indexOf(suffix, str.length - suffix.length) !== -1;
215
+ function ne(i) {
216
+ return i.replace(
217
+ /([-_][a-z])/g,
218
+ (e) => e.toUpperCase().replace("-", "").replace("_", "")
219
+ );
492
220
  }
493
- var getHostWithProtocol = function (host) {
494
- while (endsWith(host, "/")) {
495
- host = host.substr(0, host.length - 1);
496
- }
497
- if (host.indexOf("https://") === 0 || host.indexOf("http://") === 0) {
498
- return host;
499
- }
500
- else {
501
- return "https://" + host;
502
- }
503
- };
504
-
505
- var MemoryQueue = /** @class */ (function () {
506
- function MemoryQueue() {
507
- this.queue = [];
508
- }
509
- MemoryQueue.prototype.flush = function () {
510
- var queue = this.queue;
511
- this.queue = [];
512
- return queue;
513
- };
514
- MemoryQueue.prototype.push = function () {
515
- var _a;
516
- var values = [];
517
- for (var _i = 0; _i < arguments.length; _i++) {
518
- values[_i] = arguments[_i];
519
- }
520
- (_a = this.queue).push.apply(_a, values);
521
- };
522
- return MemoryQueue;
523
- }());
524
- var LocalStorageQueue = /** @class */ (function () {
525
- function LocalStorageQueue(key) {
526
- this.key = key;
527
- }
528
- LocalStorageQueue.prototype.flush = function () {
529
- var queue = this.get();
530
- if (queue.length) {
531
- this.set([]);
532
- }
533
- return queue;
534
- };
535
- LocalStorageQueue.prototype.push = function () {
536
- var values = [];
537
- for (var _i = 0; _i < arguments.length; _i++) {
538
- values[_i] = arguments[_i];
539
- }
540
- var queue = this.get();
541
- queue.push.apply(queue, values);
542
- this.set(queue);
543
- };
544
- LocalStorageQueue.prototype.set = function (queue) {
545
- localStorage.setItem(this.key, JSON.stringify(queue));
546
- };
547
- LocalStorageQueue.prototype.get = function () {
548
- var data = localStorage.getItem(this.key);
549
- if (data !== null && data !== "") {
550
- return JSON.parse(data);
551
- }
552
- return [];
553
- };
554
- return LocalStorageQueue;
555
- }());
556
-
557
- var ObjProto = Object.prototype;
558
- var toString = ObjProto.toString;
559
- var hasOwnProperty = ObjProto.hasOwnProperty;
560
- var ArrayProto = Array.prototype;
561
- var nativeForEach = ArrayProto.forEach, nativeIsArray = Array.isArray, breaker = {};
562
- var _isArray = nativeIsArray ||
563
- function (obj) {
564
- return toString.call(obj) === '[object Array]';
565
- };
566
- function _eachArray(obj, iterator, thisArg) {
567
- if (Array.isArray(obj)) {
568
- if (nativeForEach && obj.forEach === nativeForEach) {
569
- obj.forEach(iterator, thisArg);
570
- }
571
- else if ('length' in obj && obj.length === +obj.length) {
572
- for (var i = 0, l = obj.length; i < l; i++) {
573
- if (i in obj && iterator.call(thisArg, obj[i], i) === breaker) {
574
- return;
575
- }
576
- }
577
- }
578
- }
221
+ function H(i) {
222
+ return typeof i != "object" || i === null ? i : Array.isArray(i) ? i.map(H) : Object.keys(i).reduce((e, t) => {
223
+ const s = ne(t);
224
+ return e[s] = H(i[t]), e;
225
+ }, {});
579
226
  }
580
- // Embed part of the Underscore Library
581
- var _trim = function (str) {
582
- return str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
583
- };
584
- var _bind_instance_methods = function (obj) {
585
- for (var func in obj) {
586
- if (typeof obj[func] === 'function') {
587
- obj[func] = obj[func].bind(obj);
588
- }
589
- }
590
- };
591
- /**
592
- * @param {*=} obj
593
- * @param {function(...*)=} iterator
594
- * @param {Object=} thisArg
595
- */
596
- function _each(obj, iterator, thisArg) {
597
- if (obj === null || obj === undefined) {
598
- return;
599
- }
600
- if (nativeForEach && Array.isArray(obj) && obj.forEach === nativeForEach) {
601
- obj.forEach(iterator, thisArg);
602
- }
603
- else if ('length' in obj && obj.length === +obj.length) {
604
- for (var i = 0, l = obj.length; i < l; i++) {
605
- if (i in obj && iterator.call(thisArg, obj[i], i) === breaker) {
606
- return;
607
- }
608
- }
609
- }
610
- else {
611
- for (var key in obj) {
612
- if (hasOwnProperty.call(obj, key)) {
613
- if (iterator.call(thisArg, obj[key], key) === breaker) {
614
- return;
615
- }
616
- }
617
- }
618
- }
227
+ function $(i) {
228
+ switch (typeof i.className) {
229
+ case "string":
230
+ return i.className;
231
+ case "object":
232
+ return ("baseVal" in i.className ? i.className.baseVal : null) || i.getAttribute("class") || "";
233
+ default:
234
+ return "";
235
+ }
619
236
  }
620
- var _extend = function (obj) {
621
- var args = [];
622
- for (var _i = 1; _i < arguments.length; _i++) {
623
- args[_i - 1] = arguments[_i];
624
- }
625
- _eachArray(args, function (source) {
626
- for (var prop in source) {
627
- if (source[prop] !== void 0) {
628
- obj[prop] = source[prop];
629
- }
630
- }
631
- });
632
- return obj;
633
- };
634
- function _includes(str, needle) {
635
- return str.indexOf(needle) !== -1;
237
+ function L(i) {
238
+ let e = "";
239
+ return O(i) && !M(i) && i.childNodes && i.childNodes.length && f(i.childNodes, function(t) {
240
+ B(t) && t.textContent && (e += x(t.textContent).split(/(\s+)/).filter(P).join("").replace(/[\r\n]/g, " ").replace(/[ ]+/g, " ").substring(0, 255));
241
+ }), x(e);
636
242
  }
637
- // from a comment on http://dbj.org/dbj/?p=286
638
- // fails on only one very rare and deliberate custom object:
639
- // let bomb = { toString : undefined, valueOf: function(o) { return "function BOMBA!"; }};
640
- var _isFunction = function (f) {
641
- try {
642
- return /^\s*\bfunction\b/.test(f);
643
- }
644
- catch (x) {
645
- return false;
646
- }
647
- };
648
- var _isUndefined = function (obj) {
649
- return obj === void 0;
650
- };
651
- var _register_event = (function () {
652
- // written by Dean Edwards, 2005
653
- // with input from Tino Zijdel - crisp@xs4all.nl
654
- // with input from Carl Sverre - mail@carlsverre.com
655
- // with input from PostHog
656
- // http://dean.edwards.name/weblog/2005/10/add-event/
657
- // https://gist.github.com/1930440
658
- /**
659
- * @param {Object} element
660
- * @param {string} type
661
- * @param {function(...*)} handler
662
- * @param {boolean=} oldSchool
663
- * @param {boolean=} useCapture
664
- */
665
- var register_event = function (element, type, handler, oldSchool, useCapture) {
666
- if (!element) {
667
- getLogger().error('No valid element provided to register_event');
668
- return;
669
- }
670
- if (element.addEventListener && !oldSchool) {
671
- element.addEventListener(type, handler, !!useCapture);
672
- }
673
- else {
674
- var ontype = 'on' + type;
675
- var old_handler = element[ontype] // can be undefined
676
- ;
677
- element[ontype] = makeHandler(element, handler, old_handler);
678
- }
679
- };
680
- function makeHandler(element, new_handler, old_handlers) {
681
- return function (event) {
682
- event = event || fixEvent(window.event);
683
- // this basically happens in firefox whenever another script
684
- // overwrites the onload callback and doesn't pass the event
685
- // object to previously defined callbacks. All the browsers
686
- // that don't define window.event implement addEventListener
687
- // so the dom_loaded handler will still be fired as usual.
688
- if (!event) {
689
- return undefined;
690
- }
691
- var ret = true;
692
- var old_result;
693
- if (_isFunction(old_handlers)) {
694
- old_result = old_handlers(event);
695
- }
696
- var new_result = new_handler.call(element, event);
697
- if (false === old_result || false === new_result) {
698
- ret = false;
699
- }
700
- return ret;
701
- };
702
- }
703
- function fixEvent(event) {
704
- if (event) {
705
- event.preventDefault = fixEvent.preventDefault;
706
- event.stopPropagation = fixEvent.stopPropagation;
707
- }
708
- return event;
709
- }
710
- fixEvent.preventDefault = function () {
711
- this.returnValue = false;
712
- };
713
- fixEvent.stopPropagation = function () {
714
- this.cancelBubble = true;
715
- };
716
- return register_event;
717
- })();
718
- var _safewrap = function (f) {
719
- return function () {
720
- var args = [];
721
- for (var _i = 0; _i < arguments.length; _i++) {
722
- args[_i] = arguments[_i];
723
- }
724
- try {
725
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
726
- // @ts-ignore
727
- return f.apply(this, args);
728
- }
729
- catch (e) {
730
- getLogger().error('Implementation error. Please turn on debug and contact support@usermaven.com.', e);
731
- // if (Config.DEBUG) {
732
- // getLogger.critical(e)
733
- // }
734
- }
735
- };
736
- };
737
- var _safewrap_instance_methods = function (obj) {
738
- for (var func in obj) {
739
- if (typeof obj[func] === 'function') {
740
- obj[func] = _safewrap(obj[func]);
741
- }
742
- }
743
- };
744
- var COPY_IN_PROGRESS_ATTRIBUTE = typeof Symbol !== 'undefined' ? Symbol('__deepCircularCopyInProgress__') : '__deepCircularCopyInProgress__';
745
- /**
746
- * Deep copies an object.
747
- * It handles cycles by replacing all references to them with `undefined`
748
- * Also supports customizing native values
749
- *
750
- * @param value
751
- * @param customizer
752
- * @param [key] if provided this is the object key associated with the value to be copied. It allows the customizer function to have context when it runs
753
- * @returns {{}|undefined|*}
754
- */
755
- function deepCircularCopy(value, customizer, key) {
756
- if (value !== Object(value))
757
- return customizer ? customizer(value, key) : value; // primitive value
758
- if (value[COPY_IN_PROGRESS_ATTRIBUTE])
759
- return undefined;
760
- value[COPY_IN_PROGRESS_ATTRIBUTE] = true;
761
- var result;
762
- if (_isArray(value)) {
763
- result = [];
764
- _eachArray(value, function (it) {
765
- result.push(deepCircularCopy(it, customizer));
766
- });
767
- }
768
- else {
769
- result = {};
770
- _each(value, function (val, key) {
771
- if (key !== COPY_IN_PROGRESS_ATTRIBUTE) {
772
- result[key] = deepCircularCopy(val, customizer, key);
773
- }
774
- });
775
- }
776
- delete value[COPY_IN_PROGRESS_ATTRIBUTE];
777
- return result;
243
+ function q(i) {
244
+ return !!i && i.nodeType === 1;
778
245
  }
779
- var LONG_STRINGS_ALLOW_LIST = ['$performance_raw'];
780
- function _copyAndTruncateStrings(object, maxStringLength) {
781
- return deepCircularCopy(object, function (value, key) {
782
- if (key && LONG_STRINGS_ALLOW_LIST.indexOf(key) > -1) {
783
- return value;
784
- }
785
- if (typeof value === 'string' && maxStringLength !== null) {
786
- return value.slice(0, maxStringLength);
787
- }
788
- return value;
789
- });
246
+ function g(i, e) {
247
+ return !!i && !!i.tagName && i.tagName.toLowerCase() === e.toLowerCase();
790
248
  }
791
- // Function to find the closest link element
792
- function _findClosestLink(element) {
793
- while (element && element.tagName) {
794
- if (element.tagName.toLowerCase() == 'a') {
795
- return element;
796
- }
797
- element = element.parentNode;
798
- }
799
- return null;
249
+ function B(i) {
250
+ return !!i && i.nodeType === 3;
800
251
  }
801
- function _cleanObject(obj) {
802
- for (var propName in obj) {
803
- if (obj[propName] === '' || obj[propName] === null || obj[propName] === undefined || (typeof obj[propName] === 'object' && Object.keys(obj[propName]).length === 0)) {
804
- delete obj[propName];
805
- }
806
- }
807
- return obj;
252
+ function N(i) {
253
+ return !!i && i.nodeType === 11;
808
254
  }
809
-
810
- /*
811
- * Get the className of an element, accounting for edge cases where element.className is an object
812
- * @param {Element} el - element to get the className of
813
- * @returns {string} the element's class
814
- */
815
- function getClassName(el) {
816
- switch (typeof el.className) {
817
- case 'string':
818
- return el.className;
819
- // TODO: when is this ever used?
820
- case 'object': // handle cases where className might be SVGAnimatedString or some other type
821
- return ('baseVal' in el.className ? el.className.baseVal : null) || el.getAttribute('class') || '';
822
- default:
823
- // future proof
824
- return '';
255
+ const b = ["a", "button", "form", "input", "select", "textarea", "label"];
256
+ function re(i, e) {
257
+ if (!i || g(i, "html") || !q(i))
258
+ return !1;
259
+ let t = i;
260
+ for (; t && !g(t, "body"); ) {
261
+ if (t.classList && t.classList.contains("um-no-capture"))
262
+ return !1;
263
+ t.parentNode && N(t.parentNode) ? t = t.parentNode.host : t = t.parentNode;
264
+ }
265
+ let s = !1;
266
+ for (t = i; t && !g(t, "body"); ) {
267
+ if (t.parentNode && N(t.parentNode)) {
268
+ t = t.parentNode.host, t && b.indexOf(t.tagName.toLowerCase()) > -1 && (s = !0);
269
+ continue;
270
+ }
271
+ const o = t.parentNode;
272
+ if (!o) break;
273
+ if (b.indexOf(o.tagName.toLowerCase()) > -1)
274
+ s = !0;
275
+ else {
276
+ const c = window.getComputedStyle(o);
277
+ c && c.getPropertyValue("cursor") === "pointer" && (s = !0);
825
278
  }
279
+ t = o;
280
+ }
281
+ const n = window.getComputedStyle(i);
282
+ if (n && n.getPropertyValue("cursor") === "pointer" && e.type === "click")
283
+ return !0;
284
+ const r = i.tagName.toLowerCase();
285
+ switch (r) {
286
+ case "html":
287
+ return !1;
288
+ case "form":
289
+ return e.type === "submit";
290
+ case "input":
291
+ return e.type === "change" || e.type === "click";
292
+ case "select":
293
+ case "textarea":
294
+ return e.type === "change" || e.type === "click";
295
+ default:
296
+ return s ? e.type === "click" : e.type === "click" && (b.indexOf(r) > -1 || i.getAttribute("contenteditable") === "true");
297
+ }
826
298
  }
827
- /*
828
- * Get the direct text content of an element, protecting against sensitive data collection.
829
- * Concats textContent of each of the element's text node children; this avoids potential
830
- * collection of sensitive data that could happen if we used element.textContent and the
831
- * element had sensitive child elements, since element.textContent includes child content.
832
- * Scrubs values that look like they could be sensitive (i.e. cc or ssn number).
833
- * @param {Element} el - element to get the text of
834
- * @returns {string} the element's direct text content
835
- */
836
- function getSafeText(el) {
837
- var elText = '';
838
- if (shouldCaptureElement(el) && !isSensitiveElement(el) && el.childNodes && el.childNodes.length) {
839
- _each(el.childNodes, function (child) {
840
- if (isTextNode(child) && child.textContent) {
841
- elText += _trim(child.textContent)
842
- // scrub potentially sensitive values
843
- .split(/(\s+)/)
844
- .filter(shouldCaptureValue)
845
- .join('')
846
- // normalize whitespace
847
- .replace(/[\r\n]/g, ' ')
848
- .replace(/[ ]+/g, ' ')
849
- // truncate
850
- .substring(0, 255);
851
- }
852
- });
853
- }
854
- return _trim(elText);
299
+ function O(i) {
300
+ for (let s = i; s.parentNode && !g(s, "body"); s = s.parentNode) {
301
+ const n = $(s).split(" ");
302
+ if (_(n, "ph-sensitive") || _(n, "ph-no-capture"))
303
+ return !1;
304
+ }
305
+ if (_($(i).split(" "), "ph-include"))
306
+ return !0;
307
+ const e = i.type || "";
308
+ if (typeof e == "string")
309
+ switch (e.toLowerCase()) {
310
+ case "hidden":
311
+ return !1;
312
+ case "password":
313
+ return !1;
314
+ }
315
+ const t = i.name || i.id || "";
316
+ 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, "")));
855
317
  }
856
- /*
857
- * Check whether an element has nodeType Node.ELEMENT_NODE
858
- * @param {Element} el - element to check
859
- * @returns {boolean} whether el is of the correct nodeType
860
- */
861
- function isElementNode(el) {
862
- return !!el && el.nodeType === 1; // Node.ELEMENT_NODE - use integer constant for browser portability
318
+ function M(i) {
319
+ const e = ["button", "checkbox", "submit", "reset"];
320
+ return !!(g(i, "input") && !e.includes(i.type) || g(i, "select") || g(i, "textarea") || i.getAttribute("contenteditable") === "true");
863
321
  }
864
- /*
865
- * Check whether an element is of a given tag type.
866
- * Due to potential reference discrepancies (such as the webcomponents.js polyfill),
867
- * we want to match tagNames instead of specific references because something like
868
- * element === document.body won't always work because element might not be a native
869
- * element.
870
- * @param {Element} el - element to check
871
- * @param {string} tag - tag name (e.g., "div")
872
- * @returns {boolean} whether el is of the given tag type
873
- */
874
- function isTag(el, tag) {
875
- return !!el && !!el.tagName && el.tagName.toLowerCase() === tag.toLowerCase();
322
+ function P(i) {
323
+ return !(i === null || ie(i) || typeof i == "string" && (i = x(i), /^(?:(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((i || "").replace(/[- ]/g, "")) || /(^\d{3}-?\d{2}-?\d{4}$)/.test(i)));
876
324
  }
877
- /*
878
- * Check whether an element has nodeType Node.TEXT_NODE
879
- * @param {Element} el - element to check
880
- * @returns {boolean} whether el is of the correct nodeType
881
- */
882
- function isTextNode(el) {
883
- return !!el && el.nodeType === 3; // Node.TEXT_NODE - use integer constant for browser portability
325
+ function oe(i) {
326
+ return typeof i == "string" ? i.substring(0, 10) === "_ngcontent" || i.substring(0, 7) === "_nghost" : !1;
884
327
  }
885
- /*
886
- * Check whether an element has nodeType Node.DOCUMENT_FRAGMENT_NODE
887
- * @param {Element} el - element to check
888
- * @returns {boolean} whether el is of the correct nodeType
889
- */
890
- function isDocumentFragment(el) {
891
- return !!el && el.nodeType === 11; // Node.DOCUMENT_FRAGMENT_NODE - use integer constant for browser portability
328
+ function T() {
329
+ return p(10);
892
330
  }
893
- var usefulElements = ['a', 'button', 'form', 'input', 'select', 'textarea', 'label'];
894
- /*
895
- * Check whether a DOM event should be "captured" or if it may contain sentitive data
896
- * using a variety of heuristics.
897
- * @param {Element} el - element to check
898
- * @param {Event} event - event to check
899
- * @returns {boolean} whether the event should be captured
900
- */
901
- function shouldCaptureDomEvent(el, event) {
902
- if (!el || isTag(el, 'html') || !isElementNode(el)) {
903
- return false;
904
- }
905
- // Check if current element or any parent has um-no-capture class
906
- var curEl = el;
907
- while (curEl && !isTag(curEl, 'body')) {
908
- if (curEl.classList && curEl.classList.contains('um-no-capture')) {
909
- return false;
910
- }
911
- // Handle shadow DOM
912
- if (curEl.parentNode && isDocumentFragment(curEl.parentNode)) {
913
- curEl = curEl.parentNode.host;
914
- }
915
- else {
916
- curEl = curEl.parentNode;
917
- }
918
- }
919
- var parentIsUsefulElement = false;
920
- curEl = el;
921
- while (curEl && !isTag(curEl, 'body')) {
922
- // Handle shadow DOM
923
- if (curEl.parentNode && isDocumentFragment(curEl.parentNode)) {
924
- curEl = curEl.parentNode.host;
925
- if (curEl && usefulElements.indexOf(curEl.tagName.toLowerCase()) > -1) {
926
- parentIsUsefulElement = true;
927
- }
928
- continue;
929
- }
930
- var parentNode = curEl.parentNode;
931
- if (!parentNode)
932
- break;
933
- if (usefulElements.indexOf(parentNode.tagName.toLowerCase()) > -1) {
934
- parentIsUsefulElement = true;
935
- }
936
- else {
937
- var compStyles_1 = window.getComputedStyle(parentNode);
938
- if (compStyles_1 && compStyles_1.getPropertyValue('cursor') === 'pointer') {
939
- parentIsUsefulElement = true;
940
- }
941
- }
942
- curEl = parentNode;
943
- }
944
- var compStyles = window.getComputedStyle(el);
945
- if (compStyles && compStyles.getPropertyValue('cursor') === 'pointer' && event.type === 'click') {
946
- return true;
947
- }
948
- var tag = el.tagName.toLowerCase();
949
- switch (tag) {
950
- case 'html':
951
- return false;
952
- case 'form':
953
- return event.type === 'submit';
954
- case 'input':
955
- return event.type === 'change' || event.type === 'click';
956
- case 'select':
957
- case 'textarea':
958
- return event.type === 'change' || event.type === 'click';
959
- default:
960
- if (parentIsUsefulElement)
961
- return event.type === 'click';
962
- return (event.type === 'click' &&
963
- (usefulElements.indexOf(tag) > -1 || el.getAttribute('contenteditable') === 'true'));
964
- }
331
+ function ae(i) {
332
+ 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(i).toLowerCase());
965
333
  }
966
- /*
967
- * Check whether a DOM element should be "captured" or if it may contain sentitive data
968
- * using a variety of heuristics.
969
- * @param {Element} el - element to check
970
- * @returns {boolean} whether the element should be captured
971
- */
972
- function shouldCaptureElement(el) {
973
- for (var curEl = el; curEl.parentNode && !isTag(curEl, 'body'); curEl = curEl.parentNode) {
974
- var classes = getClassName(curEl).split(' ');
975
- if (_includes(classes, 'ph-sensitive') || _includes(classes, 'ph-no-capture')) {
976
- return false;
977
- }
978
- }
979
- if (_includes(getClassName(el).split(' '), 'ph-include')) {
980
- return true;
981
- }
982
- // don't include hidden or password fields
983
- var type = el.type || '';
984
- if (typeof type === 'string') {
985
- // it's possible for el.type to be a DOM element if el is a form with a child input[name="type"]
986
- switch (type.toLowerCase()) {
987
- case 'hidden':
988
- return false;
989
- case 'password':
990
- return false;
991
- }
992
- }
993
- // filter out data from fields that look like sensitive fields
994
- var name = el.name || el.id || '';
995
- // See https://github.com/posthog/posthog-js/issues/165
996
- // Under specific circumstances a bug caused .replace to be called on a DOM element
997
- // instead of a string, removing the element from the page. Ensure this issue is mitigated.
998
- if (typeof name === 'string') {
999
- // it's possible for el.name or el.id to be a DOM element if el is a form with a child input[name="name"]
1000
- var sensitiveNameRegex = /^cc|cardnum|ccnum|creditcard|csc|cvc|cvv|exp|pass|pwd|routing|seccode|securitycode|securitynum|socialsec|socsec|ssn/i;
1001
- if (sensitiveNameRegex.test(name.replace(/[^a-zA-Z0-9]/g, ''))) {
1002
- return false;
1003
- }
1004
- }
1005
- return true;
334
+ function ce(i, e) {
335
+ let t;
336
+ return function(...s) {
337
+ const n = () => {
338
+ clearTimeout(t), i(...s);
339
+ };
340
+ clearTimeout(t), t = setTimeout(n, e);
341
+ };
1006
342
  }
1007
- /*
1008
- * Check whether a DOM element is 'sensitive' and we should only capture limited data
1009
- * @param {Element} el - element to check
1010
- * @returns {boolean} whether the element should be captured
1011
- */
1012
- function isSensitiveElement(el) {
1013
- // don't send data from inputs or similar elements since there will always be
1014
- // a risk of clientside javascript placing sensitive data in attributes
1015
- var allowedInputTypes = ['button', 'checkbox', 'submit', 'reset'];
1016
- if ((isTag(el, 'input') && !allowedInputTypes.includes(el.type)) ||
1017
- isTag(el, 'select') ||
1018
- isTag(el, 'textarea') ||
1019
- el.getAttribute('contenteditable') === 'true') {
1020
- return true;
1021
- }
1022
- return false;
343
+ function le(i) {
344
+ const e = {}, t = i.replace(/^\?/, "").split("&");
345
+ for (let s = 0; s < t.length; s++) {
346
+ const n = t[s].split("=");
347
+ n[0] !== "" && (e[decodeURIComponent(n[0])] = decodeURIComponent(n[1] || ""));
348
+ }
349
+ return e;
1023
350
  }
1024
- /*
1025
- * Check whether a string value should be "captured" or if it may contain sentitive data
1026
- * using a variety of heuristics.
1027
- * @param {string} value - string value to check
1028
- * @returns {boolean} whether the element should be captured
1029
- */
1030
- function shouldCaptureValue(value) {
1031
- if (value === null || _isUndefined(value)) {
1032
- return false;
1033
- }
1034
- if (typeof value === 'string') {
1035
- value = _trim(value);
1036
- // check to see if input value looks like a credit card number
1037
- // see: https://www.safaribooksonline.com/library/view/regular-expressions-cookbook/9781449327453/ch04s20.html
1038
- var ccRegex = /^(?:(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}))$/;
1039
- if (ccRegex.test((value || '').replace(/[- ]/g, ''))) {
1040
- return false;
1041
- }
1042
- // check to see if input value looks like a social security number
1043
- var ssnRegex = /(^\d{3}-?\d{2}-?\d{4}$)/;
1044
- if (ssnRegex.test(value)) {
1045
- return false;
1046
- }
1047
- }
1048
- return true;
351
+ function I(i) {
352
+ return typeof i == "string" || i instanceof String;
1049
353
  }
1050
- /*
1051
- * Check whether an attribute name is an Angular style attr (either _ngcontent or _nghost)
1052
- * These update on each build and lead to noise in the element chain
1053
- * More details on the attributes here: https://angular.io/guide/view-encapsulation
1054
- * @param {string} attributeName - string value to check
1055
- * @returns {boolean} whether the element is an angular tag
1056
- */
1057
- function isAngularStyleAttr(attributeName) {
1058
- if (typeof attributeName === 'string') {
1059
- return attributeName.substring(0, 10) === '_ngcontent' || attributeName.substring(0, 7) === '_nghost';
1060
- }
1061
- return false;
354
+ function k(i) {
355
+ return i !== null && typeof i == "object" && i.constructor === Object;
1062
356
  }
1063
-
1064
- // Naive rage click implementation: If mouse has not moved than RAGE_CLICK_THRESHOLD_PX
1065
- // over RAGE_CLICK_CLICK_COUNT clicks with max RAGE_CLICK_TIMEOUT_MS between clicks, it's
1066
- // counted as a rage click
1067
- var RAGE_CLICK_THRESHOLD_PX = 30;
1068
- var RAGE_CLICK_TIMEOUT_MS = 1000;
1069
- var RAGE_CLICK_CLICK_COUNT = 3;
1070
- var RageClick = /** @class */ (function () {
1071
- function RageClick(instance, enabled) {
1072
- if (enabled === void 0) { enabled = false; }
1073
- this.clicks = [];
1074
- this.instance = instance;
1075
- this.enabled = enabled;
1076
- }
1077
- RageClick.prototype.click = function (x, y, timestamp) {
1078
- if (!this.enabled) {
1079
- return;
1080
- }
1081
- var lastClick = this.clicks[this.clicks.length - 1];
1082
- if (lastClick &&
1083
- Math.abs(x - lastClick.x) + Math.abs(y - lastClick.y) < RAGE_CLICK_THRESHOLD_PX &&
1084
- timestamp - lastClick.timestamp < RAGE_CLICK_TIMEOUT_MS) {
1085
- this.clicks.push({ x: x, y: y, timestamp: timestamp });
1086
- if (this.clicks.length === RAGE_CLICK_CLICK_COUNT) {
1087
- this.instance.capture('$rageclick');
1088
- }
1089
- }
1090
- else {
1091
- this.clicks = [{ x: x, y: y, timestamp: timestamp }];
1092
- }
1093
- };
1094
- return RageClick;
1095
- }());
1096
-
1097
- /**
1098
- * Scroll extension to add scroll get scroll depth in percentage
1099
- */
1100
- var ScrollDepth = /** @class */ (function () {
1101
- function ScrollDepth(instance) {
1102
- this.instance = instance;
1103
- this.lastScrollDepth = 0;
1104
- this.canSend = true;
1105
- this.documentElement = document.documentElement;
357
+ function ue(i) {
358
+ if (i === null)
359
+ return v.ERROR;
360
+ const e = i.toUpperCase(), t = v[e];
361
+ return t || t === 0 ? t : v.ERROR;
362
+ }
363
+ class he {
364
+ constructor(e) {
365
+ this.maxScrollDepth = 0, this.milestones = [25, 50, 75, 90], this.lastScrollDepth = 0, this.client = e, this.documentElement = document.documentElement, this.debouncedHandleScroll = ce(this.handleScroll.bind(this), 250), this.initializeEventListener();
366
+ }
367
+ initializeEventListener() {
368
+ window.addEventListener("scroll", this.debouncedHandleScroll);
369
+ }
370
+ track() {
371
+ const e = this.getScrollDepth();
372
+ e > this.lastScrollDepth && (this.lastScrollDepth = e, this.checkMilestones(e));
373
+ }
374
+ send(e = "$scroll") {
375
+ if (!this.lastScrollDepth)
376
+ return;
377
+ const t = {
378
+ percent: this.lastScrollDepth,
379
+ window_height: this.getWindowHeight(),
380
+ document_height: this.getDocumentHeight(),
381
+ scroll_distance: this.getScrollDistance()
382
+ };
383
+ this.client.track(e, t);
384
+ }
385
+ handleScroll() {
386
+ this.track();
387
+ }
388
+ getScrollDepth() {
389
+ const e = this.getWindowHeight(), t = this.getDocumentHeight(), s = this.getScrollDistance(), n = t - e;
390
+ return Math.min(100, Math.floor(s / n * 100));
391
+ }
392
+ getWindowHeight() {
393
+ return window.innerHeight || this.documentElement.clientHeight || document.body.clientHeight || 0;
394
+ }
395
+ getDocumentHeight() {
396
+ return Math.max(
397
+ document.body.scrollHeight || 0,
398
+ this.documentElement.scrollHeight || 0,
399
+ document.body.offsetHeight || 0,
400
+ this.documentElement.offsetHeight || 0,
401
+ document.body.clientHeight || 0,
402
+ this.documentElement.clientHeight || 0
403
+ );
404
+ }
405
+ getScrollDistance() {
406
+ return window.pageYOffset || this.documentElement.scrollTop || document.body.scrollTop || 0;
407
+ }
408
+ checkMilestones(e) {
409
+ this.milestones.filter((s) => e >= s).forEach((s) => {
410
+ this.send(), this.milestones = this.milestones.filter((n) => n !== s);
411
+ });
412
+ }
413
+ }
414
+ const C = class C {
415
+ constructor(e, t, s = d()) {
416
+ this.logger = s, this.scrollDepth = null, this.customProperties = [], this.client = e, this.options = t, this.scrollDepth = new he(e), j(this), z(this);
417
+ }
418
+ init() {
419
+ if (!(document && document.body)) {
420
+ this.logger.debug("Document not ready yet, trying again in 500 milliseconds..."), setTimeout(() => this.init(), 500);
421
+ return;
1106
422
  }
1107
- /**
1108
- * Track scroll depth
1109
- * @description this function will be called on every scroll event to track scroll depth
1110
- */
1111
- ScrollDepth.prototype.track = function () {
1112
- var scrollDepth = this.getScrollDepth();
1113
- // If scroll depth is greater than last scroll depth, then update last scroll depth
1114
- // We are doing this to only get the maximum scroll depth
1115
- if (scrollDepth > this.lastScrollDepth) {
1116
- this.lastScrollDepth = scrollDepth;
1117
- this.canSend = true;
1118
- }
1119
- };
1120
- /**
1121
- * Send scroll depth event
1122
- * @description this function will be when we want to send scroll depth event e.g. on page visibility change
1123
- */
1124
- ScrollDepth.prototype.send = function (eventType) {
1125
- if (eventType === void 0) { eventType = "$scroll"; }
1126
- if (!this.canSend) {
1127
- return;
1128
- }
1129
- // Creating payload
1130
- var props = {
1131
- percent: this.lastScrollDepth,
1132
- window_height: this.getWindowHeight(),
1133
- document_height: this.getDocumentHeight(),
1134
- scroll_distance: this.getScrollDistance()
1135
- };
1136
- // Sending event
1137
- this.instance.capture(eventType, props);
1138
- // Setting canSend to false, for avoiding sending multiple events
1139
- this.canSend = false;
1140
- };
1141
- /**
1142
- * Core method to get scroll depth
1143
- */
1144
- ScrollDepth.prototype.getScrollDepth = function () {
1145
- try {
1146
- // Get the height of the window and the document body
1147
- var winHeight = this.getWindowHeight();
1148
- var docHeight = this.getDocumentHeight();
1149
- // Get the current scroll position and the length of the track
1150
- var scrollTop = this.getScrollDistance();
1151
- var trackLength = docHeight - winHeight;
1152
- // Calculate the scroll depth as a percentage
1153
- return Math.min(100, Math.floor(scrollTop / trackLength * 100));
1154
- }
1155
- catch (e) {
1156
- return 0;
1157
- }
1158
- };
1159
- /**
1160
- * Core method to get window height
1161
- */
1162
- ScrollDepth.prototype.getWindowHeight = function () {
1163
- try {
1164
- return window.innerHeight || this.documentElement.clientHeight ||
1165
- document.body.clientHeight || 0;
1166
- }
1167
- catch (e) {
1168
- return 0;
1169
- }
1170
- };
1171
- /**
1172
- * Core method to get document height
1173
- */
1174
- ScrollDepth.prototype.getDocumentHeight = function () {
1175
- try {
1176
- return Math.max(document.body.scrollHeight || 0, this.documentElement.scrollHeight || 0, document.body.offsetHeight || 0, this.documentElement.offsetHeight || 0, document.body.clientHeight || 0, this.documentElement.clientHeight || 0);
1177
- }
1178
- catch (e) {
1179
- return 0;
1180
- }
1181
- };
1182
- /**
1183
- * Core method to get scroll distance
1184
- */
1185
- ScrollDepth.prototype.getScrollDistance = function () {
1186
- try {
1187
- return window.scrollY || window.pageYOffset || document.body.scrollTop ||
1188
- this.documentElement.scrollTop || 0;
1189
- }
1190
- catch (e) {
1191
- return 0;
1192
- }
423
+ this.addDomEventHandlers();
424
+ }
425
+ addDomEventHandlers() {
426
+ const e = (t) => {
427
+ t = t || window.event, this.captureEvent(t);
1193
428
  };
1194
- return ScrollDepth;
1195
- }());
1196
-
1197
- var autocapture = {
1198
- _initializedTokens: [],
1199
- _previousElementSibling: function (el) {
1200
- if (el.previousElementSibling) {
1201
- return el.previousElementSibling;
1202
- }
1203
- else {
1204
- var _el = el;
1205
- do {
1206
- _el = _el.previousSibling; // resolves to ChildNode->Node, which is Element's parent class
1207
- } while (_el && !isElementNode(_el));
1208
- return _el;
1209
- }
1210
- },
1211
- _getPropertiesFromElement: function (elem, maskInputs, maskText) {
1212
- var tag_name = elem.tagName.toLowerCase();
1213
- var props = {
1214
- tag_name: tag_name,
1215
- };
1216
- if (usefulElements.indexOf(tag_name) > -1 && !maskText) {
1217
- props['$el_text'] = getSafeText(elem);
1218
- }
1219
- var classes = getClassName(elem);
1220
- if (classes.length > 0)
1221
- props['classes'] = classes.split(' ').filter(function (c) {
1222
- return c !== '';
1223
- });
1224
- _each(elem.attributes, function (attr) {
1225
- // Only capture attributes we know are safe
1226
- if (isSensitiveElement(elem) && ['name', 'id', 'class'].indexOf(attr.name) === -1)
1227
- return;
1228
- if (!maskInputs && shouldCaptureValue(attr.value) && !isAngularStyleAttr(attr.name)) {
1229
- props['attr__' + attr.name] = attr.value;
1230
- }
1231
- });
1232
- var nthChild = 1;
1233
- var nthOfType = 1;
1234
- var currentElem = elem;
1235
- while ((currentElem = this._previousElementSibling(currentElem))) {
1236
- // eslint-disable-line no-cond-assign
1237
- nthChild++;
1238
- if (currentElem.tagName === elem.tagName) {
1239
- nthOfType++;
1240
- }
1241
- }
1242
- props['nth_child'] = nthChild;
1243
- props['nth_of_type'] = nthOfType;
1244
- return props;
1245
- },
1246
- _getDefaultProperties: function (eventType) {
1247
- return {
1248
- $event_type: eventType,
1249
- $ce_version: 1,
1250
- };
1251
- },
1252
- _extractCustomPropertyValue: function (customProperty) {
1253
- var propValues = [];
1254
- _each(document.querySelectorAll(customProperty['css_selector']), function (matchedElem) {
1255
- var value;
1256
- if (['input', 'select'].indexOf(matchedElem.tagName.toLowerCase()) > -1) {
1257
- value = matchedElem['value'];
1258
- }
1259
- else if (matchedElem['textContent']) {
1260
- value = matchedElem['textContent'];
1261
- }
1262
- if (shouldCaptureValue(value)) {
1263
- propValues.push(value);
1264
- }
1265
- });
1266
- return propValues.join(', ');
1267
- },
1268
- // TODO: delete custom_properties after changeless typescript refactor
1269
- _getCustomProperties: function (targetElementList) {
1270
- var _this = this;
1271
- var props = {}; // will be deleted
1272
- _each(this._customProperties, function (customProperty) {
1273
- _each(customProperty['event_selectors'], function (eventSelector) {
1274
- var eventElements = document.querySelectorAll(eventSelector);
1275
- _each(eventElements, function (eventElement) {
1276
- if (_includes(targetElementList, eventElement) && shouldCaptureElement(eventElement)) {
1277
- props[customProperty['name']] = _this._extractCustomPropertyValue(customProperty);
1278
- }
1279
- });
1280
- });
1281
- });
1282
- return props;
1283
- },
1284
- _getEventTarget: function (e) {
1285
- var _a;
1286
- // https://developer.mozilla.org/en-US/docs/Web/API/Event/target#Compatibility_notes
1287
- if (typeof e.target === 'undefined') {
1288
- return e.srcElement || null;
1289
- }
1290
- else {
1291
- if ((_a = e.target) === null || _a === void 0 ? void 0 : _a.shadowRoot) {
1292
- return e.composedPath()[0] || null;
1293
- }
1294
- return e.target || null;
1295
- }
1296
- },
1297
- _captureEvent: function (e, instance, opts) {
1298
- var _this = this;
1299
- var _a;
1300
- /*** Don't mess with this code without running IE8 tests on it ***/
1301
- var target = this._getEventTarget(e);
1302
- if (isTextNode(target)) {
1303
- // defeat Safari bug (see: http://www.quirksmode.org/js/events_properties.html)
1304
- target = (target.parentNode || null);
1305
- }
1306
- // If type is 'scroll', track the scroll depth
1307
- if (e.type === 'scroll') {
1308
- this.scrollDepth.track();
1309
- return true;
1310
- }
1311
- // If type is visibilitychange and the page is about to be hidden, send a scroll depth event
1312
- if ((e.type === 'visibilitychange' && document.visibilityState === 'hidden') || e.type === 'popstate') {
1313
- this.scrollDepth.send();
1314
- return true;
1315
- }
1316
- if (e.type === 'click' && e instanceof MouseEvent) {
1317
- (_a = this.rageclicks) === null || _a === void 0 ? void 0 : _a.click(e.clientX, e.clientY, new Date().getTime());
1318
- }
1319
- if (target && shouldCaptureDomEvent(target, e)) {
1320
- var targetElementList = [target];
1321
- var curEl = target;
1322
- while (curEl.parentNode && !isTag(curEl, 'body')) {
1323
- if (isDocumentFragment(curEl.parentNode)) {
1324
- targetElementList.push(curEl.parentNode.host);
1325
- curEl = curEl.parentNode.host;
1326
- continue;
1327
- }
1328
- targetElementList.push(curEl.parentNode);
1329
- curEl = curEl.parentNode;
1330
- }
1331
- var elementsJson_1 = [];
1332
- var href_1, explicitNoCapture_1 = false;
1333
- _each(targetElementList, function (el) {
1334
- var shouldCaptureEl = shouldCaptureElement(el);
1335
- // if the element or a parent element is an anchor tag
1336
- // include the href as a property
1337
- if (el.tagName.toLowerCase() === 'a') {
1338
- href_1 = el.getAttribute('href');
1339
- href_1 = shouldCaptureEl && shouldCaptureValue(href_1) && href_1;
1340
- }
1341
- // allow users to programmatically prevent capturing of elements by adding class 'ph-no-capture'
1342
- var classes = getClassName(el).split(' ');
1343
- if (_includes(classes, 'ph-no-capture')) {
1344
- explicitNoCapture_1 = true;
1345
- }
1346
- elementsJson_1.push(_this._getPropertiesFromElement(el, opts === null || opts === void 0 ? void 0 : opts.mask_all_element_attributes, opts === null || opts === void 0 ? void 0 : opts.mask_all_text));
1347
- });
1348
- if (!(opts === null || opts === void 0 ? void 0 : opts.mask_all_text)) {
1349
- elementsJson_1[0]['$el_text'] = getSafeText(target);
1350
- }
1351
- if (href_1) {
1352
- elementsJson_1[0]['attr__href'] = href_1;
1353
- }
1354
- if (explicitNoCapture_1) {
1355
- return false;
1356
- }
1357
- var props = _extend(this._getDefaultProperties(e.type), {
1358
- $elements: elementsJson_1,
1359
- }, this._getCustomProperties(targetElementList));
1360
- instance.capture('$autocapture', props);
1361
- return true;
1362
- }
1363
- },
1364
- // only reason is to stub for unit tests
1365
- // since you can't override window.location props
1366
- _navigate: function (href) {
1367
- window.location.href = href;
1368
- },
1369
- _addDomEventHandlers: function (instance, opts) {
1370
- var _this = this;
1371
- var handler = function (e) {
1372
- e = e || window.event;
1373
- _this._captureEvent(e, instance, opts);
1374
- };
1375
- _register_event(document, 'submit', handler, false, true);
1376
- _register_event(document, 'change', handler, false, true);
1377
- _register_event(document, 'click', handler, false, true);
1378
- _register_event(document, 'visibilitychange', handler, false, true);
1379
- _register_event(document, 'scroll', handler, false, true);
1380
- _register_event(window, 'popstate', handler, false, true);
1381
- },
1382
- _customProperties: [],
1383
- rageclicks: null,
1384
- scrollDepth: null,
1385
- opts: {},
1386
- init: function (instance, opts) {
1387
- var _this = this;
1388
- this.rageclicks = new RageClick(instance);
1389
- this.scrollDepth = new ScrollDepth(instance);
1390
- this.opts = opts;
1391
- if (!(document && document.body)) {
1392
- console.debug('document not ready yet, trying again in 500 milliseconds...');
1393
- setTimeout(function () {
1394
- _this.readyAutocapture(instance, opts);
1395
- }, 500);
1396
- return;
1397
- }
1398
- this.readyAutocapture(instance, opts);
1399
- },
1400
- readyAutocapture: function (instance, opts) {
1401
- this._addDomEventHandlers(instance, opts);
1402
- },
1403
- // this is a mechanism to ramp up CE with no server-side interaction.
1404
- // when CE is active, every page load results in a decide request. we
1405
- // need to gently ramp this up so we don't overload decide. this decides
1406
- // deterministically if CE is enabled for this project by modding the char
1407
- // value of the project token.
1408
- enabledForProject: function (token, numBuckets, numEnabledBuckets) {
1409
- if (!token) {
1410
- return true;
1411
- }
1412
- numBuckets = !_isUndefined(numBuckets) ? numBuckets : 10;
1413
- numEnabledBuckets = !_isUndefined(numEnabledBuckets) ? numEnabledBuckets : 10;
1414
- var charCodeSum = 0;
1415
- for (var i = 0; i < token.length; i++) {
1416
- charCodeSum += token.charCodeAt(i);
1417
- }
1418
- return charCodeSum % numBuckets < numEnabledBuckets;
1419
- },
1420
- isBrowserSupported: function () {
1421
- return _isFunction(document.querySelectorAll);
1422
- },
1423
- };
1424
- _bind_instance_methods(autocapture);
1425
- _safewrap_instance_methods(autocapture);
1426
-
1427
- var FormTracking = /** @class */ (function () {
1428
- function FormTracking(instance, trackingType) {
1429
- if (trackingType === void 0) { trackingType = 'all'; }
1430
- this.instance = instance;
1431
- this.trackingType = trackingType;
1432
- // Wait for the DOM to be ready
1433
- if (document.readyState === 'loading') {
1434
- document.addEventListener('DOMContentLoaded', this.track.bind(this));
1435
- }
1436
- else {
1437
- this.track();
1438
- }
429
+ m(document, "submit", e, !1, !0), m(document, "change", e, !1, !0), m(document, "click", e, !1, !0), m(document, "visibilitychange", e, !1, !0), m(document, "scroll", e, !1, !0), m(window, "popstate", e, !1, !0);
430
+ }
431
+ isPageRefresh() {
432
+ if ("PerformanceNavigationTiming" in window) {
433
+ const e = performance.getEntriesByType("navigation");
434
+ if (e.length > 0)
435
+ return e[0].type === "reload";
1439
436
  }
1440
- /**
1441
- * Track form submit
1442
- * @description this function will be called on every form submit event to track form submit
1443
- */
1444
- FormTracking.prototype.track = function () {
1445
- var _this = this;
1446
- this.formElements = document.querySelectorAll('form');
1447
- if (this.trackingType === 'tagged') {
1448
- this.formElements = document.querySelectorAll('form[data-um-form]');
1449
- }
1450
- this.formElements.forEach(function (form) {
1451
- form.addEventListener('submit', function (event) {
1452
- var form = event.target;
1453
- var props = _this._getFormDetails(form);
1454
- _this.instance.capture('$form', _cleanObject(props));
1455
- });
1456
- });
1457
- };
1458
- FormTracking.getInstance = function (instance, trackingType) {
1459
- if (trackingType === void 0) { trackingType = 'all'; }
1460
- if (!FormTracking.instance) {
1461
- FormTracking.instance = new FormTracking(instance, trackingType);
1462
- }
1463
- return FormTracking.instance;
1464
- };
1465
- FormTracking.prototype._getFormDetails = function (form) {
1466
- var _this = this;
1467
- var formDetails = {
1468
- form_id: form.id,
1469
- form_name: form.name || '',
1470
- form_action: form.action,
1471
- form_method: form.method,
1472
- };
1473
- var formFields = form.querySelectorAll('input, select, textarea');
1474
- // ignore form fields with class um-no-capture
1475
- var filteredFormFields = Array.from(formFields).filter(function (field) { return !field.classList.contains('um-no-capture'); });
1476
- filteredFormFields.forEach(function (field, index) {
1477
- var fieldProps = _this._getFieldProps(field, index);
1478
- Object.assign(formDetails, fieldProps);
437
+ return performance.navigation && performance.navigation.type === 1;
438
+ }
439
+ captureEvent(e) {
440
+ var s, n;
441
+ let t = this.getEventTarget(e);
442
+ if (B(t) && (t = t.parentNode || null), e.type === "scroll")
443
+ return (s = this.scrollDepth) == null || s.track(), !0;
444
+ if (e.type === "visibilitychange" && document.visibilityState === "hidden" || e.type === "popstate")
445
+ return this.isPageRefresh() || (n = this.scrollDepth) == null || n.send(), !0;
446
+ if (t && re(t, e)) {
447
+ const r = [t];
448
+ let o = t;
449
+ for (; o.parentNode && !g(o, "body"); ) {
450
+ if (N(o.parentNode)) {
451
+ r.push(o.parentNode.host), o = o.parentNode.host;
452
+ continue;
453
+ }
454
+ r.push(o.parentNode), o = o.parentNode;
455
+ }
456
+ const c = [];
457
+ let l, a = !1;
458
+ if (f(r, (w) => {
459
+ const J = O(w);
460
+ w.tagName.toLowerCase() === "a" && (l = w.getAttribute("href"), l = J && P(l) && l);
461
+ const Q = $(w).split(" ");
462
+ _(Q, "ph-no-capture") && (a = !0), c.push(
463
+ this.getPropertiesFromElement(
464
+ w,
465
+ this.options.maskAllElementAttributes ?? !1,
466
+ this.options.maskAllText ?? !1
467
+ )
468
+ );
469
+ }), this.options.maskAllText || (c[0].$el_text = L(t)), l && (c[0].attr__href = l), a)
470
+ return !1;
471
+ const h = ee(
472
+ this.getDefaultProperties(e.type),
473
+ {
474
+ $elements: c
475
+ },
476
+ this.getCustomProperties(r)
477
+ );
478
+ return this.client.track("$autocapture", h), !0;
479
+ }
480
+ }
481
+ getCustomProperties(e) {
482
+ const t = {};
483
+ return f(this.customProperties, (s) => {
484
+ f(s.event_selectors, (n) => {
485
+ const r = document.querySelectorAll(n);
486
+ f(r, (o) => {
487
+ _(e, o) && O(o) && (t[s.name] = this.extractCustomPropertyValue(s));
1479
488
  });
1480
- return formDetails;
1481
- };
1482
- FormTracking.prototype._getFieldProps = function (field, index) {
1483
- var _a;
1484
- var fieldDataAttributes = Object.keys(field.dataset).length ? JSON.stringify(field.dataset) : undefined;
1485
- var safeValue = this.getSafeText(field);
1486
- return _a = {},
1487
- _a["field_" + (index + 1) + "_tag"] = field.tagName.toLowerCase(),
1488
- _a["field_" + (index + 1) + "_type"] = field instanceof HTMLInputElement ? field.type : undefined,
1489
- _a["field_" + (index + 1) + "_data_attributes"] = fieldDataAttributes,
1490
- _a["field_" + (index + 1) + "_id"] = field.id,
1491
- _a["field_" + (index + 1) + "_value"] = safeValue,
1492
- _a["field_" + (index + 1) + "_class"] = field.className,
1493
- _a["field_" + (index + 1) + "_name"] = field.name,
1494
- _a;
1495
- };
1496
- FormTracking.prototype.getSafeText = function (element) {
1497
- var safeText = '';
1498
- if ('value' in element && element.type !== "password") {
1499
- safeText = element.value;
1500
- }
1501
- else if (element.hasChildNodes()) {
1502
- var textNodes = Array.from(element.childNodes).filter(function (node) { return node.nodeType === Node.TEXT_NODE; });
1503
- safeText = textNodes.map(function (node) { return node.textContent; }).join('');
1504
- }
1505
- else {
1506
- safeText = element.textContent || '';
1507
- }
1508
- return this._scrubPotentiallySensitiveValues(safeText);
1509
- };
1510
- FormTracking.prototype._scrubPotentiallySensitiveValues = function (text) {
1511
- if (!this._shouldCaptureValue(text)) {
1512
- return '<redacted>';
1513
- }
1514
- return text;
1515
- };
1516
- FormTracking.prototype._shouldCaptureValue = function (value) {
1517
- if (this._isNullish(value)) {
1518
- return false;
1519
- }
1520
- if (this._isString(value)) {
1521
- value = this._trim(value);
1522
- // check to see if input value looks like a credit card number
1523
- // see: https://www.safaribooksonline.com/library/view/regular-expressions-cookbook/9781449327453/ch04s20.html
1524
- var ccRegex = /^(?:(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}))$/;
1525
- if (ccRegex.test((value || '').replace(/[- ]/g, ''))) {
1526
- return false;
1527
- }
1528
- // check to see if input value looks like a social security number
1529
- var ssnRegex = /(^\d{3}-?\d{2}-?\d{4}$)/;
1530
- if (ssnRegex.test(value)) {
1531
- return false;
1532
- }
1533
- }
1534
- return true;
1535
- };
1536
- FormTracking.prototype._isNullish = function (value) {
1537
- return value === null || value === undefined;
1538
- };
1539
- FormTracking.prototype._isString = function (value) {
1540
- return typeof value === 'string' || value instanceof String;
1541
- };
1542
- FormTracking.prototype._trim = function (value) {
1543
- return value.trim().replace(/^\s+|\s+$/g, '');
489
+ });
490
+ }), t;
491
+ }
492
+ extractCustomPropertyValue(e) {
493
+ const t = [];
494
+ return f(document.querySelectorAll(e.css_selector), function(s) {
495
+ let n;
496
+ ["input", "select"].indexOf(s.tagName.toLowerCase()) > -1 ? n = s.value : s.textContent && (n = s.textContent), P(n) && t.push(n);
497
+ }), t.join(", ");
498
+ }
499
+ getEventTarget(e) {
500
+ var t;
501
+ return typeof e.target > "u" ? e.srcElement || null : (t = e.target) != null && t.shadowRoot ? e.composedPath()[0] || null : e.target || null;
502
+ }
503
+ getPropertiesFromElement(e, t, s) {
504
+ const n = e.tagName.toLowerCase(), r = {
505
+ tag_name: n
506
+ };
507
+ b.indexOf(n) > -1 && !s && (r.$el_text = L(e));
508
+ const o = $(e);
509
+ o.length > 0 && (r.classes = o.split(" ").filter(function(h) {
510
+ return h !== "";
511
+ })), f(e.attributes, function(h) {
512
+ M(e) && ["name", "id", "class"].indexOf(h.name) === -1 || !t && P(h.value) && !oe(h.name) && (r["attr__" + h.name] = h.value);
513
+ });
514
+ let c = 1, l = 1, a = e;
515
+ for (; a = this.previousElementSibling(a); )
516
+ c++, a.tagName === e.tagName && l++;
517
+ return r.nth_child = c, r.nth_of_type = l, r;
518
+ }
519
+ previousElementSibling(e) {
520
+ if (e.previousElementSibling)
521
+ return e.previousElementSibling;
522
+ {
523
+ let t = e;
524
+ do
525
+ t = t.previousSibling;
526
+ while (t && !q(t));
527
+ return t;
528
+ }
529
+ }
530
+ getDefaultProperties(e) {
531
+ return {
532
+ $event_type: e,
533
+ $ce_version: 1
1544
534
  };
1545
- return FormTracking;
1546
- }());
1547
-
1548
- var VERSION_INFO = {
1549
- env: 'production',
1550
- date: '2024-11-19T12:36:28.908Z',
1551
- version: '1.4.4'
1552
- };
1553
- var USERMAVEN_VERSION = VERSION_INFO.version + "/" + VERSION_INFO.env + "@" + VERSION_INFO.date;
1554
- var MAX_AGE_TEN_YEARS = 31622400 * 10;
1555
- var beaconTransport = function (url, json) {
1556
- getLogger().debug("Sending beacon", json);
1557
- var blob = new Blob([json], { type: "text/plain" });
1558
- navigator.sendBeacon(url, blob);
1559
- return Promise.resolve();
535
+ }
536
+ encodeHtml(e) {
537
+ return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
538
+ }
539
+ static enabledForProject(e, t = 10, s = 10) {
540
+ if (!e)
541
+ return !1;
542
+ let n = 0;
543
+ for (let r = 0; r < e.length; r++)
544
+ n += e.charCodeAt(r);
545
+ return n % t < s;
546
+ }
1560
547
  };
1561
- function tryFormat(string) {
1562
- if (typeof string === "string") {
1563
- try {
1564
- return JSON.stringify(JSON.parse(string), null, 2);
1565
- }
1566
- catch (e) {
1567
- return string;
1568
- }
1569
- }
548
+ C.FORCE_CAPTURE_ATTR = "data-um-force-capture", C.PREVENT_CAPTURE_ATTR = "data-um-no-capture";
549
+ let S = C;
550
+ class de {
551
+ constructor(e) {
552
+ this.client = e, this.lastPageUrl = window.location.href, this.trackInitialPageview(), this.initializePageviewTracking();
553
+ }
554
+ trackInitialPageview() {
555
+ this.trackPageview();
556
+ }
557
+ initializePageviewTracking() {
558
+ window.addEventListener("popstate", this.handlePageview.bind(this));
559
+ const e = history.pushState;
560
+ history.pushState = (...t) => {
561
+ e.apply(history, t), this.handlePageview();
562
+ }, window.addEventListener("hashchange", this.handlePageview.bind(this)), setInterval(this.checkForUrlChange.bind(this), 1e3);
563
+ }
564
+ handlePageview() {
565
+ this.trackPageview();
566
+ }
567
+ checkForUrlChange() {
568
+ window.location.href !== this.lastPageUrl && this.trackPageview();
569
+ }
570
+ trackPageview() {
571
+ const e = window.location.href;
572
+ e !== this.lastPageUrl && (this.lastPageUrl = e, this.client.track("pageview", {
573
+ url: e,
574
+ referrer: document.referrer,
575
+ title: document.title
576
+ }));
577
+ }
1570
578
  }
1571
- var echoTransport = function (url, json) {
1572
- console.debug("Jitsu client tried to send payload to " + url, tryFormat(json));
1573
- return Promise.resolve();
1574
- };
1575
- // This is a hack to expire all cookies with non-root path left behind by invalid tracking.
1576
- // TODO remove soon
1577
- function expireNonRootCookies(name, path) {
1578
- if (path === void 0) { path = undefined; }
1579
- path = path !== null && path !== void 0 ? path : window.location.pathname;
1580
- if (path == "" || path == "/") {
1581
- return;
1582
- }
1583
- deleteCookie(name, path);
1584
- expireNonRootCookies(name, path.slice(0, path.lastIndexOf("/")));
579
+ class ge {
580
+ constructor(e, t, s = d()) {
581
+ this.trackingHost = e, this.logger = s, this.config = t;
582
+ }
583
+ async send(e) {
584
+ const t = this.config.key, s = this.constructUrl(t), n = new Blob([JSON.stringify(e)], { type: "application/json" });
585
+ if (navigator.sendBeacon(s, n))
586
+ this.logger.debug(`Successfully queued ${e.length} event(s) via Beacon API`);
587
+ else
588
+ throw new Error("Failed to queue events via Beacon API");
589
+ }
590
+ constructUrl(e) {
591
+ const t = this.config.cookiePolicy !== "keep" ? `&cookie_policy=${this.config.cookiePolicy}` : "", s = this.config.ipPolicy !== "keep" ? `&ip_policy=${this.config.ipPolicy}` : "", n = u() ? "/api/v1/event" : "/api/v1/s2s/event";
592
+ return this.config.randomizeUrl ? `${this.trackingHost}/api.${p()}?p_${p()}=${e}${t}${s}` : `${this.trackingHost}${n}?token=${e}${t}${s}`;
593
+ }
594
+ // Note: Beacon API doesn't support custom headers, so we can't use them here.
595
+ // If custom headers are crucial, you might want to fall back to XHR or Fetch in those cases.
596
+ }
597
+ class D {
598
+ constructor(e, t, s = d()) {
599
+ this.trackingHost = e, this.logger = s, this.config = t;
600
+ }
601
+ async send(e) {
602
+ const t = this.config.key, s = this.constructUrl(t), n = JSON.stringify(e), r = {
603
+ "Content-Type": "application/json",
604
+ ...this.getCustomHeaders()
605
+ }, o = await fetch(s, {
606
+ method: "POST",
607
+ headers: r,
608
+ body: n
609
+ });
610
+ if (!o.ok)
611
+ throw new Error(`HTTP error! status: ${o.status}`);
612
+ this.logger.debug(`Successfully sent ${e.length} event(s)`), this.postHandle(o.status, await o.text());
613
+ }
614
+ constructUrl(e) {
615
+ const t = this.config.cookiePolicy !== "keep" ? `&cookie_policy=${this.config.cookiePolicy}` : "", s = this.config.ipPolicy !== "keep" ? `&ip_policy=${this.config.ipPolicy}` : "", n = u() ? "/api/v1/event" : "/api/v1/s2s/event";
616
+ return this.config.randomizeUrl ? `${this.trackingHost}/api.${p()}?p_${p()}=${e}${t}${s}` : `${this.trackingHost}${n}?token=${e}${t}${s}`;
617
+ }
618
+ getCustomHeaders() {
619
+ return typeof this.config.customHeaders == "function" ? this.config.customHeaders() : this.config.customHeaders ? this.config.customHeaders : {};
620
+ }
621
+ postHandle(e, t) {
622
+ this.logger.debug(`Response received. Status: ${e}, Body: ${t}`);
623
+ }
1585
624
  }
1586
- var CookiePersistence = /** @class */ (function () {
1587
- function CookiePersistence(cookieDomain, cookieName) {
1588
- this.cookieDomain = cookieDomain;
1589
- this.cookieName = cookieName;
625
+ class fe {
626
+ constructor(e, t, s = d()) {
627
+ this.trackingHost = e, this.logger = s, this.config = t;
628
+ }
629
+ send(e) {
630
+ return new Promise((t, s) => {
631
+ const n = new XMLHttpRequest(), r = this.config.key, o = this.constructUrl(r);
632
+ n.open("POST", o, !0), n.setRequestHeader("Content-Type", "application/json");
633
+ const c = this.getCustomHeaders();
634
+ Object.keys(c).forEach((l) => {
635
+ n.setRequestHeader(l, c[l]);
636
+ }), n.onload = () => {
637
+ n.status >= 200 && n.status < 300 ? (this.logger.debug(`Successfully sent ${e.length} event(s)`), t()) : s(new Error(`HTTP error! status: ${n.status}`));
638
+ }, n.onerror = () => {
639
+ s(new Error("Network error"));
640
+ }, n.send(JSON.stringify(e));
641
+ });
642
+ }
643
+ constructUrl(e) {
644
+ const t = this.config.cookiePolicy !== "keep" ? `&cookie_policy=${this.config.cookiePolicy}` : "", s = this.config.ipPolicy !== "keep" ? `&ip_policy=${this.config.ipPolicy}` : "", n = u() ? "/api/v1/event" : "/api/v1/s2s/event";
645
+ return this.config.randomizeUrl ? `${this.trackingHost}/api.${p()}?p_${p()}=${e}${t}${s}` : `${this.trackingHost}${n}?token=${e}${t}${s}`;
646
+ }
647
+ getCustomHeaders() {
648
+ return typeof this.config.customHeaders == "function" ? this.config.customHeaders() : this.config.customHeaders ? this.config.customHeaders : {};
649
+ }
650
+ postHandle(e, t) {
651
+ this.logger.debug(`Response received. Status: ${e}, Body: ${t}`);
652
+ }
653
+ }
654
+ class V {
655
+ constructor(e, t) {
656
+ this.storage = {}, this.prefix = `usermaven_${e}_`, this.load(), this.logger = t || d();
657
+ }
658
+ set(e, t) {
659
+ this.storage[e] = t, this.save();
660
+ }
661
+ get(e) {
662
+ return this.storage[e];
663
+ }
664
+ remove(e) {
665
+ delete this.storage[e], this.save();
666
+ }
667
+ clear() {
668
+ this.storage = {}, this.save();
669
+ }
670
+ save() {
671
+ if (!u()) {
672
+ this.logger.warn("localStorage is not available in this environment");
673
+ return;
1590
674
  }
1591
- CookiePersistence.prototype.save = function (props) {
1592
- setCookie(this.cookieName, JSON.stringify(props), {
1593
- domain: this.cookieDomain,
1594
- secure: document.location.protocol !== "http:",
1595
- maxAge: MAX_AGE_TEN_YEARS,
1596
- });
1597
- };
1598
- CookiePersistence.prototype.restore = function () {
1599
- expireNonRootCookies(this.cookieName);
1600
- var str = getCookie(this.cookieName);
1601
- if (str) {
1602
- try {
1603
- var parsed = JSON.parse(decodeURIComponent(str));
1604
- if (typeof parsed !== "object") {
1605
- getLogger().warn("Can't restore value of " + this.cookieName + "@" + this.cookieDomain + ", expected to be object, but found " + (typeof parsed !== "object") + ": " + parsed + ". Ignoring");
1606
- return undefined;
1607
- }
1608
- return parsed;
1609
- }
1610
- catch (e) {
1611
- getLogger().error("Failed to decode JSON from " + str, e);
1612
- return undefined;
1613
- }
1614
- }
1615
- return undefined;
1616
- };
1617
- CookiePersistence.prototype.delete = function () {
1618
- deleteCookie(this.cookieName);
1619
- };
1620
- return CookiePersistence;
1621
- }());
1622
- var NoPersistence = /** @class */ (function () {
1623
- function NoPersistence() {
675
+ try {
676
+ localStorage.setItem(this.prefix + "data", JSON.stringify(this.storage));
677
+ } catch (e) {
678
+ this.logger.error("Error saving to localStorage:", e);
1624
679
  }
1625
- NoPersistence.prototype.save = function (props) {
1626
- };
1627
- NoPersistence.prototype.restore = function () {
1628
- return undefined;
1629
- };
1630
- NoPersistence.prototype.delete = function () {
1631
- };
1632
- return NoPersistence;
1633
- }());
1634
- var defaultCompatMode = false;
1635
- function usermavenClient(opts) {
1636
- var client = new UsermavenClientImpl();
1637
- client.init(opts);
1638
- return client;
1639
- }
1640
- var browserEnv = {
1641
- getSourceIp: function () { return undefined; },
1642
- describeClient: function () { return ({
1643
- referer: document.referrer,
1644
- url: window.location.href,
1645
- page_title: document.title,
1646
- doc_path: document.location.pathname,
1647
- doc_host: document.location.hostname,
1648
- doc_search: window.location.search,
1649
- screen_resolution: screen.width + "x" + screen.height,
1650
- vp_size: Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0) +
1651
- "x" +
1652
- Math.max(document.documentElement.clientHeight || 0, window.innerHeight || 0),
1653
- user_agent: navigator.userAgent,
1654
- user_language: navigator.language,
1655
- doc_encoding: document.characterSet,
1656
- }); },
1657
- getAnonymousId: function (_a) {
1658
- var name = _a.name, domain = _a.domain, _b = _a.crossDomainLinking, crossDomainLinking = _b === void 0 ? true : _b, _c = _a.cookiePolicy, cookiePolicy = _c === void 0 ? 'keep' : _c;
1659
- // In strict mode (cookiePolicy === 'strict'), don't use cookies at all
1660
- if (cookiePolicy === 'strict') {
1661
- // Return an empty string to indicate that we don't want to use cookies
1662
- return "";
1663
- }
1664
- expireNonRootCookies(name);
1665
- // Check if cross domain linking is enabled
1666
- if (crossDomainLinking) {
1667
- // Try to extract the '_um' parameter from query string and hash fragment (https://example.com#_um=1~abcde5~)
1668
- var urlParams = new URLSearchParams(window.location.search);
1669
- var queryId = urlParams.get('_um');
1670
- var urlHash = window.location.hash.substring(1);
1671
- var hashedValues = urlHash.split("~");
1672
- var fragmentId = hashedValues.length > 1 ? hashedValues[1] : undefined;
1673
- // If the '_um' parameter is set in both the query string and hash fragment,
1674
- // prioritize the one in query string
1675
- var crossDomainAnonymousId = queryId || fragmentId;
1676
- // If coming from another domain, use the ID from URL parameter
1677
- if (crossDomainAnonymousId) {
1678
- getLogger().debug("Existing user id from other domain", crossDomainAnonymousId);
1679
- // Check if the ID needs to be set as cookie
1680
- var currentCookie = getCookie(name);
1681
- if (!currentCookie || currentCookie !== crossDomainAnonymousId) {
1682
- setCookie(name, crossDomainAnonymousId, {
1683
- domain: domain,
1684
- secure: document.location.protocol !== "http:",
1685
- maxAge: MAX_AGE_TEN_YEARS,
1686
- });
1687
- }
1688
- return crossDomainAnonymousId;
1689
- }
1690
- }
1691
- var idCookie = getCookie(name);
1692
- if (idCookie) {
1693
- getLogger().debug("Existing user id", idCookie);
1694
- return idCookie;
1695
- }
1696
- var newId = generateId();
1697
- getLogger().debug("New user id", newId);
1698
- setCookie(name, newId, {
1699
- domain: domain,
1700
- secure: document.location.protocol !== "http:",
1701
- maxAge: MAX_AGE_TEN_YEARS,
1702
- });
1703
- return newId;
1704
- },
1705
- };
1706
- function ensurePrefix(prefix, str) {
1707
- if (!str) {
1708
- return str;
680
+ }
681
+ load() {
682
+ if (!u()) {
683
+ this.logger.warn("localStorage is not available in this environment");
684
+ return;
685
+ }
686
+ try {
687
+ const e = localStorage.getItem(this.prefix + "data");
688
+ e && (this.storage = JSON.parse(e));
689
+ } catch (e) {
690
+ this.logger.error("Error loading from localStorage:", e);
1709
691
  }
1710
- return (str === null || str === void 0 ? void 0 : str.length) > 0 && str.indexOf(prefix) !== 0 ? prefix + str : str;
692
+ }
1711
693
  }
1712
- function cutPostfix(postfixes, str) {
1713
- for (var _i = 0, _a = typeof postfixes === "string"
1714
- ? [postfixes]
1715
- : postfixes; _i < _a.length; _i++) {
1716
- var postfix = _a[_i];
1717
- while (str && str.length > 0 && str.charAt(str.length - 1) === postfix) {
1718
- str = str.substring(0, str.length - 1);
1719
- }
694
+ class pe {
695
+ constructor() {
696
+ this.storage = {};
697
+ }
698
+ set(e, t) {
699
+ this.storage[e] = t;
700
+ }
701
+ get(e) {
702
+ return this.storage[e];
703
+ }
704
+ remove(e) {
705
+ delete this.storage[e];
706
+ }
707
+ save() {
708
+ }
709
+ clear() {
710
+ this.storage = {};
711
+ }
712
+ }
713
+ class F {
714
+ // Default to true for server-side
715
+ constructor(e, t = 3, s = 1e3, n = 10, r = 1e3, o = d(), c = "default") {
716
+ this.transport = e, this.maxRetries = t, this.retryInterval = s, this.batchSize = n, this.batchInterval = r, this.logger = o, this.queue = [], this.processing = !1, this.batchTimeoutId = null, this.isOnline = !0, this.persistence = new V(`offline_queue_${c}`), u() && (this.isOnline = navigator.onLine, this.loadQueueFromStorage(), this.initNetworkListeners(), this.scheduleBatch());
717
+ }
718
+ add(e) {
719
+ const t = { payload: e, retries: 0, timestamp: Date.now() };
720
+ this.queue.push(t), u() ? this.saveQueueToStorage() : this.processBatch();
721
+ }
722
+ initNetworkListeners() {
723
+ u() && (window.addEventListener("online", () => {
724
+ this.isOnline = !0, this.processBatch();
725
+ }), window.addEventListener("offline", () => {
726
+ this.isOnline = !1;
727
+ }));
728
+ }
729
+ scheduleBatch() {
730
+ u() && (this.batchTimeoutId !== null && clearTimeout(this.batchTimeoutId), this.batchTimeoutId = window.setTimeout(() => this.processBatch(), this.batchInterval));
731
+ }
732
+ async processBatch() {
733
+ if ((!u() || this.isOnline) && !this.processing && this.queue.length > 0) {
734
+ this.processing = !0;
735
+ const e = this.queue.splice(0, this.batchSize), t = e.map((s) => s.payload);
736
+ try {
737
+ await this.transport.send(t), this.logger.debug(`Successfully sent batch of ${e.length} payloads`), u() && this.saveQueueToStorage();
738
+ } catch (s) {
739
+ this.logger.error("Failed to send batch", s), await this.handleBatchFailure(e);
740
+ }
741
+ this.processing = !1;
742
+ }
743
+ u() && this.scheduleBatch();
744
+ }
745
+ async handleBatchFailure(e) {
746
+ for (const t of e)
747
+ t.retries < this.maxRetries ? (t.retries++, this.queue.unshift(t), this.logger.warn(`Retry attempt ${t.retries} for payload`)) : this.logger.error("Max retries reached, discarding payload", t.payload);
748
+ u() && (this.saveQueueToStorage(), await new Promise((t) => setTimeout(t, this.retryInterval)));
749
+ }
750
+ loadQueueFromStorage() {
751
+ if (u()) {
752
+ const e = this.persistence.get("queue");
753
+ e && (this.queue = JSON.parse(e));
1720
754
  }
1721
- return str;
755
+ }
756
+ saveQueueToStorage() {
757
+ u() && this.persistence.set("queue", JSON.stringify(this.queue));
758
+ }
1722
759
  }
1723
- function httpApi(req, res, opts) {
1724
- if (opts === void 0) { opts = {}; }
1725
- var header = function (req, name) {
1726
- var vals = req.headers[name.toLowerCase()];
1727
- if (!vals) {
1728
- return undefined;
1729
- }
1730
- if (typeof vals === "string") {
1731
- return vals;
1732
- }
1733
- else if (vals.length > 0) {
1734
- return vals.join(",");
1735
- }
1736
- };
1737
- return {
1738
- getAnonymousId: function (_a) {
1739
- var name = _a.name, domain = _a.domain, _b = _a.cookiePolicy, cookiePolicy = _b === void 0 ? 'keep' : _b;
1740
- if (opts === null || opts === void 0 ? void 0 : opts.disableCookies) {
1741
- return "";
1742
- }
1743
- // In strict mode (cookiePolicy === 'strict'), don't use cookies at all
1744
- if (cookiePolicy === 'strict') {
1745
- // Return an empty string to indicate that we don't want to use cookies
1746
- return "";
1747
- }
1748
- var cookie = parseCookieString(req.headers["cookie"])[name];
1749
- if (!cookie) {
1750
- var cookieOpts = {
1751
- maxAge: 31622400 * 10,
1752
- httpOnly: false,
1753
- };
1754
- if (domain) {
1755
- cookieOpts.domain = domain;
1756
- }
1757
- var newId = generateId();
1758
- res.setHeader("Set-Cookie", serializeCookie(name, newId, cookieOpts));
1759
- return newId;
1760
- }
1761
- else {
1762
- return cookie;
1763
- }
1764
- },
1765
- getSourceIp: function () {
1766
- var ip = header(req, "x-forwarded-for") ||
1767
- header(req, "x-real-ip") ||
1768
- req.socket.remoteAddress;
1769
- return ip && ip.split(",")[0].trim();
1770
- },
1771
- describeClient: function () {
1772
- var url = req.url
1773
- ? new URL(req.url, req.url.startsWith("http") ? undefined : "http://localhost")
1774
- : {};
1775
- var requestHost = header(req, "x-forwarded-host") || header(req, "host") || url.hostname;
1776
- var proto = cutPostfix([":", "/"], header(req, "x-forwarded-proto") || url.protocol);
1777
- var query = ensurePrefix("?", url.search);
1778
- var path = ensurePrefix("/", url.pathname);
1779
- return {
1780
- doc_encoding: "",
1781
- doc_host: requestHost,
1782
- doc_path: req.url,
1783
- doc_search: query,
1784
- page_title: "",
1785
- referer: header(req, "referrer"),
1786
- screen_resolution: "",
1787
- url: proto + "://" + requestHost + (path || "") + (query || ""),
1788
- user_agent: req.headers["user-agent"],
1789
- user_language: req.headers["accept-language"] &&
1790
- req.headers["accept-language"].split(",")[0],
1791
- vp_size: "",
1792
- };
1793
- },
1794
- };
760
+ class me {
761
+ constructor(e) {
762
+ this.clicks = [], this.threshold = 3, this.timeWindow = 2e3, this.distanceThreshold = 30, this.client = e, this.initializeEventListener(), z(this);
763
+ }
764
+ initializeEventListener() {
765
+ document.addEventListener("click", this.handleClick.bind(this));
766
+ }
767
+ handleClick(e) {
768
+ const t = e.target;
769
+ this.shouldCaptureElement(t) && this.click(e.clientX, e.clientY, Date.now());
770
+ }
771
+ shouldCaptureElement(e) {
772
+ return !e.closest(".um-no-capture");
773
+ }
774
+ click(e, t, s) {
775
+ const n = { x: e, y: t, timestamp: s };
776
+ this.clicks.push(n), this.clicks = this.clicks.filter((r) => s - r.timestamp < this.timeWindow), this.clicks.length >= this.threshold && this.checkRageClick();
777
+ }
778
+ checkRageClick() {
779
+ const e = this.clicks[0], s = (this.clicks[this.clicks.length - 1].timestamp - e.timestamp) / 1e3;
780
+ this.clicks.every((r, o) => {
781
+ if (o === 0) return !0;
782
+ const c = this.clicks[o - 1];
783
+ return Math.sqrt(Math.pow(r.x - c.x, 2) + Math.pow(r.y - c.y, 2)) < this.distanceThreshold;
784
+ }) && this.sendRageClickEvent(s);
785
+ }
786
+ sendRageClickEvent(e) {
787
+ const t = this.clicks[this.clicks.length - 1];
788
+ document.elementFromPoint(t.x, t.y) && this.client.track("$rage_click", {
789
+ no_of_clicks: this.clicks.length,
790
+ time: e.toFixed(2)
791
+ }), this.clicks = [];
792
+ }
1795
793
  }
1796
- var emptyEnv = {
1797
- getSourceIp: function () { return undefined; },
1798
- describeClient: function () { return ({}); },
1799
- getAnonymousId: function () { return ""; },
1800
- };
1801
- /**
1802
- * Dictionary of supported environments
1803
- */
1804
- var envs = {
1805
- httpApi: httpApi,
1806
- nextjsApi: httpApi,
1807
- // fetchApi: fetchApi,
1808
- // nextjsMiddleware: fetchApi,
1809
- browser: function () { return browserEnv; },
1810
- express: httpApi,
1811
- empty: function () { return emptyEnv; },
1812
- };
1813
- var xmlHttpTransport = function (url, jsonPayload, additionalHeaders, handler) {
1814
- if (handler === void 0) { handler = function (code, body) {
1815
- }; }
1816
- var req = new window.XMLHttpRequest();
1817
- return new Promise(function (resolve, reject) {
1818
- req.onerror = function (e) {
1819
- getLogger().error("Failed to send payload to " + url + ": " + ((e === null || e === void 0 ? void 0 : e.message) || "unknown error"), jsonPayload, e);
1820
- handler(-1, {});
1821
- reject(new Error("Failed to send JSON. See console logs"));
1822
- };
1823
- req.onload = function () {
1824
- if (req.status !== 200) {
1825
- handler(req.status, {});
1826
- getLogger().warn("Failed to send data to " + url + " (#" + req.status + " - " + req.statusText + ")", jsonPayload);
1827
- reject(new Error("Failed to send JSON. Error code: " + req.status + ". See logs for details"));
1828
- }
1829
- else {
1830
- handler(req.status, req.responseText);
1831
- }
1832
- resolve();
1833
- };
1834
- req.open("POST", url);
1835
- req.setRequestHeader("Content-Type", "application/json");
1836
- Object.entries(additionalHeaders || {}).forEach(function (_a) {
1837
- var key = _a[0], val = _a[1];
1838
- return req.setRequestHeader(key, val);
794
+ class ye {
795
+ constructor(e, t, s = d()) {
796
+ this.trackingHost = e, this.logger = s, this.config = t;
797
+ }
798
+ async send(e) {
799
+ const t = this.config.key, s = new (void 0)(this.constructUrl(t)), n = {
800
+ hostname: s.hostname,
801
+ port: 443,
802
+ path: `${s.pathname}${s.search}`,
803
+ method: "POST",
804
+ headers: {
805
+ "Content-Type": "application/json",
806
+ ...this.getCustomHeaders()
807
+ }
808
+ };
809
+ return new Promise((r, o) => {
810
+ const c = (void 0)(n, (l) => {
811
+ l.on("data", (a) => {
812
+ }), l.on("end", () => {
813
+ const a = l.statusCode || 0;
814
+ a >= 200 && a < 300 ? (this.logger.debug(`Successfully sent ${e.length} event(s)`), r()) : o(new Error(`HTTP error! status: ${a}`));
1839
815
  });
1840
- req.send(jsonPayload);
1841
- getLogger().debug("sending json", jsonPayload);
816
+ });
817
+ c.on("error", (l) => {
818
+ o(l);
819
+ }), c.write(JSON.stringify(e)), c.end();
1842
820
  });
1843
- };
1844
- var fetchTransport = function (fetch) {
1845
- return function (url, jsonPayload, additionalHeaders, handler) {
1846
- if (handler === void 0) { handler = function (code, body) {
1847
- }; }
1848
- return __awaiter(void 0, void 0, void 0, function () {
1849
- var res, e_1, resJson, text, contentType, e_2;
1850
- var _a, _b;
1851
- return __generator(this, function (_c) {
1852
- switch (_c.label) {
1853
- case 0:
1854
- _c.trys.push([0, 2, , 3]);
1855
- return [4 /*yield*/, fetch(url, {
1856
- method: "POST",
1857
- headers: __assign({ Accept: "application/json", "Content-Type": "application/json" }, (additionalHeaders || {})),
1858
- body: jsonPayload,
1859
- })];
1860
- case 1:
1861
- res = _c.sent();
1862
- return [3 /*break*/, 3];
1863
- case 2:
1864
- e_1 = _c.sent();
1865
- getLogger().error("Failed to send data to " + url + ": " + ((e_1 === null || e_1 === void 0 ? void 0 : e_1.message) || "unknown error"), jsonPayload, e_1);
1866
- handler(-1, {});
1867
- return [2 /*return*/];
1868
- case 3:
1869
- if (res.status !== 200) {
1870
- getLogger().warn("Failed to send data to " + url + " (#" + res.status + " - " + res.statusText + ")", jsonPayload);
1871
- handler(res.status, {});
1872
- return [2 /*return*/];
1873
- }
1874
- resJson = {};
1875
- text = "";
1876
- contentType = (_b = (_a = res.headers) === null || _a === void 0 ? void 0 : _a.get('Content-Type')) !== null && _b !== void 0 ? _b : "";
1877
- _c.label = 4;
1878
- case 4:
1879
- _c.trys.push([4, 6, , 7]);
1880
- return [4 /*yield*/, res.text()];
1881
- case 5:
1882
- text = _c.sent();
1883
- resJson = JSON.parse(text);
1884
- return [3 /*break*/, 7];
1885
- case 6:
1886
- e_2 = _c.sent();
1887
- getLogger().error("Failed to parse " + url + " response. Content-type: " + contentType + " text: " + text, e_2);
1888
- return [3 /*break*/, 7];
1889
- case 7:
1890
- try {
1891
- handler(res.status, resJson);
1892
- }
1893
- catch (e) {
1894
- getLogger().error("Failed to handle " + url + " response. Content-type: " + contentType + " text: " + text, e);
1895
- }
1896
- return [2 /*return*/];
1897
- }
1898
- });
1899
- });
821
+ }
822
+ constructUrl(e) {
823
+ const t = this.config.cookiePolicy !== "keep" ? `&cookie_policy=${this.config.cookiePolicy}` : "", s = this.config.ipPolicy !== "keep" ? `&ip_policy=${this.config.ipPolicy}` : "";
824
+ return `${this.trackingHost}/api/v1/s2s/event?token=${e}${t}${s}`;
825
+ }
826
+ getCustomHeaders() {
827
+ return typeof this.config.customHeaders == "function" ? this.config.customHeaders() : this.config.customHeaders ? this.config.customHeaders : {};
828
+ }
829
+ }
830
+ class y {
831
+ constructor(e, t = "all", s = {}) {
832
+ this.instance = e, this.trackingType = t, this.options = s, document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", this.initialize.bind(this)) : this.initialize();
833
+ }
834
+ initialize() {
835
+ this.trackingType !== "none" && this.setupFormTracking();
836
+ }
837
+ setupFormTracking() {
838
+ var e;
839
+ this.formElements = this.trackingType === "tagged" ? document.querySelectorAll("form[data-um-form]") : document.querySelectorAll("form"), (e = this.formElements) == null || e.forEach((t) => {
840
+ t.addEventListener("submit", this.handleFormSubmit.bind(this));
841
+ });
842
+ }
843
+ handleFormSubmit(e) {
844
+ const t = e.target, s = this._getFormDetails(t);
845
+ this.instance.track("$form", R(s)), this.options.trackFieldChanges && this.trackFieldChanges(t);
846
+ }
847
+ trackFieldChanges(e) {
848
+ e.querySelectorAll("input, select, textarea").forEach((s) => {
849
+ s.addEventListener("change", (n) => {
850
+ const r = this._getFieldProps(n.target, 0);
851
+ this.instance.track("$form_field_change", R(r));
852
+ });
853
+ });
854
+ }
855
+ static getInstance(e, t = "all", s = {}) {
856
+ return y.instance || (y.instance = new y(e, t, s)), y.instance;
857
+ }
858
+ _getFormDetails(e) {
859
+ const t = {
860
+ form_id: e.id,
861
+ form_name: e.name || "",
862
+ form_action: e.action,
863
+ form_method: e.method,
864
+ form_class: e.className,
865
+ form_attributes: this._getElementAttributes(e)
866
+ }, s = e.querySelectorAll("input, select, textarea");
867
+ return Array.from(s).filter((r) => !r.classList.contains("um-no-capture")).forEach((r, o) => {
868
+ const c = this._getFieldProps(r, o);
869
+ Object.assign(t, c);
870
+ }), t;
871
+ }
872
+ _getFieldProps(e, t) {
873
+ const s = Object.keys(e.dataset).length ? JSON.stringify(e.dataset) : void 0, n = this.getSafeText(e);
874
+ return {
875
+ [`field_${t + 1}_tag`]: e.tagName.toLowerCase(),
876
+ [`field_${t + 1}_type`]: e instanceof HTMLInputElement ? e.type : void 0,
877
+ [`field_${t + 1}_data_attributes`]: s,
878
+ [`field_${t + 1}_id`]: e.id,
879
+ [`field_${t + 1}_value`]: n,
880
+ [`field_${t + 1}_class`]: e.className,
881
+ [`field_${t + 1}_name`]: e.name,
882
+ [`field_${t + 1}_attributes`]: this._getElementAttributes(e)
1900
883
  };
1901
- };
1902
- var UsermavenClientImpl = /** @class */ (function () {
1903
- function UsermavenClientImpl() {
1904
- this.userProperties = {};
1905
- this.groupProperties = {};
1906
- this.permanentProperties = {
1907
- globalProps: {},
1908
- propsPerEvent: {},
1909
- };
1910
- this.cookieDomain = "";
1911
- this.trackingHost = "";
1912
- this.idCookieName = "";
1913
- this.randomizeUrl = false;
1914
- this.namespace = "usermaven";
1915
- this.crossDomainLinking = true;
1916
- this.formTracking = false;
1917
- this.domains = [];
1918
- this.apiKey = "";
1919
- this.initialized = false;
1920
- this._3pCookies = {};
1921
- this.cookiePolicy = "keep";
1922
- this.ipPolicy = "keep";
1923
- this.beaconApi = false;
1924
- this.transport = xmlHttpTransport;
1925
- this.customHeaders = function () { return ({}); };
1926
- this.queue = new MemoryQueue();
1927
- this.maxSendAttempts = 4;
1928
- this.retryTimeout = [500, 1e12];
1929
- this.flushing = false;
1930
- this.attempt = 1;
1931
- this.propertyBlacklist = [];
1932
- // public persistence?: UserMavenPersistence;
1933
- // public sessionManager?: SessionIdManager;
1934
- this.__autocapture_enabled = false;
1935
- this.__auto_pageview_enabled = false;
1936
- // private anonymousId: string = '';
1937
- // Fallback tracking host
1938
- this.trackingHostFallback = "https://events.usermaven.com" ;
884
+ }
885
+ _getElementAttributes(e) {
886
+ return Object.keys(e.dataset).length ? JSON.parse(JSON.stringify(e.dataset)) : {};
887
+ }
888
+ getSafeText(e) {
889
+ let t = "";
890
+ return "value" in e && e.type !== "password" ? t = e.value : e.hasChildNodes() ? t = Array.from(e.childNodes).filter(
891
+ (n) => n.nodeType === Node.TEXT_NODE
892
+ ).map((n) => n.textContent).join("") : t = e.textContent || "", this._scrubPotentiallySensitiveValues(t);
893
+ }
894
+ _scrubPotentiallySensitiveValues(e) {
895
+ return this._shouldCaptureValue(e) ? e : "<redacted>";
896
+ }
897
+ _shouldCaptureValue(e) {
898
+ return !(this._isNullish(e) || this._isString(e) && (e = this._trim(e), /^(?:(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((e || "").replace(/[- ]/g, "")) || /(^\d{3}-?\d{2}-?\d{4}$)/.test(e)));
899
+ }
900
+ _isNullish(e) {
901
+ return e == null;
902
+ }
903
+ _isString(e) {
904
+ return typeof e == "string" || e instanceof String;
905
+ }
906
+ _trim(e) {
907
+ if (typeof String.prototype.trim == "function")
908
+ return e.trim();
909
+ let t = 0, s = e.length - 1;
910
+ const n = [
911
+ " ",
912
+ `
913
+ `,
914
+ "\r",
915
+ " ",
916
+ "\f",
917
+ "\v",
918
+ " ",
919
+ " ",
920
+ " ",
921
+ "",
922
+ " ",
923
+ " ",
924
+ " ",
925
+ " ",
926
+ " ",
927
+ " ",
928
+ " ",
929
+ " ",
930
+ " ",
931
+ "\u2028",
932
+ "\u2029",
933
+ " ",
934
+ " ",
935
+ " "
936
+ ].join("");
937
+ for (; t <= s && n.indexOf(e[t]) > -1; )
938
+ t++;
939
+ for (; s >= t && n.indexOf(e[s]) > -1; )
940
+ s--;
941
+ return e.slice(t, s + 1);
942
+ }
943
+ }
944
+ class we {
945
+ constructor(e) {
946
+ this.config = this.mergeConfig(e, U), this.logger = d(this.config.logLevel), this.namespace = e.namespace || "default", this.transport = this.initializeTransport(this.config), this.persistence = this.initializePersistence(), this.retryQueue = new F(
947
+ this.transport,
948
+ this.config.maxSendAttempts || 3,
949
+ this.config.minSendTimeout || 1e3,
950
+ 10,
951
+ 200,
952
+ // Reduced interval to .2 second
953
+ this.logger,
954
+ this.namespace
955
+ ), u() && this.initializeBrowserFeatures(), this.anonymousId = this.getOrCreateAnonymousId(), this.logger.info(`Usermaven client initialized for namespace: ${this.namespace}`);
956
+ }
957
+ initializeBrowserFeatures() {
958
+ if (this.cookieManager = new X(this.config.cookieDomain), this.config.autocapture && S.enabledForProject(this.config.key) && (this.autoCapture = new S(this, this.config, this.logger), this.autoCapture.init()), this.config.formTracking) {
959
+ const e = this.config.formTracking === !0 ? "all" : this.config.formTracking;
960
+ this.formTracking = y.getInstance(this, e || "none", {
961
+ trackFieldChanges: !1
962
+ });
963
+ }
964
+ this.config.autoPageview && (this.pageviewTracking = new de(this)), this.config.crossDomainLinking && this.manageCrossDomainLinking(), this.config.rageClick && (this.rageClick = new me(this)), this.setupPageLeaveTracking();
965
+ }
966
+ /**
967
+ * Recursively merge the provided configuration with the existing defaultConfig
968
+ * @param config
969
+ * @param defaultConfig
970
+ */
971
+ mergeConfig(e, t) {
972
+ const s = JSON.parse(JSON.stringify(e));
973
+ let n = { ...t, ...s };
974
+ return Object.keys(t).forEach((r) => {
975
+ k(t[r]) && (n[r] = this.mergeConfig(e[r], t[r]));
976
+ }), n;
977
+ }
978
+ init(e) {
979
+ this.config = { ...this.config, ...e }, this.logger = d(this.config.logLevel), this.namespace = e.namespace || this.namespace, this.transport = this.initializeTransport(e), this.persistence = this.initializePersistence(), this.retryQueue = new F(
980
+ this.transport,
981
+ this.config.maxSendAttempts || 3,
982
+ this.config.minSendTimeout || 1e3,
983
+ 10,
984
+ 250,
985
+ // Reduced interval to .25 second
986
+ this.logger,
987
+ this.namespace
988
+ ), u() && this.initializeBrowserFeatures(), this.anonymousId = this.getOrCreateAnonymousId(), this.logger.info(`Usermaven client reinitialized for namespace: ${this.namespace}`);
989
+ }
990
+ manageCrossDomainLinking() {
991
+ if (!this.config.crossDomainLinking || !this.config.domains)
992
+ return;
993
+ const e = this.config.domains.split(",").map((s) => s.trim()), t = this.config.cookieName || `__eventn_id_${this.config.key}`;
994
+ document.addEventListener("click", (s) => {
995
+ var c;
996
+ const n = this.findClosestLink(s.target);
997
+ if (!n) return;
998
+ const r = n.getAttribute("href");
999
+ if (!r || !r.startsWith("http")) return;
1000
+ const o = new URL(r);
1001
+ if (o.hostname !== window.location.hostname && e.includes(o.hostname)) {
1002
+ const l = (c = this.cookieManager) == null ? void 0 : c.get(t);
1003
+ l && (o.searchParams.append("_um", l), n.setAttribute("href", o.toString()));
1004
+ }
1005
+ }), this.logger.debug("Cross-domain linking initialized");
1006
+ }
1007
+ findClosestLink(e) {
1008
+ for (; e && e.tagName !== "A"; )
1009
+ e = e.parentElement;
1010
+ return e;
1011
+ }
1012
+ initializeTransport(e) {
1013
+ const t = "https://events.usermaven.com";
1014
+ if (!u())
1015
+ return new ye(e.trackingHost || t, e);
1016
+ const s = "XMLHttpRequest" in window, n = typeof fetch < "u", r = typeof navigator < "u" && "sendBeacon" in navigator;
1017
+ if (e.useBeaconApi && r)
1018
+ return new ge(e.trackingHost || t, e, this.logger);
1019
+ if (e.forceUseFetch && n)
1020
+ return new D(e.trackingHost || t, e, this.logger);
1021
+ if (s)
1022
+ return new fe(e.trackingHost || t, e, this.logger);
1023
+ if (n)
1024
+ return new D(e.trackingHost || t, e, this.logger);
1025
+ throw new Error("No suitable transport method available");
1026
+ }
1027
+ initializePersistence() {
1028
+ return this.config.disableEventPersistence || !u() ? new pe() : new V(`${this.namespace}_${this.config.key}`, this.logger);
1029
+ }
1030
+ getOrCreateAnonymousId() {
1031
+ var s, n;
1032
+ if (!u())
1033
+ return T();
1034
+ if (this.config.privacyPolicy === "strict" || this.config.cookiePolicy === "strict")
1035
+ return "";
1036
+ const e = this.config.cookieName || `__eventn_id_${this.config.key}`;
1037
+ let t = (s = this.cookieManager) == null ? void 0 : s.get(e);
1038
+ if (!t) {
1039
+ if (this.config.crossDomainLinking) {
1040
+ const c = new URLSearchParams(window.location.search).get("_um"), a = window.location.hash.substring(1).split("~"), h = a.length > 1 ? a[1] : void 0;
1041
+ t = c || h || T();
1042
+ }
1043
+ t || (t = T());
1044
+ const r = 365 * 10;
1045
+ (n = this.cookieManager) == null || n.set(e, t, r, document.location.protocol !== "http:", !1);
1046
+ }
1047
+ return t;
1048
+ }
1049
+ async id(e, t = !1) {
1050
+ if (!k(e))
1051
+ throw new Error("User data must be an object");
1052
+ if (e.email && !ae(e.email))
1053
+ throw new Error("Invalid email provided");
1054
+ if (!e.id || !I(e.id))
1055
+ throw new Error("User ID must be a string");
1056
+ const s = e.id;
1057
+ if (this.persistence.set("userId", s), this.persistence.set("userProps", e), !t) {
1058
+ const n = {
1059
+ ...e,
1060
+ anonymous_id: this.anonymousId
1061
+ };
1062
+ await this.track("user_identify", n);
1063
+ }
1064
+ this.logger.info("User identified:", e);
1065
+ }
1066
+ track(e, t, s = !1) {
1067
+ this.trackInternal(e, t, s);
1068
+ }
1069
+ trackInternal(e, t, s = !1) {
1070
+ if (!I(e))
1071
+ throw new Error("Event name must be a string");
1072
+ if (t !== void 0 && (typeof t != "object" || t === null || Array.isArray(t)))
1073
+ throw new Error("Event payload must be a non-null object and not an array");
1074
+ const n = this.createEventPayload(e, t);
1075
+ try {
1076
+ if (s) {
1077
+ this.transport.send(n), this.logger.debug(`Event sent: ${e}`, [n]);
1078
+ return;
1079
+ }
1080
+ this.retryQueue.add(n), this.logger.debug(`Event tracked: ${e}`, [n]);
1081
+ } catch (r) {
1082
+ throw this.logger.error(`Failed to track event: ${e}`, r), new Error(`Failed to track event: ${e}`);
1939
1083
  }
1940
- // Used for session + autocapture
1941
- UsermavenClientImpl.prototype.get_config = function (prop_name) {
1942
- return this.config ? this.config[prop_name] : null;
1943
- };
1944
- UsermavenClientImpl.prototype.id = function (props, doNotSendEvent) {
1945
- this.userProperties = __assign(__assign({}, this.userProperties), props);
1946
- getLogger().debug("Usermaven user identified", props);
1947
- if (this.userIdPersistence) {
1948
- this.userIdPersistence.save(props);
1949
- }
1950
- else {
1951
- getLogger().warn("Id() is called before initialization");
1952
- }
1953
- if (!doNotSendEvent) {
1954
- return this.track("user_identify", {});
1955
- }
1956
- else {
1957
- return Promise.resolve();
1958
- }
1959
- };
1960
- UsermavenClientImpl.prototype.group = function (props, doNotSendEvent) {
1961
- this.groupProperties = __assign(__assign({}, this.groupProperties), props);
1962
- getLogger().debug("Usermaven group identified", props);
1963
- if (this.userIdPersistence) {
1964
- // Update the 'company' property in the user persistence
1965
- this.userIdPersistence.save({ company: props });
1966
- }
1967
- else {
1968
- getLogger().warn("Group() is called before initialization");
1969
- }
1970
- if (!doNotSendEvent) {
1971
- return this.track("group", {});
1972
- }
1973
- else {
1974
- return Promise.resolve();
1975
- }
1976
- };
1977
- UsermavenClientImpl.prototype.reset = function (resetAnonId) {
1978
- if (this.userIdPersistence) {
1979
- this.userIdPersistence.delete();
1980
- }
1981
- if (this.propsPersistance) {
1982
- this.propsPersistance.delete();
1983
- }
1984
- if (resetAnonId) {
1985
- var idCookie = getCookie(this.idCookieName);
1986
- if (idCookie) {
1987
- getLogger().debug("Removing id cookie", idCookie);
1988
- setCookie(this.idCookieName, "", {
1989
- domain: this.cookieDomain,
1990
- expires: new Date(0),
1991
- });
1992
- }
1993
- }
1994
- return Promise.resolve();
1995
- };
1996
- UsermavenClientImpl.prototype.rawTrack = function (payload) {
1997
- return this.sendJson(payload);
1998
- };
1999
- UsermavenClientImpl.prototype.makeEvent = function (event_type, src, payload) {
2000
- var _a;
2001
- var env = payload.env, payloadData = __rest(payload, ["env"]);
2002
- if (!env) {
2003
- env = isWindowAvailable() ? envs.browser() : envs.empty();
2004
- }
2005
- this.restoreId();
2006
- var context = this.getCtx(env);
2007
- var persistentProps = __assign(__assign({}, this.permanentProperties.globalProps), ((_a = this.permanentProperties.propsPerEvent[event_type]) !== null && _a !== void 0 ? _a : {}));
2008
- var base = __assign({ api_key: this.apiKey, src: src, event_type: event_type }, payloadData);
2009
- var sourceIp = env.getSourceIp();
2010
- if (sourceIp) {
2011
- base["source_ip"] = sourceIp;
2012
- }
2013
- return this.compatMode
2014
- ? __assign(__assign(__assign({}, persistentProps), { eventn_ctx: context }), base) : __assign(__assign(__assign({}, persistentProps), context), base);
2015
- };
2016
- UsermavenClientImpl.prototype._send3p = function (sourceType, object, type) {
2017
- var eventType = "3rdparty";
2018
- if (type && type !== "") {
2019
- eventType = type;
2020
- }
2021
- var e = this.makeEvent(eventType, sourceType, {
2022
- src_payload: object,
2023
- });
2024
- return this.sendJson(e);
2025
- };
2026
- UsermavenClientImpl.prototype.sendJson = function (json) {
2027
- return __awaiter(this, void 0, Promise, function () {
2028
- var umExclusionState;
2029
- return __generator(this, function (_a) {
2030
- switch (_a.label) {
2031
- case 0:
2032
- umExclusionState = getUmExclusionState();
2033
- if (!!umExclusionState) return [3 /*break*/, 3];
2034
- if (!(this.maxSendAttempts > 1)) return [3 /*break*/, 1];
2035
- this.queue.push([json, 0]);
2036
- this.scheduleFlush(0);
2037
- return [3 /*break*/, 3];
2038
- case 1: return [4 /*yield*/, this.doSendJson(json)];
2039
- case 2:
2040
- _a.sent();
2041
- _a.label = 3;
2042
- case 3: return [2 /*return*/];
2043
- }
2044
- });
2045
- });
2046
- };
2047
- UsermavenClientImpl.prototype.doSendJson = function (json) {
2048
- var _this = this;
2049
- var cookiePolicy = this.cookiePolicy !== "keep" ? "&cookie_policy=" + this.cookiePolicy : "";
2050
- var ipPolicy = this.ipPolicy !== "keep" ? "&ip_policy=" + this.ipPolicy : "";
2051
- var urlPrefix = isWindowAvailable() ? "/api/v1/event" : "/api/v1/s2s/event";
2052
- var url = "" + this.trackingHost + urlPrefix + "?token=" + this.apiKey + cookiePolicy + ipPolicy;
2053
- if (this.randomizeUrl) {
2054
- url = this.trackingHost + "/api." + generateRandom() + "?p_" + generateRandom() + "=" + this.apiKey + cookiePolicy + ipPolicy;
2055
- }
2056
- var jsonString = JSON.stringify(json);
2057
- getLogger().debug("Sending payload to " + url, json.length);
2058
- return this.transport(url, jsonString, this.customHeaders(), function (code, body) {
2059
- return _this.postHandle(code, body);
2060
- });
2061
- };
2062
- UsermavenClientImpl.prototype.scheduleFlush = function (timeout) {
2063
- var _this = this;
2064
- if (this.flushing) {
2065
- return;
2066
- }
2067
- this.flushing = true;
2068
- if (typeof timeout === "undefined") {
2069
- var random = Math.random() + 1;
2070
- var factor = Math.pow(2, this.attempt++);
2071
- timeout = Math.min(this.retryTimeout[0] * random * factor, this.retryTimeout[1]);
2072
- }
2073
- getLogger().debug("Scheduling event queue flush in " + timeout + " ms.");
2074
- setTimeout(function () { return _this.flush(); }, timeout);
2075
- };
2076
- UsermavenClientImpl.prototype.flush = function () {
2077
- return __awaiter(this, void 0, Promise, function () {
2078
- var queue;
2079
- var _a;
2080
- var _this = this;
2081
- return __generator(this, function (_b) {
2082
- switch (_b.label) {
2083
- case 0:
2084
- if (isWindowAvailable() && !window.navigator.onLine) {
2085
- this.flushing = false;
2086
- this.scheduleFlush();
2087
- }
2088
- queue = this.queue.flush();
2089
- this.flushing = false;
2090
- if (queue.length === 0) {
2091
- return [2 /*return*/];
2092
- }
2093
- _b.label = 1;
2094
- case 1:
2095
- _b.trys.push([1, 3, , 4]);
2096
- return [4 /*yield*/, this.doSendJson(queue.map(function (el) { return el[0]; }))];
2097
- case 2:
2098
- _b.sent();
2099
- this.attempt = 1;
2100
- getLogger().debug("Successfully flushed " + queue.length + " events from queue");
2101
- return [3 /*break*/, 4];
2102
- case 3:
2103
- _b.sent();
2104
- // In case of failing custom domain (trackingHost), we will replace it with default domain (trackingHostFallback)
2105
- if (this.trackingHost !== this.trackingHostFallback) {
2106
- getLogger().debug("Using fallback tracking host " + this.trackingHostFallback + " instead of " + this.trackingHost + " on " + VERSION_INFO.env);
2107
- this.trackingHost = this.trackingHostFallback;
2108
- }
2109
- queue = queue.map(function (el) { return [el[0], el[1] + 1]; }).filter(function (el) {
2110
- if (el[1] >= _this.maxSendAttempts) {
2111
- getLogger().error("Dropping queued event after " + el[1] + " attempts since max send attempts " + _this.maxSendAttempts + " reached. See logs for details");
2112
- return false;
2113
- }
2114
- return true;
2115
- });
2116
- if (queue.length > 0) {
2117
- (_a = this.queue).push.apply(_a, queue);
2118
- this.scheduleFlush();
2119
- }
2120
- else {
2121
- this.attempt = 1;
2122
- }
2123
- return [3 /*break*/, 4];
2124
- case 4: return [2 /*return*/];
2125
- }
2126
- });
2127
- });
2128
- };
2129
- UsermavenClientImpl.prototype.postHandle = function (status, response) {
2130
- if (this.cookiePolicy === "strict" || this.cookiePolicy === "comply") {
2131
- if (status === 200) {
2132
- var data = response;
2133
- if (typeof response === "string") {
2134
- data = JSON.parse(response);
2135
- }
2136
- if (!data["delete_cookie"]) {
2137
- return;
2138
- }
2139
- }
2140
- this.userIdPersistence.delete();
2141
- this.propsPersistance.delete();
2142
- deleteCookie(this.idCookieName);
2143
- }
2144
- if (status === 200) {
2145
- var data = response;
2146
- if (typeof response === "string" && response.length > 0) {
2147
- data = JSON.parse(response);
2148
- var extras = data["jitsu_sdk_extras"];
2149
- if (extras && extras.length > 0) {
2150
- var isWindow = isWindowAvailable();
2151
- if (!isWindow) {
2152
- getLogger().error("Tags destination supported only in browser environment");
2153
- }
2154
- else {
2155
- for (var _i = 0, extras_1 = extras; _i < extras_1.length; _i++) {
2156
- var _a = extras_1[_i], type = _a.type, id = _a.id, value = _a.value;
2157
- if (type === "tag") {
2158
- var tag = document.createElement("div");
2159
- tag.id = id;
2160
- insertAndExecute(tag, value);
2161
- if (tag.childElementCount > 0) {
2162
- document.body.appendChild(tag);
2163
- }
2164
- }
2165
- }
2166
- }
2167
- }
2168
- }
2169
- }
2170
- };
2171
- UsermavenClientImpl.prototype.getCtx = function (env) {
2172
- var now = new Date();
2173
- var props = env.describeClient() || {};
2174
- var user = __assign({}, this.userProperties);
2175
- var company = user['company'] || {};
2176
- delete user['company'];
2177
- var payload = __assign(__assign({ event_id: "", user: __assign(__assign({}, user), { anonymous_id: env.getAnonymousId({
2178
- name: this.idCookieName,
2179
- domain: this.cookieDomain,
2180
- crossDomainLinking: this.crossDomainLinking,
2181
- cookiePolicy: this.cookiePolicy
2182
- }) }), ids: this._getIds(), utc_time: reformatDate(now.toISOString()), local_tz_offset: now.getTimezoneOffset() }, props), getDataFromParams(parseQuery(props.doc_search)));
2183
- // id and name attributes will be checked on backend
2184
- if (Object.keys(company).length) {
2185
- payload['company'] = company;
2186
- }
2187
- return payload;
2188
- };
2189
- UsermavenClientImpl.prototype._getIds = function () {
2190
- if (!isWindowAvailable()) {
2191
- return {};
2192
- }
2193
- var cookies = getCookies(false);
2194
- var res = {};
2195
- for (var _i = 0, _a = Object.entries(cookies); _i < _a.length; _i++) {
2196
- var _b = _a[_i], key = _b[0], value = _b[1];
2197
- if (this._3pCookies[key]) {
2198
- res[key.charAt(0) == "_" ? key.substr(1) : key] = value;
2199
- }
2200
- }
2201
- return res;
2202
- };
2203
- UsermavenClientImpl.prototype.pathMatches = function (wildcardPath, docUrl) {
2204
- var actualPath = new URL(docUrl).pathname;
2205
- return actualPath.match(new RegExp('^' + wildcardPath.trim().replace(/\*\*/g, '.*').replace(/([^\.])\*/g, '$1[^\\s\/]*') + '\/?$'));
2206
- };
2207
- UsermavenClientImpl.prototype.track = function (type, payload) {
2208
- var _this = this;
2209
- var data = payload || {};
2210
- getLogger().debug("track event of type", type, data);
2211
- var env = isWindowAvailable() ? envs.browser() : envs.empty();
2212
- var context = this.getCtx(env);
2213
- // Check if the page is not excluded.
2214
- if (this.config && this.config.exclude && this.config.exclude.length > 1 && (context === null || context === void 0 ? void 0 : context.url)) {
2215
- var excludeList = this.config.exclude.split(',');
2216
- // check if the current page is in the exclude list
2217
- if (excludeList.some(function (excludePage) { return _this.pathMatches(excludePage.trim(), context === null || context === void 0 ? void 0 : context.url); })) {
2218
- getLogger().debug("Page is excluded from tracking");
2219
- return;
2220
- }
2221
- }
2222
- var p = payload || {};
2223
- // All custom events and scroll event will have event_attributes
2224
- if (type !== "$autocapture" && type !== "user_identify" && type !== "pageview" && type !== "$pageleave") {
2225
- p = {
2226
- event_attributes: payload,
2227
- };
2228
- }
2229
- var e = this.makeEvent(type, this.compatMode ? "eventn" : "usermaven", p);
2230
- return this.sendJson(e);
2231
- };
2232
- UsermavenClientImpl.prototype.init = function (options) {
2233
- var _this = this;
2234
- var _a, _b, _c, _d, _e, _f;
2235
- if (isWindowAvailable() && !options.force_use_fetch) {
2236
- if (options.fetch) {
2237
- getLogger().warn("Custom fetch implementation is provided to Usermaven. However, it will be ignored since Usermaven runs in browser");
2238
- }
2239
- this.transport = this.beaconApi ? beaconTransport : xmlHttpTransport;
2240
- }
2241
- else {
2242
- if (!options.fetch && !globalThis.fetch) {
2243
- throw new Error("Usermaven runs in Node environment. However, neither UsermavenOptions.fetch is provided, nor global fetch function is defined. \n" +
2244
- "Please, provide custom fetch implementation. You can get it via node-fetch package");
2245
- }
2246
- this.transport = fetchTransport(options.fetch || globalThis.fetch);
2247
- }
2248
- if (options.custom_headers &&
2249
- typeof options.custom_headers === "function") {
2250
- this.customHeaders = options.custom_headers;
2251
- }
2252
- else if (options.custom_headers) {
2253
- this.customHeaders = function () {
2254
- return options.custom_headers;
2255
- };
2256
- }
2257
- if (options.tracking_host === "echo") {
2258
- getLogger().warn('jitsuClient is configured with "echo" transport. Outgoing requests will be written to console');
2259
- this.transport = echoTransport;
2260
- }
2261
- if (options.ip_policy) {
2262
- this.ipPolicy = options.ip_policy;
2263
- }
2264
- if (options.cookie_policy) {
2265
- this.cookiePolicy = options.cookie_policy;
2266
- }
2267
- if (options.privacy_policy === "strict") {
2268
- this.ipPolicy = "strict";
2269
- this.cookiePolicy = "strict";
2270
- }
2271
- if (options.use_beacon_api && navigator.sendBeacon) {
2272
- this.beaconApi = true;
2273
- }
2274
- //can't handle delete cookie response when beacon api
2275
- if (this.cookiePolicy === "comply" && this.beaconApi) {
2276
- this.cookiePolicy = "strict";
2277
- }
2278
- if (options.log_level) {
2279
- setRootLogLevel(options.log_level);
2280
- }
2281
- this.initialOptions = options;
2282
- getLogger().debug("Initializing Usemaven Tracker tracker", options, USERMAVEN_VERSION);
2283
- if (!options.key) {
2284
- getLogger().error("Can't initialize Usemaven, key property is not set");
2285
- return;
2286
- }
2287
- this.compatMode =
2288
- options.compat_mode === undefined
2289
- ? defaultCompatMode
2290
- : !!options.compat_mode;
2291
- this.cookieDomain = options.cookie_domain || getCookieDomain();
2292
- this.namespace = options.namespace || "usermaven";
2293
- this.crossDomainLinking = (_a = options.cross_domain_linking) !== null && _a !== void 0 ? _a : true;
2294
- this.formTracking = (_b = options.form_tracking) !== null && _b !== void 0 ? _b : false;
2295
- this.domains = options.domains ? (options.domains).split(',').map(function (domain) { return domain.trim(); }) : [];
2296
- this.trackingHost = getHostWithProtocol(options["tracking_host"] || "t.usermaven.com");
2297
- this.randomizeUrl = options.randomize_url || false;
2298
- this.apiKey = options.key;
2299
- this.__auto_pageview_enabled = options.auto_pageview || false;
2300
- this.idCookieName = options.cookie_name || "__eventn_id_" + options.key;
2301
- if (this.cookiePolicy === "strict") {
2302
- this.propsPersistance = new NoPersistence();
2303
- }
2304
- else {
2305
- this.propsPersistance = isWindowAvailable()
2306
- ? new CookiePersistence(this.cookieDomain, this.idCookieName + "_props")
2307
- : new NoPersistence();
2308
- }
2309
- if (this.cookiePolicy === "strict") {
2310
- this.userIdPersistence = new NoPersistence();
2311
- }
2312
- else {
2313
- this.userIdPersistence = isWindowAvailable()
2314
- ? new CookiePersistence(this.cookieDomain, this.idCookieName + "_usr")
2315
- : new NoPersistence();
2316
- }
2317
- if (this.propsPersistance) {
2318
- var restored = this.propsPersistance.restore();
2319
- if (restored) {
2320
- this.permanentProperties = restored;
2321
- this.permanentProperties.globalProps = (_c = restored.globalProps) !== null && _c !== void 0 ? _c : {};
2322
- this.permanentProperties.propsPerEvent = (_d = restored.propsPerEvent) !== null && _d !== void 0 ? _d : {};
2323
- }
2324
- getLogger().debug("Restored persistent properties", this.permanentProperties);
2325
- }
2326
- this.propertyBlacklist = options.property_blacklist && options.property_blacklist.length > 0 ? options.property_blacklist : [];
2327
- // // Added these configuration for session management + autocapture
2328
- var defaultConfig = {
2329
- autocapture: false,
2330
- properties_string_max_length: null,
2331
- property_blacklist: [],
2332
- sanitize_properties: null,
2333
- auto_pageview: false
2334
- };
2335
- this.config = _extend({}, defaultConfig, options || {}, this.config || {}, { token: this.apiKey });
2336
- getLogger().debug('Default Configuration', this.config);
2337
- // this.manageSession(this.config);
2338
- this.manageAutoCapture(this.config);
2339
- this.manageFormTracking(this.config);
2340
- this.manageCrossDomainLinking({
2341
- cross_domain_linking: this.crossDomainLinking,
2342
- domains: this.domains,
2343
- cookiePolicy: this.cookiePolicy
2344
- });
2345
- if (options.capture_3rd_party_cookies === false) {
2346
- this._3pCookies = {};
2347
- }
2348
- else {
2349
- (options.capture_3rd_party_cookies || [
2350
- "_ga",
2351
- "_fbp",
2352
- "_ym_uid",
2353
- "ajs_user_id",
2354
- "ajs_anonymous_id",
2355
- ]).forEach(function (name) { return (_this._3pCookies[name] = true); });
2356
- }
2357
- if (options.ga_hook) {
2358
- getLogger().warn("GA event interceptor isn't supported anymore");
2359
- }
2360
- if (options.segment_hook) {
2361
- interceptSegmentCalls(this);
2362
- }
2363
- if (isWindowAvailable()) {
2364
- if (!options.disable_event_persistence) {
2365
- this.queue = new LocalStorageQueue(this.namespace + "-event-queue");
2366
- this.scheduleFlush(0);
2367
- }
2368
- window.addEventListener("beforeunload", function () { return _this.flush(); });
2369
- }
2370
- if (this.__auto_pageview_enabled) {
2371
- enableAutoPageviews(this);
2372
- }
2373
- this.retryTimeout = [
2374
- (_e = options.min_send_timeout) !== null && _e !== void 0 ? _e : this.retryTimeout[0],
2375
- (_f = options.max_send_timeout) !== null && _f !== void 0 ? _f : this.retryTimeout[1],
2376
- ];
2377
- if (!!options.max_send_attempts) {
2378
- this.maxSendAttempts = options.max_send_attempts;
2379
- }
2380
- this.initialized = true;
2381
- };
2382
- UsermavenClientImpl.prototype.interceptAnalytics = function (analytics) {
2383
- var _this = this;
2384
- var interceptor = function (chain) {
2385
- var _a;
2386
- try {
2387
- var payload = __assign({}, chain.payload);
2388
- getLogger().debug("Intercepted segment payload", payload.obj);
2389
- var integration = chain.integrations["Segment.io"];
2390
- if (integration && integration.analytics) {
2391
- var analyticsOriginal = integration.analytics;
2392
- if (typeof analyticsOriginal.user === "function" &&
2393
- analyticsOriginal.user() &&
2394
- typeof analyticsOriginal.user().id === "function") {
2395
- payload.obj.userId = analyticsOriginal.user().id();
2396
- }
2397
- }
2398
- if ((_a = payload === null || payload === void 0 ? void 0 : payload.obj) === null || _a === void 0 ? void 0 : _a.timestamp) {
2399
- payload.obj.sentAt = payload.obj.timestamp;
2400
- }
2401
- var type = chain.payload.type();
2402
- if (type === "track") {
2403
- type = chain.payload.event();
2404
- }
2405
- _this._send3p("ajs", payload, type);
2406
- }
2407
- catch (e) {
2408
- getLogger().warn("Failed to send an event", e);
2409
- }
2410
- chain.next(chain.payload);
2411
- };
2412
- if (typeof analytics.addSourceMiddleware === "function") {
2413
- //analytics is fully initialized
2414
- getLogger().debug("Analytics.js is initialized, calling addSourceMiddleware");
2415
- analytics.addSourceMiddleware(interceptor);
2416
- }
2417
- else {
2418
- getLogger().debug("Analytics.js is not initialized, pushing addSourceMiddleware to callstack");
2419
- analytics.push(["addSourceMiddleware", interceptor]);
2420
- }
2421
- analytics["__en_intercepted"] = true;
2422
- };
2423
- UsermavenClientImpl.prototype.restoreId = function () {
2424
- if (this.userIdPersistence) {
2425
- var props = this.userIdPersistence.restore();
2426
- if (props) {
2427
- this.userProperties = __assign(__assign({}, props), this.userProperties);
2428
- }
2429
- }
2430
- };
2431
- UsermavenClientImpl.prototype.set = function (properties, opts) {
2432
- var _a;
2433
- var eventType = opts === null || opts === void 0 ? void 0 : opts.eventType;
2434
- var persist = (opts === null || opts === void 0 ? void 0 : opts.persist) === undefined || (opts === null || opts === void 0 ? void 0 : opts.persist);
2435
- if (eventType !== undefined) {
2436
- var current = (_a = this.permanentProperties.propsPerEvent[eventType]) !== null && _a !== void 0 ? _a : {};
2437
- this.permanentProperties.propsPerEvent[eventType] = __assign(__assign({}, current), properties);
2438
- }
2439
- else {
2440
- this.permanentProperties.globalProps = __assign(__assign({}, this.permanentProperties.globalProps), properties);
2441
- }
2442
- if (this.propsPersistance && persist) {
2443
- this.propsPersistance.save(this.permanentProperties);
2444
- }
2445
- };
2446
- UsermavenClientImpl.prototype.unset = function (propertyName, opts) {
2447
- requireWindow();
2448
- var eventType = opts === null || opts === void 0 ? void 0 : opts.eventType;
2449
- var persist = (opts === null || opts === void 0 ? void 0 : opts.persist) === undefined || (opts === null || opts === void 0 ? void 0 : opts.persist);
2450
- if (!eventType) {
2451
- delete this.permanentProperties.globalProps[propertyName];
2452
- }
2453
- else if (this.permanentProperties.propsPerEvent[eventType]) {
2454
- delete this.permanentProperties.propsPerEvent[eventType][propertyName];
2455
- }
2456
- if (this.propsPersistance && persist) {
2457
- this.propsPersistance.save(this.permanentProperties);
2458
- }
2459
- };
2460
- UsermavenClientImpl.prototype.manageCrossDomainLinking = function (options) {
2461
- if (!isWindowAvailable() || !options.cross_domain_linking || options.domains.length === 0 || options.cookiePolicy === "strict") {
2462
- return false;
2463
- }
2464
- var cookieName = this.idCookieName;
2465
- var domains = options.domains || [];
2466
- // Listen for all clicks on the page
2467
- document.addEventListener('click', function (event) {
2468
- // Find the closest link
2469
- var target = _findClosestLink(event.target);
2470
- if (target) {
2471
- // Check if the link is pointing to a different domain
2472
- var href = (target === null || target === void 0 ? void 0 : target.hasAttribute('href')) ? target === null || target === void 0 ? void 0 : target.getAttribute('href') : '';
2473
- if (href && href.startsWith('http')) {
2474
- var url = new URL(href);
2475
- var cookie = getCookie(cookieName);
2476
- // Skip the link if it's pointing to the current domain
2477
- if (url.hostname === window.location.hostname) {
2478
- return;
2479
- }
2480
- if (domains.includes(url.hostname) && cookie) {
2481
- // Add the '_um' parameter to the URL
2482
- url.searchParams.append('_um', cookie);
2483
- target.setAttribute('href', url.toString());
2484
- }
2485
- }
2486
- }
2487
- }, false);
2488
- };
2489
- /**
2490
- * Manage auto-capturing
2491
- * @param options
2492
- */
2493
- UsermavenClientImpl.prototype.manageAutoCapture = function (options) {
2494
- getLogger().debug("Auto Capture Status: ", this.config['autocapture']);
2495
- this.__autocapture_enabled = this.config['autocapture'] && isWindowAvailable();
2496
- if (!this.__autocapture_enabled) {
2497
- return;
2498
- }
2499
- var num_buckets = 100;
2500
- var num_enabled_buckets = 100;
2501
- if (!autocapture.enabledForProject(this.apiKey, num_buckets, num_enabled_buckets)) {
2502
- this.config['autocapture'] = false;
2503
- this.__autocapture_enabled = false;
2504
- getLogger().debug('Not in active bucket: disabling Automatic Event Collection.');
2505
- }
2506
- else if (!autocapture.isBrowserSupported()) {
2507
- this.config['autocapture'] = false;
2508
- this.__autocapture_enabled = false;
2509
- getLogger().debug('Disabling Automatic Event Collection because this browser is not supported');
2510
- }
2511
- else {
2512
- getLogger().debug('Autocapture enabled...');
2513
- autocapture.init(this, options);
2514
- }
2515
- };
2516
- /**
2517
- * Manage form tracking
2518
- */
2519
- UsermavenClientImpl.prototype.manageFormTracking = function (options) {
2520
- if (!isWindowAvailable() || !this.formTracking || this.formTracking === "none") {
2521
- return;
2522
- }
2523
- getLogger().debug('Form tracking enabled...');
2524
- // all and true are the same
2525
- var trackingType = this.formTracking === true ? 'all' : this.formTracking;
2526
- FormTracking.getInstance(this, trackingType).track();
2527
- };
2528
- /**
2529
- * Capture an event. This is the most important and
2530
- * frequently used usermaven function.
2531
- *
2532
- * ### Usage:
2533
- * usermaven.capture('Registered', {'Gender': 'Male', 'Age': 21}, {});
2534
- *
2535
- * @param {String} event_name The name of the event. This can be anything the user does - 'Button Click', 'Sign Up', 'Item Purchased', etc.
2536
- * @param {Object} [properties] A set of properties to include with the event you're sending. These describe the user who did the event or details about the event itself.
2537
- * @param {Object} [options] Optional configuration for this capture request.
2538
- * @param {String} [options.transport] Transport method for network request ('XHR' or 'sendBeacon').
2539
- */
2540
- UsermavenClientImpl.prototype.capture = function (event_name, properties) {
2541
- var _a, _b;
2542
- if (properties === void 0) { properties = {}; }
2543
- if (!this.initialized) {
2544
- console.error('Trying to capture event before initialization');
2545
- return;
2546
- }
2547
- if (_isUndefined(event_name) || typeof event_name !== 'string') {
2548
- console.error('No event name provided to usermaven.capture');
2549
- return;
2550
- }
2551
- // if (_.isBlockedUA(userAgent)) {
2552
- // return
2553
- // }
2554
- var data = {
2555
- event: event_name + (properties['$event_type'] ? '_' + properties['$event_type'] : ''),
2556
- properties: this._calculate_event_properties(event_name, properties),
2557
- };
2558
- data = _copyAndTruncateStrings(data, this.get_config('properties_string_max_length'));
2559
- // send event if there is a tagname available
2560
- if ((_b = (_a = data.properties) === null || _a === void 0 ? void 0 : _a.autocapture_attributes) === null || _b === void 0 ? void 0 : _b.tag_name) {
2561
- this.track("$autocapture", data.properties);
2562
- // this.track(data.event, data.properties)
2563
- }
2564
- // send event if the event is $scroll
2565
- if (event_name === '$scroll') {
2566
- this.track(event_name, data.properties);
2567
- }
2568
- // send event if the event is $form
2569
- if (event_name === '$form') {
2570
- this.track(event_name, data.properties);
2571
- }
2572
- };
2573
- UsermavenClientImpl.prototype._calculate_event_properties = function (event_name, event_properties) {
2574
- var _a, _b;
2575
- // set defaults
2576
- var properties = event_properties || {};
2577
- if (event_name === '$snapshot' || event_name === '$scroll' || event_name === '$form') {
2578
- return properties;
2579
- }
2580
- if (_isArray(this.propertyBlacklist)) {
2581
- _each(this.propertyBlacklist, function (blacklisted_prop) {
2582
- delete properties[blacklisted_prop];
2583
- });
2584
- }
2585
- else {
2586
- console.error('Invalid value for property_blacklist config: ' + this.propertyBlacklist);
2587
- }
2588
- // assign first element from $elements only
2589
- var attributes = {};
2590
- var elements = properties['$elements'] || [];
2591
- if (elements.length) {
2592
- attributes = elements[0];
2593
- }
2594
- properties['autocapture_attributes'] = attributes;
2595
- properties['autocapture_attributes']["el_text"] = (_a = properties['autocapture_attributes']["$el_text"]) !== null && _a !== void 0 ? _a : "";
2596
- properties['autocapture_attributes']["event_type"] = (_b = properties["$event_type"]) !== null && _b !== void 0 ? _b : "";
2597
- ['$ce_version', "$event_type", "$initial_referrer", "$initial_referring_domain", "$referrer", "$referring_domain", "$elements"].forEach(function (key) {
2598
- delete properties[key];
2599
- });
2600
- // TODO: later remove this from the autotrack code.
2601
- delete properties['autocapture_attributes']["$el_text"];
2602
- delete properties['autocapture_attributes']["nth_child"];
2603
- delete properties['autocapture_attributes']["nth_of_type"];
2604
- return properties;
2605
- };
2606
- return UsermavenClientImpl;
2607
- }());
2608
- function enableAutoPageviews(t) {
2609
- var page = function () { return t.track("pageview"); };
2610
- // Attach pushState and popState listeners
2611
- var originalPushState = history.pushState;
2612
- if (originalPushState) {
2613
- // eslint-disable-next-line functional/immutable-data
2614
- history.pushState = function (data, title, url) {
2615
- originalPushState.apply(this, [data, title, url]);
2616
- page();
2617
- };
2618
- addEventListener('popstate', page);
1084
+ }
1085
+ rawTrack(e) {
1086
+ if (!k(e))
1087
+ throw new Error("Event payload must be an object");
1088
+ this.track("raw", e);
1089
+ }
1090
+ async group(e, t = !1) {
1091
+ if (!k(e))
1092
+ throw new Error("Company properties must be an object");
1093
+ if (!e.id || !e.name || !e.created_at)
1094
+ throw new Error("Company properties must include id, name, and created_at");
1095
+ this.persistence.set("companyProps", e), t || await this.track("group", e), this.logger.info("Company identified:", e);
1096
+ }
1097
+ createEventPayload(e, t) {
1098
+ const s = this.persistence.get("userProps") || {}, n = this.persistence.get("companyProps") || (s == null ? void 0 : s.company) || {}, r = this.persistence.get("userId"), o = this.persistence.get("global_props") || {}, c = this.persistence.get(`props_${e}`) || {};
1099
+ let l = t || {};
1100
+ const a = {
1101
+ event_id: "",
1102
+ user: {
1103
+ anonymous_id: this.anonymousId,
1104
+ id: r,
1105
+ ...s
1106
+ },
1107
+ ...n && { company: n },
1108
+ ids: this.getThirdPartyIds(),
1109
+ utc_time: (/* @__PURE__ */ new Date()).toISOString(),
1110
+ local_tz_offset: (/* @__PURE__ */ new Date()).getTimezoneOffset(),
1111
+ api_key: this.config.key,
1112
+ src: "usermaven",
1113
+ event_type: e,
1114
+ namespace: this.namespace,
1115
+ ...o,
1116
+ ...c
1117
+ };
1118
+ if (e === "$autocapture") {
1119
+ const h = this.processAutocaptureAttributes(t || {});
1120
+ a.autocapture_attributes = h;
1121
+ } else e !== "user_identify" && e !== "group" && (Array.isArray(this.config.propertyBlacklist) && this.config.propertyBlacklist.forEach((h) => {
1122
+ delete l[h];
1123
+ }), a.event_attributes = l);
1124
+ return u() && (a.referer = document.referrer, a.url = window.location.href, a.page_title = document.title, a.doc_path = window.location.pathname, a.doc_host = window.location.hostname, a.doc_search = window.location.search, a.screen_resolution = `${window.screen.width}x${window.screen.height}`, a.vp_size = `${window.innerWidth}x${window.innerHeight}`, a.user_agent = navigator.userAgent, a.user_language = navigator.language, a.doc_encoding = document.characterSet, a.utm = this.getUtmParams()), a;
1125
+ }
1126
+ processAutocaptureAttributes(e) {
1127
+ let t = {};
1128
+ const s = e.$elements || [];
1129
+ return s.length && (t = { ...s[0] }), t.el_text = t.$el_text || "", t.event_type = e.$event_type || "", ["$ce_version", "$event_type", "$initial_referrer", "$initial_referring_domain", "$referrer", "$referring_domain", "$elements"].forEach((n) => {
1130
+ delete t[n];
1131
+ }), delete t.$el_text, delete t.nth_child, delete t.nth_of_type, t;
1132
+ }
1133
+ getCookie(e) {
1134
+ var t;
1135
+ return ((t = this.cookieManager) == null ? void 0 : t.get(e)) || null;
1136
+ }
1137
+ getThirdPartyIds() {
1138
+ const e = {};
1139
+ if (u()) {
1140
+ const t = this.getCookie("_fbp");
1141
+ t && (e.fbp = t);
2619
1142
  }
2620
- addEventListener('hashchange', page);
1143
+ return e;
1144
+ }
1145
+ getUtmParams() {
1146
+ const e = {}, t = le(window.location.search);
1147
+ return ["utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content"].forEach((n) => {
1148
+ t[n] && (e[n.replace("utm_", "")] = t[n]);
1149
+ }), e;
1150
+ }
1151
+ pageview() {
1152
+ u() ? this.track("pageview", {
1153
+ url: window.location.href,
1154
+ referrer: document.referrer,
1155
+ title: document.title
1156
+ }, !0) : this.logger.warn("Pageview tracking is not available in server-side environments");
1157
+ }
1158
+ setupPageLeaveTracking() {
1159
+ if (!u()) return;
1160
+ let e = !1, t = !1;
1161
+ const s = () => {
1162
+ !e && !t && (e = !0, this.track("$pageleave", {
1163
+ url: window.location.href,
1164
+ referrer: document.referrer,
1165
+ title: document.title
1166
+ }));
1167
+ };
1168
+ window.addEventListener("beforeunload", (r) => {
1169
+ t = !0, setTimeout(() => {
1170
+ t = !1;
1171
+ }, 100);
1172
+ }), document.addEventListener("visibilitychange", () => {
1173
+ document.visibilityState === "hidden" && !t && s();
1174
+ });
1175
+ const n = history.pushState;
1176
+ history.pushState = function() {
1177
+ return s(), n.apply(this, arguments);
1178
+ }, window.addEventListener("popstate", s);
1179
+ }
1180
+ getConfig() {
1181
+ return this.config;
1182
+ }
1183
+ getLogger() {
1184
+ return this.logger;
1185
+ }
1186
+ async reset(e = !1) {
1187
+ if (this.persistence.clear(), e && this.cookieManager) {
1188
+ const t = this.config.cookieName || `__eventn_id_${this.config.key}`;
1189
+ this.cookieManager.delete(t), this.anonymousId = this.getOrCreateAnonymousId();
1190
+ }
1191
+ this.logger.info("core state reset", { resetAnonId: e, namespace: this.namespace });
1192
+ }
1193
+ set(e, t) {
1194
+ if (!k(e))
1195
+ throw new Error("Properties must be an object");
1196
+ const s = t == null ? void 0 : t.eventType, n = (t == null ? void 0 : t.persist) ?? !0;
1197
+ if (s) {
1198
+ let r = this.persistence.get(`props_${s}`) || {};
1199
+ r = { ...r, ...e }, this.persistence.set(`props_${s}`, r);
1200
+ } else {
1201
+ let r = this.persistence.get("global_props") || {};
1202
+ r = { ...r, ...e }, this.persistence.set("global_props", r);
1203
+ }
1204
+ n && this.persistence.save(), this.logger.debug("Properties set", {
1205
+ properties: e,
1206
+ eventType: s || "global",
1207
+ persist: n
1208
+ });
1209
+ }
1210
+ setUserId(e) {
1211
+ this.persistence.set("userId", e);
1212
+ let t = this.persistence.get("userProps") || {};
1213
+ t.id = e, this.persistence.set("userProps", t), this.persistence.save();
1214
+ }
1215
+ unset(e, t) {
1216
+ const s = t == null ? void 0 : t.eventType, n = (t == null ? void 0 : t.persist) ?? !0;
1217
+ if (s) {
1218
+ let r = this.persistence.get(`props_${s}`) || {};
1219
+ delete r[e], this.persistence.set(`props_${s}`, r);
1220
+ } else {
1221
+ let r = this.persistence.get("global_props") || {};
1222
+ delete r[e], this.persistence.set("global_props", r);
1223
+ }
1224
+ n && this.persistence.save(), this.logger.debug(`Property unset: ${e}`, `Event type: ${s || "global"}`);
1225
+ }
1226
+ }
1227
+ function ke(i) {
1228
+ const e = JSON.parse(JSON.stringify(i)), t = H(e), s = { ...U, ...t };
1229
+ if (!s.key)
1230
+ throw new Error("API key is required!");
1231
+ if (!s.trackingHost)
1232
+ throw new Error("Tracking host is required!");
1233
+ return new we(s);
2621
1234
  }
2622
- function interceptSegmentCalls(t) {
2623
- var win = window;
2624
- if (!win.analytics) {
2625
- win.analytics = [];
1235
+ function ve(i) {
1236
+ var n;
1237
+ const e = {
1238
+ key: i.getAttribute("data-key") || void 0,
1239
+ trackingHost: i.getAttribute("data-tracking-host") || "https://events.usermaven.com",
1240
+ logLevel: ue(i.getAttribute("data-log-level")),
1241
+ autocapture: i.getAttribute("data-autocapture") === "true",
1242
+ formTracking: i.getAttribute("data-form-tracking") === "false" ? !1 : i.getAttribute("data-form-tracking") === "true" ? "all" : i.getAttribute("data-form-tracking"),
1243
+ autoPageview: i.getAttribute("data-auto-pageview") === "true",
1244
+ useBeaconApi: i.getAttribute("data-use-beacon-api") === "true",
1245
+ forceUseFetch: i.getAttribute("data-force-use-fetch") === "true",
1246
+ gaHook: i.getAttribute("data-ga-hook") === "true",
1247
+ segmentHook: i.getAttribute("data-segment-hook") === "true",
1248
+ randomizeUrl: i.getAttribute("data-randomize-url") === "true",
1249
+ capture3rdPartyCookies: i.getAttribute("data-capture-3rd-party-cookies") === "false" ? !1 : void 0,
1250
+ idMethod: i.getAttribute("data-id-method") || void 0,
1251
+ privacyPolicy: i.getAttribute("data-privacy-policy") === "strict" ? "strict" : void 0,
1252
+ ipPolicy: i.getAttribute("data-ip-policy") || void 0,
1253
+ cookiePolicy: i.getAttribute("data-cookie-policy") || void 0,
1254
+ minSendTimeout: parseInt(i.getAttribute("data-min-send-timeout") || "", 10) || void 0,
1255
+ maxSendTimeout: parseInt(i.getAttribute("data-max-send-timeout") || "", 10) || void 0,
1256
+ maxSendAttempts: parseInt(i.getAttribute("data-max-send-attempts") || "", 10) || void 0,
1257
+ propertiesStringMaxLength: parseInt(i.getAttribute("data-properties-string-max-length") || "", 10) || null,
1258
+ propertyBlacklist: ((n = i.getAttribute("data-property-blacklist")) == null ? void 0 : n.split(",")) || void 0,
1259
+ exclude: i.getAttribute("data-exclude") || void 0,
1260
+ namespace: i.getAttribute("data-namespace") || void 0,
1261
+ crossDomainLinking: i.getAttribute("data-cross-domain-linking") !== "false",
1262
+ domains: i.getAttribute("data-domains") || void 0,
1263
+ maskAllText: i.getAttribute("data-mask-all-text") === "true",
1264
+ maskAllElementAttributes: i.getAttribute("data-mask-all-element-attributes") === "true"
1265
+ }, t = ke(e), s = e.namespace || "usermaven";
1266
+ u() && t.pageview(), _e(s, t);
1267
+ }
1268
+ function _e(i, e) {
1269
+ let t = !1;
1270
+ const s = [], n = [];
1271
+ function r() {
1272
+ for (; s.length > 0; ) {
1273
+ const a = s.shift();
1274
+ a && window[i].apply(null, a);
2626
1275
  }
2627
- t.interceptAnalytics(win.analytics);
1276
+ }
1277
+ function o() {
1278
+ n.forEach((a) => a()), n.length = 0;
1279
+ }
1280
+ window[i] = function(...a) {
1281
+ const h = a[0];
1282
+ if (h === "onLoad") {
1283
+ typeof a[1] == "function" && (t ? a[1]() : n.push(a[1]));
1284
+ return;
1285
+ }
1286
+ if (!t) {
1287
+ s.push(a);
1288
+ return;
1289
+ }
1290
+ if (typeof e[h] == "function")
1291
+ return e[h].apply(e, a.slice(1));
1292
+ console.error(`Method ${h} not found on UsermavenClient`);
1293
+ };
1294
+ const c = `${i}Q`, l = window[c] || [];
1295
+ for (window[c] = l, l.push = function(...a) {
1296
+ return window[i].apply(null, a), Array.prototype.push.apply(this, a);
1297
+ }, setTimeout(() => {
1298
+ t = !0, r(), o(), console.log(`Usermaven client for namespace ${i} is ready`);
1299
+ }, 0); l.length > 0; ) {
1300
+ const a = l.shift();
1301
+ a && s.push(a);
1302
+ }
2628
1303
  }
1304
+ u() && function(i, e) {
1305
+ const t = i.currentScript;
1306
+ function s() {
1307
+ t && t.src.includes("lib.js") && ve(t);
1308
+ }
1309
+ typeof e < "u" && (i.readyState === "loading" ? i.addEventListener("DOMContentLoaded", s) : s());
1310
+ }(document, window);
2629
1311
 
2630
1312
  function createClient(params) {
2631
- return usermavenClient(params);
1313
+ return ke(params);
2632
1314
  }
2633
1315
 
2634
1316
  function useUsermaven() {
2635
1317
  const client = useContext(UsermavenContext);
2636
1318
  if (!client) {
2637
- throw new Error("Before calling useUsermaven() hook, please wrap your component into <JitsuProvider />. Read more in https://usermaven.com/docs/integrations/next");
1319
+ throw new Error("Before calling useUsermaven() hook, please wrap your component into <UsermavenProvider />. Read more in http://jitsu.com/docs/sending-data/js-sdk/react");
2638
1320
  }
2639
1321
  const id = useCallback((userData, doNotSendEvent) => client === null || client === void 0 ? void 0 : client.id(userData, doNotSendEvent), [client]);
2640
1322
  const trackPageView = useCallback(() => client === null || client === void 0 ? void 0 : client.track('pageview'), [client]);
2641
1323
  const track = useCallback((typeName, payload) => client === null || client === void 0 ? void 0 : client.track(typeName, payload), [client]);
2642
1324
  const rawTrack = useCallback((payload) => client === null || client === void 0 ? void 0 : client.rawTrack(payload), [client]);
2643
- const interceptAnalytics = useCallback((analytics) => client === null || client === void 0 ? void 0 : client.interceptAnalytics(analytics), [client]);
1325
+ const set = useCallback((properties, opts) => client === null || client === void 0 ? void 0 : client.set(properties, opts), [client]);
1326
+ const unset = useCallback((propertyName, opts) => client === null || client === void 0 ? void 0 : client.unset(propertyName, opts), [client]);
2644
1327
  return Object.assign(Object.assign({}, client), { id,
2645
1328
  track,
2646
1329
  trackPageView,
2647
1330
  rawTrack,
2648
- interceptAnalytics });
1331
+ set,
1332
+ unset });
2649
1333
  }
2650
1334
 
2651
- function usePageView(usermaven, opts = {}) {
2652
- const router = useRouter();
1335
+ function useUrlChange() {
1336
+ const [url, setUrl] = useState('');
2653
1337
  useEffect(() => {
2654
- const handleRouteChange = () => {
2655
- if (opts.before) {
2656
- opts.before(usermaven);
2657
- }
2658
- usermaven.track((opts === null || opts === void 0 ? void 0 : opts.typeName) || 'pageview', opts.payload);
1338
+ setUrl(window.location.href);
1339
+ const handleUrlChange = () => {
1340
+ setUrl(window.location.href);
1341
+ };
1342
+ window.addEventListener('popstate', handleUrlChange);
1343
+ const originalPushState = window.history.pushState;
1344
+ const originalReplaceState = window.history.replaceState;
1345
+ window.history.pushState = function () {
1346
+ originalPushState.apply(this, arguments);
1347
+ handleUrlChange();
1348
+ };
1349
+ window.history.replaceState = function () {
1350
+ originalReplaceState.apply(this, arguments);
1351
+ handleUrlChange();
2659
1352
  };
2660
- handleRouteChange();
2661
- router.events.on('routeChangeComplete', handleRouteChange);
2662
1353
  return () => {
2663
- router.events.off('routeChangeComplete', handleRouteChange);
1354
+ window.removeEventListener('popstate', handleUrlChange);
1355
+ window.history.pushState = originalPushState;
1356
+ window.history.replaceState = originalReplaceState;
2664
1357
  };
2665
- }, [router.events, usermaven.track, opts.payload, opts.before]);
1358
+ }, []);
1359
+ return url;
1360
+ }
1361
+ function usePageView(usermaven, opts = {}) {
1362
+ const url = useUrlChange();
1363
+ const trackPageView = useCallback(() => {
1364
+ if (typeof window === 'undefined') {
1365
+ return;
1366
+ }
1367
+ if (opts.before) {
1368
+ opts.before(usermaven);
1369
+ }
1370
+ usermaven.track((opts === null || opts === void 0 ? void 0 : opts.typeName) || 'pageview', Object.assign(Object.assign({}, opts.payload), { url: window.location.href, path: window.location.pathname, referrer: document.referrer, title: document.title }));
1371
+ }, [usermaven, opts.before, opts.typeName, opts.payload]);
1372
+ useEffect(() => {
1373
+ if (url) {
1374
+ trackPageView();
1375
+ }
1376
+ }, [url, trackPageView]);
2666
1377
  return usermaven;
2667
1378
  }
2668
1379
 
@@ -2887,4 +1598,4 @@ function middlewareEnv(req, res, opts = {}) {
2887
1598
  };
2888
1599
  }
2889
1600
 
2890
- export { UsermavenContext, JitsuProvider as UsermavenProvider, createClient, middlewareEnv, usePageView, useUsermaven };
1601
+ export { UsermavenContext, UsermavenProvider, createClient, middlewareEnv, usePageView, useUsermaven };