@levo-so/insights 0.3.10 → 0.3.12
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/dist/constants/storageKeys.d.ts +22 -17
- package/dist/index.d.ts +2 -0
- package/dist/index.js +181 -379
- package/dist/lib/identityHeaders.d.ts +22 -0
- package/dist/lib/insights.d.ts +2 -1
- package/dist/lib/rotation.d.ts +42 -0
- package/dist/lib/transport.d.ts +45 -0
- package/dist/stores/events.d.ts +12 -17
- package/dist/stores/identity.d.ts +111 -0
- package/dist/stores/readiness.d.ts +6 -6
- package/dist/stores/session.d.ts +12 -21
- package/dist/stores/sessionProperties.d.ts +116 -0
- package/dist/stores.d.ts +1 -0
- package/dist/stores.js +2 -2
- package/dist/textSelection-CXG4e3wj.js +948 -0
- package/dist/types/endpoint.d.ts +38 -0
- package/dist/types/identity.d.ts +0 -1
- package/dist/utils/cookies.d.ts +23 -0
- package/dist/utils/detectMode.d.ts +20 -7
- package/dist/utils/getAsyncUserProperties.d.ts +6 -0
- package/dist/utils/getAuthHeaders.d.ts +17 -4
- package/dist/utils/getUserProperties.d.ts +28 -3
- package/dist/utils/sanitizeEvent.d.ts +51 -0
- package/package.json +9 -6
- package/dist/textSelection-Cwq6lqKg.js +0 -604
- package/dist/utils/pingEndpoint.d.ts +0 -4
package/dist/index.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { A as e,
|
|
2
|
-
import {
|
|
3
|
-
import { getVisitorSource as
|
|
4
|
-
import
|
|
5
|
-
import { Analytics as
|
|
1
|
+
import { A as e, B as t, C as n, D as r, E as i, F as a, G as o, H as s, I as c, K as l, L as u, M as d, N as f, O as p, P as m, R as h, T as g, U as _, V as v, W as y, _ as b, c as x, d as S, g as C, h as ee, i as w, j as te, l as ne, n as re, o as ie, p as ae, q as T, s as E, u as D, v as O, w as k, y as A } from "./textSelection-CXG4e3wj.js";
|
|
2
|
+
import { getLevoError as j } from "@levo-so/core";
|
|
3
|
+
import { getVisitorSource as M } from "@analytics/visitor-source";
|
|
4
|
+
import N from "get-user-locale";
|
|
5
|
+
import { Analytics as P } from "analytics";
|
|
6
6
|
//#region src/utils/rageclick.ts
|
|
7
|
-
var
|
|
8
|
-
let r =
|
|
9
|
-
if (r && Math.abs(e - r.x) + Math.abs(t - r.y) <
|
|
10
|
-
if (
|
|
7
|
+
var F = 30, I = 1e3, L = 3, R = [], z = (e, t, n) => {
|
|
8
|
+
let r = R[R.length - 1];
|
|
9
|
+
if (r && Math.abs(e - r.x) + Math.abs(t - r.y) < F && n - r.timestamp < I) {
|
|
10
|
+
if (R.push({
|
|
11
11
|
x: e,
|
|
12
12
|
y: t,
|
|
13
13
|
timestamp: n
|
|
14
|
-
}),
|
|
15
|
-
} else
|
|
14
|
+
}), R.length >= L) return R = [], !0;
|
|
15
|
+
} else R = [{
|
|
16
16
|
x: e,
|
|
17
17
|
y: t,
|
|
18
18
|
timestamp: n
|
|
19
19
|
}];
|
|
20
20
|
return !1;
|
|
21
|
-
},
|
|
21
|
+
}, B = (e) => {
|
|
22
22
|
let t = e, n = 0;
|
|
23
23
|
for (; t && n < 10;) {
|
|
24
24
|
let e = t.getAttribute?.("href");
|
|
@@ -26,43 +26,44 @@ var M = 30, N = 1e3, P = 3, F = [], I = (e, t, n) => {
|
|
|
26
26
|
t = t.parentElement, n++;
|
|
27
27
|
}
|
|
28
28
|
return null;
|
|
29
|
-
},
|
|
30
|
-
let t = e.closest("a[href]"), n = t?.getAttribute("href") ||
|
|
29
|
+
}, V = 2048, H = (e) => {
|
|
30
|
+
let t = e.closest("a[href]"), n = t?.getAttribute("href") || B(e);
|
|
31
31
|
if (!n) return {
|
|
32
32
|
type: null,
|
|
33
33
|
href: null
|
|
34
34
|
};
|
|
35
|
+
let r = n.length > V ? n.slice(0, V) : n;
|
|
35
36
|
if (t?.hasAttribute("download")) return {
|
|
36
37
|
type: "download",
|
|
37
|
-
href:
|
|
38
|
+
href: r
|
|
38
39
|
};
|
|
39
|
-
if (
|
|
40
|
+
if (r.startsWith("tel:")) return {
|
|
40
41
|
type: "tel",
|
|
41
|
-
href:
|
|
42
|
+
href: r
|
|
42
43
|
};
|
|
43
|
-
if (
|
|
44
|
+
if (r.startsWith("mailto:")) return {
|
|
44
45
|
type: "mailto",
|
|
45
|
-
href:
|
|
46
|
+
href: r
|
|
46
47
|
};
|
|
47
|
-
if (
|
|
48
|
+
if (r.startsWith("#")) return {
|
|
48
49
|
type: "anchor",
|
|
49
|
-
href:
|
|
50
|
+
href: r
|
|
50
51
|
};
|
|
51
52
|
try {
|
|
52
53
|
return {
|
|
53
|
-
type: new URL(
|
|
54
|
-
href:
|
|
54
|
+
type: new URL(r, window.location.origin).origin === window.location.origin ? "internal" : "external",
|
|
55
|
+
href: r
|
|
55
56
|
};
|
|
56
57
|
} catch (e) {
|
|
57
|
-
return console.warn("[insights] Failed to classify link",
|
|
58
|
+
return console.warn("[insights] Failed to classify link", j(e)), {
|
|
58
59
|
type: "internal",
|
|
59
|
-
href:
|
|
60
|
+
href: r
|
|
60
61
|
};
|
|
61
62
|
}
|
|
62
|
-
},
|
|
63
|
+
}, U = (e) => {
|
|
63
64
|
if (typeof window > "u") return () => {};
|
|
64
65
|
let t = 0, n = null, r = (e, t = !1, n) => {
|
|
65
|
-
let r = n ??
|
|
66
|
+
let r = n ?? D(e), i = "clientX" in e ? e.clientX : e.changedTouches?.[0]?.clientX ?? 0, a = "clientY" in e ? e.clientY : e.changedTouches?.[0]?.clientY ?? 0, o = {
|
|
66
67
|
hostname: window.location.hostname,
|
|
67
68
|
pathname: window.location.pathname,
|
|
68
69
|
page_title: document.title,
|
|
@@ -71,9 +72,9 @@ var M = 30, N = 1e3, P = 3, F = [], I = (e, t, n) => {
|
|
|
71
72
|
event_type: t ? "dblclick" : "click",
|
|
72
73
|
button_type: "button" in e ? e.button : 0
|
|
73
74
|
};
|
|
74
|
-
return r instanceof HTMLElement && (o.rage_click =
|
|
75
|
+
return r instanceof HTMLElement && (o.rage_click = z(i, a, Date.now()), o = {
|
|
75
76
|
...o,
|
|
76
|
-
...
|
|
77
|
+
...ne(r)
|
|
77
78
|
}), o;
|
|
78
79
|
}, i = (n, i, a) => {
|
|
79
80
|
try {
|
|
@@ -84,27 +85,27 @@ var M = 30, N = 1e3, P = 3, F = [], I = (e, t, n) => {
|
|
|
84
85
|
href: i.href || void 0,
|
|
85
86
|
link_type: i.type,
|
|
86
87
|
is_navigation: !0
|
|
87
|
-
});
|
|
88
|
+
}, {}, () => k());
|
|
88
89
|
} catch (e) {
|
|
89
|
-
console.error("[insights] Failed to track navigation click",
|
|
90
|
+
console.error("[insights] Failed to track navigation click", j(e));
|
|
90
91
|
}
|
|
91
92
|
}, a = (n, i = !1, a) => {
|
|
92
93
|
try {
|
|
93
|
-
let o = a ??
|
|
94
|
+
let o = a ?? D(n);
|
|
94
95
|
if (!o || Date.now() - t < 300) return;
|
|
95
|
-
let s = r(n, i, o), c =
|
|
96
|
+
let s = r(n, i, o), c = H(o);
|
|
96
97
|
e.track("page.click", {
|
|
97
98
|
...s,
|
|
98
99
|
href: c.href || void 0,
|
|
99
100
|
link_type: c.type || void 0
|
|
100
101
|
});
|
|
101
102
|
} catch (e) {
|
|
102
|
-
console.error("[insights] Failed to track click",
|
|
103
|
+
console.error("[insights] Failed to track click", j(e));
|
|
103
104
|
}
|
|
104
105
|
}, o = (e) => {
|
|
105
|
-
let t =
|
|
106
|
+
let t = D(e);
|
|
106
107
|
if (!t) return;
|
|
107
|
-
let r =
|
|
108
|
+
let r = H(t);
|
|
108
109
|
if (r.type === "external" || r.type === "download") {
|
|
109
110
|
i(e, r, t);
|
|
110
111
|
return;
|
|
@@ -117,13 +118,13 @@ var M = 30, N = 1e3, P = 3, F = [], I = (e, t, n) => {
|
|
|
117
118
|
a(e, !1, t), n = null;
|
|
118
119
|
}, 250);
|
|
119
120
|
}, s = (e) => {
|
|
120
|
-
n &&= (clearTimeout(n), null), a(e, !0,
|
|
121
|
+
n &&= (clearTimeout(n), null), a(e, !0, D(e) ?? void 0);
|
|
121
122
|
}, c = (n) => {
|
|
122
123
|
try {
|
|
123
|
-
let i =
|
|
124
|
+
let i = D(n);
|
|
124
125
|
if (!i) return;
|
|
125
126
|
t = Date.now();
|
|
126
|
-
let a =
|
|
127
|
+
let a = H(i);
|
|
127
128
|
if (a.type === "external" || a.type === "download") {
|
|
128
129
|
let t = r(n, !1, i);
|
|
129
130
|
e.track("page.click", {
|
|
@@ -143,54 +144,54 @@ var M = 30, N = 1e3, P = 3, F = [], I = (e, t, n) => {
|
|
|
143
144
|
is_touch: !0
|
|
144
145
|
});
|
|
145
146
|
} catch (e) {
|
|
146
|
-
console.error("[insights] Failed to track touch",
|
|
147
|
+
console.error("[insights] Failed to track touch", j(e));
|
|
147
148
|
}
|
|
148
149
|
};
|
|
149
150
|
return document.addEventListener("click", o), document.addEventListener("dblclick", s), document.addEventListener("touchend", c, { passive: !0 }), () => {
|
|
150
151
|
document.removeEventListener("click", o), document.removeEventListener("dblclick", s), document.removeEventListener("touchend", c), n && clearTimeout(n);
|
|
151
152
|
};
|
|
152
|
-
},
|
|
153
|
+
}, W = (e) => {
|
|
153
154
|
if (typeof window > "u") return () => {};
|
|
154
155
|
let t = (t) => (n) => {
|
|
155
156
|
try {
|
|
156
|
-
let r =
|
|
157
|
+
let r = S(n, t);
|
|
157
158
|
r && e.track("page.copy", r);
|
|
158
159
|
} catch (e) {
|
|
159
|
-
console.error(`[insights] Failed to track clipboard ${t}`,
|
|
160
|
+
console.error(`[insights] Failed to track clipboard ${t}`, j(e));
|
|
160
161
|
}
|
|
161
162
|
}, n = t("copy"), r = t("cut");
|
|
162
163
|
return document.addEventListener("copy", n, { capture: !0 }), document.addEventListener("cut", r, { capture: !0 }), () => {
|
|
163
164
|
document.removeEventListener("copy", n, { capture: !0 }), document.removeEventListener("cut", r, { capture: !0 });
|
|
164
165
|
};
|
|
165
|
-
},
|
|
166
|
+
}, G = (e) => {
|
|
166
167
|
if (typeof window > "u") return () => {};
|
|
167
168
|
let t = (t) => (n) => {
|
|
168
169
|
try {
|
|
169
|
-
let r =
|
|
170
|
+
let r = S(n, t);
|
|
170
171
|
if (r) {
|
|
171
172
|
let n = t === "submit" ? "form.submit" : "form.change";
|
|
172
173
|
e.track(n, r);
|
|
173
174
|
}
|
|
174
175
|
} catch (e) {
|
|
175
|
-
console.error(`[insights] Failed to track form ${t}`,
|
|
176
|
+
console.error(`[insights] Failed to track form ${t}`, j(e));
|
|
176
177
|
}
|
|
177
178
|
}, n = t("change"), r = t("submit");
|
|
178
179
|
return document.addEventListener("change", n, { capture: !0 }), document.addEventListener("submit", r, { capture: !0 }), () => {
|
|
179
180
|
document.removeEventListener("change", n, { capture: !0 }), document.removeEventListener("submit", r, { capture: !0 });
|
|
180
181
|
};
|
|
181
|
-
},
|
|
182
|
+
}, K = (e) => {
|
|
182
183
|
if (typeof window > "u") return () => {};
|
|
183
|
-
let { page_id: t } =
|
|
184
|
+
let { page_id: t } = y.get(), n = t || "", r = typeof window < "u" ? window.location.href : "", i = () => {
|
|
184
185
|
try {
|
|
185
186
|
e.page({ resource: "page" });
|
|
186
187
|
} catch (e) {
|
|
187
|
-
console.error("[insights] Failed to send page view",
|
|
188
|
+
console.error("[insights] Failed to send page view", j(e));
|
|
188
189
|
}
|
|
189
190
|
};
|
|
190
191
|
if (t) {
|
|
191
|
-
let e =
|
|
192
|
-
let { page_id:
|
|
193
|
-
r === "page_id" &&
|
|
192
|
+
let e = y.listen((e, t, r) => {
|
|
193
|
+
let { page_id: o } = e;
|
|
194
|
+
r === "page_id" && o && n !== o && (n = o, a(), i());
|
|
194
195
|
});
|
|
195
196
|
return () => {
|
|
196
197
|
e();
|
|
@@ -199,7 +200,7 @@ var M = 30, N = 1e3, P = 3, F = [], I = (e, t, n) => {
|
|
|
199
200
|
let e = () => {
|
|
200
201
|
if (typeof window > "u") return;
|
|
201
202
|
let e = window.location.href;
|
|
202
|
-
e !== r && (r = e, i());
|
|
203
|
+
e !== r && (r = e, a(), i());
|
|
203
204
|
};
|
|
204
205
|
window.addEventListener("popstate", e);
|
|
205
206
|
let t = window.history.pushState;
|
|
@@ -209,49 +210,32 @@ var M = 30, N = 1e3, P = 3, F = [], I = (e, t, n) => {
|
|
|
209
210
|
window.removeEventListener("popstate", e), window.history.pushState = t;
|
|
210
211
|
};
|
|
211
212
|
}
|
|
212
|
-
},
|
|
213
|
-
let n =
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
url: n || "/debug-api"
|
|
231
|
-
};
|
|
232
|
-
let o = Number.isFinite(i) && i > 0 ? i : 1e3;
|
|
233
|
-
if (t === "direct") return {
|
|
234
|
-
mode: "direct",
|
|
235
|
-
url: r ?? null
|
|
236
|
-
};
|
|
237
|
-
if (t === "proxy" || !r) return {
|
|
238
|
-
mode: "proxy",
|
|
239
|
-
url: n ?? null
|
|
240
|
-
};
|
|
241
|
-
let [s, c] = await Promise.all([n ? U(`${n}/ping`, o) : Promise.resolve(!1), r ? U(`${r}/ping`, o) : Promise.resolve(!1)]);
|
|
242
|
-
return s ? {
|
|
243
|
-
mode: "proxy",
|
|
244
|
-
url: n ?? null
|
|
245
|
-
} : c ? {
|
|
246
|
-
mode: "direct",
|
|
247
|
-
url: r
|
|
213
|
+
}, q = (e) => {
|
|
214
|
+
let { mode: t = "auto", insightsUrl: n, directInsightsUrl: r, debug: i = !1 } = e;
|
|
215
|
+
return i ? {
|
|
216
|
+
status: "proven",
|
|
217
|
+
url: n || "/debug-api",
|
|
218
|
+
mode: "proxy"
|
|
219
|
+
} : t === "direct" ? r ? {
|
|
220
|
+
status: "proven",
|
|
221
|
+
url: r,
|
|
222
|
+
mode: "direct"
|
|
223
|
+
} : { status: "none" } : t === "proxy" || !r ? n ? {
|
|
224
|
+
status: "proven",
|
|
225
|
+
url: n,
|
|
226
|
+
mode: "proxy"
|
|
227
|
+
} : { status: "none" } : n ? {
|
|
228
|
+
status: "unproven",
|
|
229
|
+
url: n,
|
|
230
|
+
fallback: r
|
|
248
231
|
} : {
|
|
249
|
-
|
|
250
|
-
url:
|
|
232
|
+
status: "proven",
|
|
233
|
+
url: r,
|
|
234
|
+
mode: "direct"
|
|
251
235
|
};
|
|
252
|
-
},
|
|
236
|
+
}, J = () => {
|
|
253
237
|
try {
|
|
254
|
-
let e = window.sessionStorage.getItem(
|
|
238
|
+
let e = window.sessionStorage.getItem(_.attribution);
|
|
255
239
|
if (!e) return;
|
|
256
240
|
let t = JSON.parse(e);
|
|
257
241
|
return {
|
|
@@ -262,25 +246,25 @@ var M = 30, N = 1e3, P = 3, F = [], I = (e, t, n) => {
|
|
|
262
246
|
} catch {
|
|
263
247
|
return;
|
|
264
248
|
}
|
|
265
|
-
},
|
|
249
|
+
}, oe = (e) => {
|
|
266
250
|
try {
|
|
267
|
-
window.sessionStorage.setItem(
|
|
251
|
+
window.sessionStorage.setItem(_.attribution, JSON.stringify(e));
|
|
268
252
|
} catch {}
|
|
269
|
-
},
|
|
253
|
+
}, se = () => {
|
|
270
254
|
if (typeof document > "u") return {
|
|
271
255
|
type: "",
|
|
272
256
|
referrer: {},
|
|
273
257
|
data: {},
|
|
274
258
|
raw: ""
|
|
275
259
|
};
|
|
276
|
-
let { type: e, referrer: t, data: n = {} } =
|
|
260
|
+
let { type: e, referrer: t, data: n = {} } = M({
|
|
277
261
|
referrer: document.referrer,
|
|
278
262
|
currentUrl: window.location.href,
|
|
279
263
|
mapper: null
|
|
280
264
|
}), r = Object.keys(n);
|
|
281
265
|
for (let e of r) n[e] && Array.isArray(n[e]) && n[e].length > 0 && (n[e] = n[e]?.[0]);
|
|
282
266
|
if (e === "internalLink") {
|
|
283
|
-
let e =
|
|
267
|
+
let e = J();
|
|
284
268
|
return e ? {
|
|
285
269
|
type: e.type,
|
|
286
270
|
referrer: e.referrer ?? {},
|
|
@@ -293,7 +277,7 @@ var M = 30, N = 1e3, P = 3, F = [], I = (e, t, n) => {
|
|
|
293
277
|
raw: document.referrer
|
|
294
278
|
};
|
|
295
279
|
}
|
|
296
|
-
return e && e !== "direct" &&
|
|
280
|
+
return e && e !== "direct" && oe({
|
|
297
281
|
type: e,
|
|
298
282
|
referrer: t,
|
|
299
283
|
data: n
|
|
@@ -303,123 +287,14 @@ var M = 30, N = 1e3, P = 3, F = [], I = (e, t, n) => {
|
|
|
303
287
|
data: n,
|
|
304
288
|
raw: document.referrer
|
|
305
289
|
};
|
|
306
|
-
},
|
|
307
|
-
let
|
|
308
|
-
function r(t) {
|
|
309
|
-
e({
|
|
310
|
-
isPrivate: t,
|
|
311
|
-
browserName: n
|
|
312
|
-
});
|
|
313
|
-
}
|
|
314
|
-
function i() {
|
|
315
|
-
let e = navigator.userAgent;
|
|
316
|
-
return e.match(/Chrome/) ? navigator.brave === void 0 ? e.match(/Edg/) ? "Edge" : e.match(/OPR/) ? "Opera" : "Chrome" : "Brave" : "Chromium";
|
|
317
|
-
}
|
|
318
|
-
function a(e) {
|
|
319
|
-
return e === eval.toString().length;
|
|
320
|
-
}
|
|
321
|
-
function o() {
|
|
322
|
-
let e = navigator.vendor;
|
|
323
|
-
return e !== void 0 && e.indexOf("Apple") === 0 && a(37);
|
|
324
|
-
}
|
|
325
|
-
function s() {
|
|
326
|
-
let e = navigator.vendor;
|
|
327
|
-
return e !== void 0 && e.indexOf("Google") === 0 && a(33);
|
|
328
|
-
}
|
|
329
|
-
function c() {
|
|
330
|
-
return document.documentElement !== void 0 && document.documentElement.style.MozAppearance !== void 0 && a(37);
|
|
331
|
-
}
|
|
332
|
-
function l() {
|
|
333
|
-
return navigator.msSaveBlob !== void 0 && a(39);
|
|
334
|
-
}
|
|
335
|
-
function u() {
|
|
336
|
-
let e = String(Math.random());
|
|
337
|
-
try {
|
|
338
|
-
let t = window.indexedDB.open(e, 1);
|
|
339
|
-
t.onupgradeneeded = (t) => {
|
|
340
|
-
let n = t.target?.result;
|
|
341
|
-
try {
|
|
342
|
-
n.createObjectStore("test", { autoIncrement: !0 }).put(new Blob()), r(!1);
|
|
343
|
-
} catch (e) {
|
|
344
|
-
let t = e;
|
|
345
|
-
return e instanceof Error && (t = e.message ?? e), r(typeof t == "string" ? /BlobURLs are not yet supported/.test(t) : !1);
|
|
346
|
-
} finally {
|
|
347
|
-
n.close(), window.indexedDB.deleteDatabase(e);
|
|
348
|
-
}
|
|
349
|
-
};
|
|
350
|
-
} catch {
|
|
351
|
-
return r(!1);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
function d() {
|
|
355
|
-
let e = window.openDatabase, t = window.localStorage;
|
|
356
|
-
try {
|
|
357
|
-
e(null, null, null, null);
|
|
358
|
-
} catch {
|
|
359
|
-
return r(!0);
|
|
360
|
-
}
|
|
361
|
-
try {
|
|
362
|
-
t.setItem("test", "1"), t.removeItem("test");
|
|
363
|
-
} catch {
|
|
364
|
-
return r(!0);
|
|
365
|
-
}
|
|
366
|
-
return r(!1);
|
|
367
|
-
}
|
|
368
|
-
function f() {
|
|
369
|
-
navigator.maxTouchPoints === void 0 ? d() : u();
|
|
370
|
-
}
|
|
371
|
-
function p() {
|
|
372
|
-
let e = window;
|
|
373
|
-
return e.performance !== void 0 && e.performance.memory !== void 0 && e.performance.memory.jsHeapSizeLimit !== void 0 ? performance.memory.jsHeapSizeLimit : 1073741824;
|
|
374
|
-
}
|
|
375
|
-
function m() {
|
|
376
|
-
navigator.webkitTemporaryStorage.queryUsageAndQuota((e, t) => {
|
|
377
|
-
r(Math.round(t / (1024 * 1024)) < Math.round(p() / (1024 * 1024)) * 2);
|
|
378
|
-
}, (e) => {
|
|
379
|
-
t(/* @__PURE__ */ Error(`detectIncognito somehow failed to query storage quota: ${e.message}`));
|
|
380
|
-
});
|
|
381
|
-
}
|
|
382
|
-
function h() {
|
|
383
|
-
let e = window.webkitRequestFileSystem;
|
|
384
|
-
e(0, 1, () => {
|
|
385
|
-
r(!1);
|
|
386
|
-
}, () => {
|
|
387
|
-
r(!0);
|
|
388
|
-
});
|
|
389
|
-
}
|
|
390
|
-
function g() {
|
|
391
|
-
self.Promise !== void 0 && self.Promise.allSettled !== void 0 ? m() : h();
|
|
392
|
-
}
|
|
393
|
-
function _() {
|
|
394
|
-
r(navigator.serviceWorker === void 0);
|
|
395
|
-
}
|
|
396
|
-
function v() {
|
|
397
|
-
r(window.indexedDB === void 0);
|
|
398
|
-
}
|
|
399
|
-
function y() {
|
|
400
|
-
o() ? (n = "Safari", f()) : s() ? (n = i(), g()) : c() ? (n = "Firefox", _()) : l() ? (n = "Internet Explorer", v()) : t(/* @__PURE__ */ Error("detectIncognito cannot determine the browser"));
|
|
401
|
-
}
|
|
402
|
-
y();
|
|
403
|
-
}), Y = () => {
|
|
404
|
-
let e = document.createElement("canvas"), t = e?.getContext("webgl") || e?.getContext("experimental-webgl");
|
|
405
|
-
if (!t) return null;
|
|
406
|
-
let n = t?.getExtension("WEBGL_debug_renderer_info");
|
|
407
|
-
return n ? t?.getParameter(n.UNMASKED_RENDERER_WEBGL) : null;
|
|
408
|
-
}, te = async () => {
|
|
409
|
-
let e = "", t = "", n = !1, r = !1, i = {};
|
|
290
|
+
}, ce = () => {
|
|
291
|
+
let e = "", t = "", n = !1, r = {};
|
|
410
292
|
if (!window) return {
|
|
411
293
|
locale: e,
|
|
412
294
|
timezone: t,
|
|
413
295
|
dark_mode: n,
|
|
414
|
-
|
|
415
|
-
properties: i
|
|
296
|
+
properties: r
|
|
416
297
|
};
|
|
417
|
-
let [a, o, s] = await Promise.allSettled([
|
|
418
|
-
J(),
|
|
419
|
-
navigator.getBattery?.() ?? Promise.reject(),
|
|
420
|
-
"mediaDevices" in navigator ? navigator.mediaDevices.enumerateDevices() : Promise.reject()
|
|
421
|
-
]);
|
|
422
|
-
a.status === "fulfilled" && (r = a.value.isPrivate);
|
|
423
298
|
try {
|
|
424
299
|
n = window.matchMedia?.("(prefers-color-scheme: dark)").matches;
|
|
425
300
|
} catch {}
|
|
@@ -427,140 +302,55 @@ var M = 30, N = 1e3, P = 3, F = [], I = (e, t, n) => {
|
|
|
427
302
|
t = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
428
303
|
} catch {}
|
|
429
304
|
try {
|
|
430
|
-
e =
|
|
305
|
+
e = N();
|
|
431
306
|
} catch {}
|
|
432
|
-
let
|
|
433
|
-
|
|
434
|
-
let e = o.value;
|
|
435
|
-
i.battery_level = Number((e?.level * 100).toFixed(0)), i.battery_charging = e?.charging, i.battery_discharging_time = e?.dischargingTime, i.battery_full_charge_capacity = e?.fullChargeCapacity, i.battery_charging_time = e?.chargingTime;
|
|
436
|
-
}
|
|
437
|
-
if (navigator && "deviceMemory" in navigator && (i.device_memory = navigator?.deviceMemory), i.touch_supported = "ontouchstart" in window || navigator?.maxTouchPoints !== void 0 && navigator?.maxTouchPoints > 0, "hardwareConcurrency" in navigator && (i.hardware_concurrency = navigator?.hardwareConcurrency), s.status === "fulfilled") {
|
|
438
|
-
let e = s.value;
|
|
439
|
-
i.camera_supported = e.some((e) => e?.kind === "videoinput"), i.microphone_supported = e.some((e) => e?.kind === "audioinput");
|
|
440
|
-
}
|
|
441
|
-
return i.gpu = Y(), {
|
|
307
|
+
let i = navigator, a = i.connection ?? i.mozConnection ?? i.webkitConnection;
|
|
308
|
+
return a && (r.network_type = a.effectiveType), r.width = window?.innerWidth, r.height = window?.innerHeight, r.pixel_ratio = window?.devicePixelRatio, screen && (r.screen_width = screen?.width, r.screen_height = screen?.height, r.color_depth = screen?.colorDepth, r.orientation = screen?.orientation?.type), navigator && "deviceMemory" in navigator && (r.device_memory = navigator?.deviceMemory), r.touch_supported = "ontouchstart" in window || navigator?.maxTouchPoints !== void 0 && navigator?.maxTouchPoints > 0, "hardwareConcurrency" in navigator && (r.hardware_concurrency = navigator?.hardwareConcurrency), {
|
|
442
309
|
locale: e,
|
|
443
310
|
timezone: t,
|
|
444
311
|
dark_mode: n,
|
|
445
|
-
|
|
446
|
-
properties: i
|
|
312
|
+
properties: r
|
|
447
313
|
};
|
|
448
|
-
},
|
|
314
|
+
}, Y = (e, t) => {
|
|
449
315
|
if (e.get()) return t(), () => {};
|
|
450
316
|
let n = e.listen((e) => {
|
|
451
317
|
e && (n(), t());
|
|
452
318
|
});
|
|
453
319
|
return n;
|
|
454
|
-
},
|
|
455
|
-
let { debug:
|
|
456
|
-
if (!
|
|
457
|
-
let
|
|
458
|
-
name:
|
|
320
|
+
}, le = (e, t, n) => {
|
|
321
|
+
let { debug: r } = o();
|
|
322
|
+
if (!e) return null;
|
|
323
|
+
let a = {
|
|
324
|
+
name: e.workspace,
|
|
459
325
|
track: ({ payload: e }) => {
|
|
460
|
-
if (!
|
|
461
|
-
let
|
|
462
|
-
|
|
326
|
+
if (!n()) return;
|
|
327
|
+
let r = e?.properties || {};
|
|
328
|
+
t(e.event, r);
|
|
463
329
|
},
|
|
464
330
|
page: ({ payload: e }) => {
|
|
465
|
-
|
|
331
|
+
n() && (i(), t("page.view", {
|
|
466
332
|
...e?.properties || {},
|
|
467
333
|
resource: "page"
|
|
468
334
|
}));
|
|
469
|
-
},
|
|
470
|
-
identify: ({ payload: n }) => {
|
|
471
|
-
if (!a()) return;
|
|
472
|
-
let { workspace: r, site_id: o, debug: s } = i(), { mode: l, isIdentified: u, isIdentifying: f, sessionToken: p, deviceToken: m, insightsBaseUrl: h, identity: g } = e(), _ = x(), y = C();
|
|
473
|
-
if (!h || !g) return;
|
|
474
|
-
let b = {
|
|
475
|
-
private_mode: n.traits?.private_mode ?? g.privateMode ?? !1,
|
|
476
|
-
dark_mode: n.traits?.dark_mode ?? g.darkMode ?? !1,
|
|
477
|
-
timezone: n.traits?.timezone ?? g.timezone ?? "",
|
|
478
|
-
locale: n.traits?.locale ?? g.locale ?? "",
|
|
479
|
-
referrer: n.traits?.referrer ?? g.referrer ?? {
|
|
480
|
-
type: "",
|
|
481
|
-
referrer: {},
|
|
482
|
-
data: {}
|
|
483
|
-
},
|
|
484
|
-
properties: {
|
|
485
|
-
...g.properties,
|
|
486
|
-
...n.traits?.properties
|
|
487
|
-
},
|
|
488
|
-
workspace_id: r ?? "",
|
|
489
|
-
site_id: o ?? void 0,
|
|
490
|
-
hostname: window.location.hostname,
|
|
491
|
-
pathname: window.location.pathname,
|
|
492
|
-
page_title: document.title,
|
|
493
|
-
url: window.location.href,
|
|
494
|
-
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
495
|
-
tab_id: _ ?? "",
|
|
496
|
-
tab_count: y ?? 0
|
|
497
|
-
};
|
|
498
|
-
if (s && console.log("[@levo-so/insights] Identification triggered:", {
|
|
499
|
-
isIdentified: u,
|
|
500
|
-
isIdentifying: f,
|
|
501
|
-
welcomeInput: b
|
|
502
|
-
}), u || f) return;
|
|
503
|
-
if (v({ isIdentifying: !0 }), s) {
|
|
504
|
-
console.log("[@levo-so/insights] Debug mode enabled. Mocking session identification."), v({
|
|
505
|
-
isIdentified: !0,
|
|
506
|
-
isIdentifying: !1,
|
|
507
|
-
sessionId: "debug-session",
|
|
508
|
-
deviceId: "debug-device"
|
|
509
|
-
}), E(d());
|
|
510
|
-
return;
|
|
511
|
-
}
|
|
512
|
-
let S = {
|
|
513
|
-
Accept: "application/json",
|
|
514
|
-
"Content-Type": "application/json",
|
|
515
|
-
...c({
|
|
516
|
-
sessionToken: p,
|
|
517
|
-
deviceToken: m,
|
|
518
|
-
mode: l
|
|
519
|
-
})
|
|
520
|
-
};
|
|
521
|
-
t.fetch.url(h, !0).url("/v1/insights/event/welcome").options({
|
|
522
|
-
keepalive: !0,
|
|
523
|
-
credentials: l === "proxy" ? "include" : "omit"
|
|
524
|
-
}).headers(S).post(b).json().then((t) => {
|
|
525
|
-
if (!a()) {
|
|
526
|
-
v({ isIdentifying: !1 });
|
|
527
|
-
return;
|
|
528
|
-
}
|
|
529
|
-
let { isIdentified: n } = e();
|
|
530
|
-
if (n) v({ isIdentifying: !1 });
|
|
531
|
-
else {
|
|
532
|
-
let e = {
|
|
533
|
-
isIdentified: !0,
|
|
534
|
-
isIdentifying: !1
|
|
535
|
-
};
|
|
536
|
-
if (t?.content?.data?.session && (e.sessionId = t?.content?.data?.session), t?.content?.data?.device && (e.deviceId = t?.content?.data?.device), l === "direct" && t?.content?.meta) {
|
|
537
|
-
let n = t.content.meta;
|
|
538
|
-
n.device_token && (e.deviceToken = n.device_token), n.session_token && (e.sessionToken = n.session_token);
|
|
539
|
-
}
|
|
540
|
-
v(e), E(d());
|
|
541
|
-
}
|
|
542
|
-
}).catch((n) => {
|
|
543
|
-
e().isIdentified || t.logger?.error("/welcome failed with error", { exception: O(n) }), v({ isIdentifying: !1 });
|
|
544
|
-
});
|
|
545
335
|
}
|
|
546
336
|
};
|
|
547
|
-
return
|
|
548
|
-
app:
|
|
549
|
-
debug: !!
|
|
550
|
-
plugins: [
|
|
337
|
+
return P({
|
|
338
|
+
app: e.workspace || "",
|
|
339
|
+
debug: !!r,
|
|
340
|
+
plugins: [a]
|
|
551
341
|
});
|
|
552
|
-
},
|
|
553
|
-
let { insightsUrl:
|
|
554
|
-
|
|
555
|
-
workspace:
|
|
556
|
-
debug:
|
|
557
|
-
site_id:
|
|
558
|
-
insightsUrl:
|
|
342
|
+
}, X = null, Z = !1, Q = [], $ = (r, i) => {
|
|
343
|
+
let { insightsUrl: a = null, debug: d = !1, site: f = null } = i;
|
|
344
|
+
l({
|
|
345
|
+
workspace: r.workspace,
|
|
346
|
+
debug: d,
|
|
347
|
+
site_id: f,
|
|
348
|
+
insightsUrl: a ?? null
|
|
559
349
|
});
|
|
560
|
-
let
|
|
350
|
+
let p = async (e, t) => {
|
|
561
351
|
if (typeof window > "u") return;
|
|
562
|
-
let { page_id: n } =
|
|
563
|
-
|
|
352
|
+
let { page_id: n } = o(), r = ie(), i = E();
|
|
353
|
+
g({
|
|
564
354
|
event: e,
|
|
565
355
|
version: t?.version || 1,
|
|
566
356
|
properties: {
|
|
@@ -572,7 +362,13 @@ var M = 30, N = 1e3, P = 3, F = [], I = (e, t, n) => {
|
|
|
572
362
|
pathname: void 0,
|
|
573
363
|
url: void 0,
|
|
574
364
|
page_title: void 0,
|
|
575
|
-
created_at: void 0
|
|
365
|
+
created_at: void 0,
|
|
366
|
+
title: void 0,
|
|
367
|
+
path: void 0,
|
|
368
|
+
hash: void 0,
|
|
369
|
+
width: void 0,
|
|
370
|
+
height: void 0,
|
|
371
|
+
referrer: void 0
|
|
576
372
|
},
|
|
577
373
|
url: t?.url ?? window.location.href,
|
|
578
374
|
page_title: t?.page_title ?? document.title,
|
|
@@ -581,75 +377,81 @@ var M = 30, N = 1e3, P = 3, F = [], I = (e, t, n) => {
|
|
|
581
377
|
created_at: t?.created_at ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
582
378
|
hostname: window.location.hostname,
|
|
583
379
|
pathname: window.location.pathname,
|
|
584
|
-
tab_id:
|
|
585
|
-
tab_count:
|
|
380
|
+
tab_id: r ?? "",
|
|
381
|
+
tab_count: i
|
|
586
382
|
});
|
|
587
|
-
},
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
t
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
data: r.data,
|
|
597
|
-
raw: r.raw ?? ""
|
|
383
|
+
}, m = (e) => {
|
|
384
|
+
let { page_id: t } = o();
|
|
385
|
+
t !== e && T("page_id", e);
|
|
386
|
+
}, _ = async () => Promise.allSettled([Promise.resolve().then(() => ce()), Promise.resolve().then(() => se())]).then(([t, n]) => {
|
|
387
|
+
let r = t.status === "fulfilled" ? t.value : null, i = n.status === "fulfilled" ? n.value : null, a = i?.type ? {
|
|
388
|
+
type: i.type,
|
|
389
|
+
referrer: i.referrer,
|
|
390
|
+
data: i.data,
|
|
391
|
+
raw: i.raw ?? ""
|
|
598
392
|
} : null;
|
|
599
393
|
v({ identity: {
|
|
600
|
-
locale:
|
|
601
|
-
timezone:
|
|
602
|
-
darkMode:
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
properties: n?.properties ?? null
|
|
394
|
+
locale: r?.locale ?? null,
|
|
395
|
+
timezone: r?.timezone ?? null,
|
|
396
|
+
darkMode: r?.dark_mode ?? null,
|
|
397
|
+
referrer: a,
|
|
398
|
+
properties: r?.properties ?? null
|
|
606
399
|
} });
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
400
|
+
let { session_id: o } = e();
|
|
401
|
+
u(o, s({
|
|
402
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
403
|
+
darkMode: r?.dark_mode ?? null,
|
|
404
|
+
landingUrl: window.location.href,
|
|
405
|
+
locale: r?.locale ?? null,
|
|
406
|
+
properties: r?.properties ?? null,
|
|
407
|
+
referrer: a,
|
|
408
|
+
timezone: r?.timezone ?? null
|
|
409
|
+
}));
|
|
410
|
+
}), y = () => {
|
|
411
|
+
if (!Z) return;
|
|
412
|
+
let e = t().endpoint, n = [i.insightsUrl, i.directInsightsUrl].filter(Boolean);
|
|
413
|
+
if (e.status === "proven" && n.includes(e.url)) return;
|
|
414
|
+
let r = q(i);
|
|
415
|
+
v({ endpoint: r }), r.status === "none" && console.warn("[@levo-so/insights] No usable insights endpoint resolved, no events will be sent.");
|
|
620
416
|
};
|
|
621
417
|
return {
|
|
622
418
|
init: (t = {}) => {
|
|
623
419
|
if (typeof window > "u") throw Error("[@levo-so/insights] init() should only be called on the client side.");
|
|
624
|
-
let { pageId:
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
t.mode === "direct" && t.isIdentified && (!t.sessionToken || !t.deviceToken) && v({ isIdentified: !1 }), O().finally(() => {
|
|
629
|
-
Q && T.set(!0);
|
|
630
|
-
});
|
|
631
|
-
})), c && $.push(X(l, () => {
|
|
632
|
-
Q && k().finally(() => {
|
|
633
|
-
Q && h.set(!0);
|
|
420
|
+
let { pageId: n } = t;
|
|
421
|
+
n && m(n), !Z && (r.NODE_ENV === "development" && !d || (Z = !0, te(), c(() => e().session_id), Q.push(Y(h, () => {
|
|
422
|
+
Z && _().finally(() => {
|
|
423
|
+
Z && O.set(!0);
|
|
634
424
|
});
|
|
635
|
-
})),
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
425
|
+
})), a && Q.push(Y(h, () => {
|
|
426
|
+
Z && (y(), C.set(!0));
|
|
427
|
+
})), Q.push(Y(b, () => {
|
|
428
|
+
if (!Z || X) return;
|
|
429
|
+
let e = le(r, p, () => X === e);
|
|
430
|
+
e && (X = e, Q.push(ee(e), ae(e), U(e), W(e), x(e), G(e), K(e), w(e), re(e)));
|
|
431
|
+
})), Q.push(Y(A, () => {
|
|
432
|
+
!Z || !X || X.page({ resource: "page" });
|
|
641
433
|
}))));
|
|
642
434
|
},
|
|
643
435
|
destroy: () => {
|
|
644
|
-
|
|
436
|
+
Z && (k(), n(), Q.forEach((e) => {
|
|
645
437
|
e();
|
|
646
|
-
}),
|
|
438
|
+
}), Q.length = 0, X = null, Z = !1, O.set(!1), C.set(!1));
|
|
647
439
|
},
|
|
648
|
-
track:
|
|
440
|
+
track: p,
|
|
649
441
|
get instance() {
|
|
650
|
-
return
|
|
442
|
+
return X;
|
|
651
443
|
}
|
|
652
444
|
};
|
|
653
|
-
}
|
|
445
|
+
}, ue = () => {
|
|
446
|
+
let { endpoint: n, deviceToken: r } = t();
|
|
447
|
+
if (n.status === "proven" && n.mode === "proxy") return {};
|
|
448
|
+
let { device_id: i, session_id: a } = e();
|
|
449
|
+
return p({
|
|
450
|
+
deviceId: i,
|
|
451
|
+
sessionId: a,
|
|
452
|
+
deviceToken: r,
|
|
453
|
+
mode: "direct"
|
|
454
|
+
});
|
|
455
|
+
}, de = (e) => (k(), d(e)), fe = () => (k(), f()), pe = (e) => (k(), m(e));
|
|
654
456
|
//#endregion
|
|
655
|
-
export {
|
|
457
|
+
export { r as AnalyticsEvents, $ as createLevoInsights, ue as getIdentityHeaders, de as identify, fe as reset, pe as rotateSession };
|