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