@levo-so/insights 0.1.85 → 0.1.105
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 +197 -212
- package/dist/lib/insights.d.ts +5 -4
- package/dist/stores/config.d.ts +5 -0
- package/dist/stores/readiness.d.ts +23 -0
- package/dist/stores/session.d.ts +8 -12
- package/dist/stores.d.ts +2 -1
- package/dist/stores.js +2 -2
- package/dist/{textSelection-DJ23SrA-.js → textSelection-eSp_MmZH.js} +147 -121
- package/dist/types/options.d.ts +6 -1
- package/dist/utils/onceTrue.d.ts +10 -0
- package/package.json +23 -23
package/dist/index.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { A as e, C as t, D as n, E as r,
|
|
2
|
-
import { AnalyticsEvents as
|
|
3
|
-
import { getVisitorSource as
|
|
4
|
-
import
|
|
5
|
-
import { Analytics as
|
|
1
|
+
import { A as e, C as t, D as n, E as r, F as i, M as a, N as o, P as s, S as c, T as l, _ as u, c as d, f, g as p, h as m, i as h, j as g, k as _, l as v, m as y, n as b, o as x, s as S, u as C, v as w, w as T } from "./textSelection-eSp_MmZH.js";
|
|
2
|
+
import { AnalyticsEvents as E, getLevoError as D } from "@levo-so/core";
|
|
3
|
+
import { getVisitorSource as O } from "@analytics/visitor-source";
|
|
4
|
+
import k from "get-user-locale";
|
|
5
|
+
import { Analytics as A } 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 j = 30, M = 1e3, N = 3, P = [], F = (e, t, n) => {
|
|
8
|
+
let r = P[P.length - 1];
|
|
9
|
+
if (r && Math.abs(e - r.x) + Math.abs(t - r.y) < j && n - r.timestamp < M) {
|
|
10
|
+
if (P.push({
|
|
11
11
|
x: e,
|
|
12
12
|
y: t,
|
|
13
13
|
timestamp: n
|
|
14
|
-
}),
|
|
15
|
-
} else
|
|
14
|
+
}), P.length >= N) return P = [], !0;
|
|
15
|
+
} else P = [{
|
|
16
16
|
x: e,
|
|
17
17
|
y: t,
|
|
18
18
|
timestamp: n
|
|
19
19
|
}];
|
|
20
20
|
return !1;
|
|
21
|
-
},
|
|
21
|
+
}, I = (e) => {
|
|
22
22
|
let t = e, n = 0;
|
|
23
23
|
for (; t && n < 10;) {
|
|
24
24
|
let e = t.getAttribute?.("href");
|
|
@@ -26,8 +26,8 @@ var k = 30, A = 1e3, j = 3, M = [], N = (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
|
+
}, L = (e) => {
|
|
30
|
+
let t = e.closest("a[href]"), n = t?.getAttribute("href") || I(e);
|
|
31
31
|
if (!n) return {
|
|
32
32
|
type: null,
|
|
33
33
|
href: null
|
|
@@ -54,15 +54,15 @@ var k = 30, A = 1e3, j = 3, M = [], N = (e, t, n) => {
|
|
|
54
54
|
href: n
|
|
55
55
|
};
|
|
56
56
|
} catch (e) {
|
|
57
|
-
return console.warn("[insights] Failed to classify link",
|
|
57
|
+
return console.warn("[insights] Failed to classify link", D(e)), {
|
|
58
58
|
type: "internal",
|
|
59
59
|
href: n
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
|
-
},
|
|
62
|
+
}, R = (e) => {
|
|
63
63
|
if (typeof window > "u") return () => {};
|
|
64
64
|
let t = 0, n = null, r = (e, t = !1, n) => {
|
|
65
|
-
let r = n ??
|
|
65
|
+
let r = n ?? v(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
66
|
hostname: window.location.hostname,
|
|
67
67
|
pathname: window.location.pathname,
|
|
68
68
|
page_title: document.title,
|
|
@@ -71,9 +71,9 @@ var k = 30, A = 1e3, j = 3, M = [], N = (e, t, n) => {
|
|
|
71
71
|
event_type: t ? "dblclick" : "click",
|
|
72
72
|
button_type: "button" in e ? e.button : 0
|
|
73
73
|
};
|
|
74
|
-
return r instanceof HTMLElement && (o.rage_click =
|
|
74
|
+
return r instanceof HTMLElement && (o.rage_click = F(i, a, Date.now()), o = {
|
|
75
75
|
...o,
|
|
76
|
-
...
|
|
76
|
+
...d(r)
|
|
77
77
|
}), o;
|
|
78
78
|
}, i = (n, i, a) => {
|
|
79
79
|
try {
|
|
@@ -86,25 +86,25 @@ var k = 30, A = 1e3, j = 3, M = [], N = (e, t, n) => {
|
|
|
86
86
|
is_navigation: !0
|
|
87
87
|
});
|
|
88
88
|
} catch (e) {
|
|
89
|
-
console.error("[insights] Failed to track navigation click",
|
|
89
|
+
console.error("[insights] Failed to track navigation click", D(e));
|
|
90
90
|
}
|
|
91
91
|
}, a = (n, i = !1, a) => {
|
|
92
92
|
try {
|
|
93
|
-
let o = a ??
|
|
93
|
+
let o = a ?? v(n);
|
|
94
94
|
if (!o || Date.now() - t < 300) return;
|
|
95
|
-
let s = r(n, i, o), c =
|
|
95
|
+
let s = r(n, i, o), c = L(o);
|
|
96
96
|
e.track("page.click", {
|
|
97
97
|
...s,
|
|
98
98
|
href: c.href || void 0,
|
|
99
99
|
link_type: c.type || void 0
|
|
100
100
|
});
|
|
101
101
|
} catch (e) {
|
|
102
|
-
console.error("[insights] Failed to track click",
|
|
102
|
+
console.error("[insights] Failed to track click", D(e));
|
|
103
103
|
}
|
|
104
104
|
}, o = (e) => {
|
|
105
|
-
let t =
|
|
105
|
+
let t = v(e);
|
|
106
106
|
if (!t) return;
|
|
107
|
-
let r =
|
|
107
|
+
let r = L(t);
|
|
108
108
|
if (r.type === "external" || r.type === "download") {
|
|
109
109
|
i(e, r, t);
|
|
110
110
|
return;
|
|
@@ -117,13 +117,13 @@ var k = 30, A = 1e3, j = 3, M = [], N = (e, t, n) => {
|
|
|
117
117
|
a(e, !1, t), n = null;
|
|
118
118
|
}, 250);
|
|
119
119
|
}, s = (e) => {
|
|
120
|
-
n &&= (clearTimeout(n), null), a(e, !0,
|
|
120
|
+
n &&= (clearTimeout(n), null), a(e, !0, v(e) ?? void 0);
|
|
121
121
|
}, c = (n) => {
|
|
122
122
|
try {
|
|
123
|
-
let i =
|
|
123
|
+
let i = v(n);
|
|
124
124
|
if (!i) return;
|
|
125
125
|
t = Date.now();
|
|
126
|
-
let a =
|
|
126
|
+
let a = L(i);
|
|
127
127
|
if (a.type === "external" || a.type === "download") {
|
|
128
128
|
let t = r(n, !1, i);
|
|
129
129
|
e.track("page.click", {
|
|
@@ -143,53 +143,52 @@ var k = 30, A = 1e3, j = 3, M = [], N = (e, t, n) => {
|
|
|
143
143
|
is_touch: !0
|
|
144
144
|
});
|
|
145
145
|
} catch (e) {
|
|
146
|
-
console.error("[insights] Failed to track touch",
|
|
146
|
+
console.error("[insights] Failed to track touch", D(e));
|
|
147
147
|
}
|
|
148
148
|
};
|
|
149
149
|
return document.addEventListener("click", o), document.addEventListener("dblclick", s), document.addEventListener("touchend", c, { passive: !0 }), () => {
|
|
150
150
|
document.removeEventListener("click", o), document.removeEventListener("dblclick", s), document.removeEventListener("touchend", c), n && clearTimeout(n);
|
|
151
151
|
};
|
|
152
|
-
},
|
|
152
|
+
}, z = (e) => {
|
|
153
153
|
if (typeof window > "u") return () => {};
|
|
154
154
|
let t = (t) => (n) => {
|
|
155
155
|
try {
|
|
156
|
-
let r =
|
|
156
|
+
let r = C(n, t);
|
|
157
157
|
r && e.track("page.copy", r);
|
|
158
158
|
} catch (e) {
|
|
159
|
-
console.error(`[insights] Failed to track clipboard ${t}`,
|
|
159
|
+
console.error(`[insights] Failed to track clipboard ${t}`, D(e));
|
|
160
160
|
}
|
|
161
161
|
}, n = t("copy"), r = t("cut");
|
|
162
162
|
return document.addEventListener("copy", n, { capture: !0 }), document.addEventListener("cut", r, { capture: !0 }), () => {
|
|
163
163
|
document.removeEventListener("copy", n, { capture: !0 }), document.removeEventListener("cut", r, { capture: !0 });
|
|
164
164
|
};
|
|
165
|
-
},
|
|
165
|
+
}, B = (e) => {
|
|
166
166
|
if (typeof window > "u") return () => {};
|
|
167
167
|
let t = (t) => (n) => {
|
|
168
168
|
try {
|
|
169
|
-
let r =
|
|
169
|
+
let r = C(n, t);
|
|
170
170
|
if (r) {
|
|
171
171
|
let n = t === "submit" ? "form.submit" : "form.change";
|
|
172
172
|
e.track(n, r);
|
|
173
173
|
}
|
|
174
174
|
} catch (e) {
|
|
175
|
-
console.error(`[insights] Failed to track form ${t}`,
|
|
175
|
+
console.error(`[insights] Failed to track form ${t}`, D(e));
|
|
176
176
|
}
|
|
177
177
|
}, n = t("change"), r = t("submit");
|
|
178
178
|
return document.addEventListener("change", n, { capture: !0 }), document.addEventListener("submit", r, { capture: !0 }), () => {
|
|
179
179
|
document.removeEventListener("change", n, { capture: !0 }), document.removeEventListener("submit", r, { capture: !0 });
|
|
180
180
|
};
|
|
181
|
-
},
|
|
181
|
+
}, V = (e) => {
|
|
182
182
|
if (typeof window > "u") return () => {};
|
|
183
|
-
let { page_id: t } =
|
|
184
|
-
|
|
185
|
-
if (t) try {
|
|
183
|
+
let { page_id: t } = a.get(), n = t || "", r = typeof window < "u" ? window.location.href : "", i = () => {
|
|
184
|
+
try {
|
|
186
185
|
e.page({ resource: "page" });
|
|
187
186
|
} catch (e) {
|
|
188
|
-
console.error("[insights] Failed to send page view",
|
|
187
|
+
console.error("[insights] Failed to send page view", D(e));
|
|
189
188
|
}
|
|
190
189
|
};
|
|
191
190
|
if (t) {
|
|
192
|
-
let e =
|
|
191
|
+
let e = a.listen((e, t, r) => {
|
|
193
192
|
let { page_id: a } = e;
|
|
194
193
|
r === "page_id" && a && n !== a && (n = a, i());
|
|
195
194
|
});
|
|
@@ -210,7 +209,7 @@ var k = 30, A = 1e3, j = 3, M = [], N = (e, t, n) => {
|
|
|
210
209
|
window.removeEventListener("popstate", e), window.history.pushState = t;
|
|
211
210
|
};
|
|
212
211
|
}
|
|
213
|
-
},
|
|
212
|
+
}, H = async (e, t) => {
|
|
214
213
|
let n = null;
|
|
215
214
|
try {
|
|
216
215
|
let r = new AbortController();
|
|
@@ -224,7 +223,7 @@ var k = 30, A = 1e3, j = 3, M = [], N = (e, t, n) => {
|
|
|
224
223
|
} finally {
|
|
225
224
|
n && clearTimeout(n);
|
|
226
225
|
}
|
|
227
|
-
},
|
|
226
|
+
}, U = async (e) => {
|
|
228
227
|
let { mode: t = "auto", insightsUrl: n, directInsightsUrl: r, pingTimeout: i = 1e3, debug: a = !1 } = e;
|
|
229
228
|
if (a) return {
|
|
230
229
|
mode: "proxy",
|
|
@@ -239,7 +238,7 @@ var k = 30, A = 1e3, j = 3, M = [], N = (e, t, n) => {
|
|
|
239
238
|
mode: "proxy",
|
|
240
239
|
url: n ?? null
|
|
241
240
|
};
|
|
242
|
-
let [s, c] = await Promise.all([n ?
|
|
241
|
+
let [s, c] = await Promise.all([n ? H(`${n}/ping`, o) : Promise.resolve(!1), r ? H(`${r}/ping`, o) : Promise.resolve(!1)]);
|
|
243
242
|
return s ? {
|
|
244
243
|
mode: "proxy",
|
|
245
244
|
url: n ?? null
|
|
@@ -250,9 +249,9 @@ var k = 30, A = 1e3, j = 3, M = [], N = (e, t, n) => {
|
|
|
250
249
|
mode: "proxy",
|
|
251
250
|
url: n ?? null
|
|
252
251
|
};
|
|
253
|
-
},
|
|
252
|
+
}, W = () => {
|
|
254
253
|
if (typeof document > "u") return {};
|
|
255
|
-
let { type: e, referrer: t, data: n = {} } =
|
|
254
|
+
let { type: e, referrer: t, data: n = {} } = O({
|
|
256
255
|
referrer: document.referrer,
|
|
257
256
|
currentUrl: window.location.href,
|
|
258
257
|
mapper: null
|
|
@@ -264,7 +263,7 @@ var k = 30, A = 1e3, j = 3, M = [], N = (e, t, n) => {
|
|
|
264
263
|
data: n,
|
|
265
264
|
raw: document.referrer
|
|
266
265
|
};
|
|
267
|
-
},
|
|
266
|
+
}, G = () => new Promise((e, t) => {
|
|
268
267
|
let n = "Unknown";
|
|
269
268
|
function r(t) {
|
|
270
269
|
e({
|
|
@@ -361,12 +360,12 @@ var k = 30, A = 1e3, j = 3, M = [], N = (e, t, n) => {
|
|
|
361
360
|
o() ? (n = "Safari", f()) : s() ? (n = i(), g()) : c() ? (n = "Firefox", _()) : l() ? (n = "Internet Explorer", v()) : t(/* @__PURE__ */ Error("detectIncognito cannot determine the browser"));
|
|
362
361
|
}
|
|
363
362
|
y();
|
|
364
|
-
}),
|
|
363
|
+
}), K = () => {
|
|
365
364
|
let e = document.createElement("canvas"), t = e?.getContext("webgl") || e?.getContext("experimental-webgl");
|
|
366
365
|
if (!t) return null;
|
|
367
366
|
let n = t?.getExtension("WEBGL_debug_renderer_info");
|
|
368
367
|
return n ? t?.getParameter(n.UNMASKED_RENDERER_WEBGL) : null;
|
|
369
|
-
},
|
|
368
|
+
}, q = async () => {
|
|
370
369
|
let e = "", t = "", n = !1, r = !1, i = {};
|
|
371
370
|
if (!window) return {
|
|
372
371
|
locale: e,
|
|
@@ -376,26 +375,20 @@ var k = 30, A = 1e3, j = 3, M = [], N = (e, t, n) => {
|
|
|
376
375
|
properties: i
|
|
377
376
|
};
|
|
378
377
|
let [a, o, s] = await Promise.allSettled([
|
|
379
|
-
|
|
378
|
+
G(),
|
|
380
379
|
navigator.getBattery?.() ?? Promise.reject(),
|
|
381
380
|
"mediaDevices" in navigator ? navigator.mediaDevices.enumerateDevices() : Promise.reject()
|
|
382
381
|
]);
|
|
383
382
|
a.status === "fulfilled" && (r = a.value.isPrivate);
|
|
384
383
|
try {
|
|
385
384
|
n = window.matchMedia?.("(prefers-color-scheme: dark)").matches;
|
|
386
|
-
} catch
|
|
387
|
-
console.error(e);
|
|
388
|
-
}
|
|
385
|
+
} catch {}
|
|
389
386
|
try {
|
|
390
387
|
t = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
391
|
-
} catch
|
|
392
|
-
console.error(e);
|
|
393
|
-
}
|
|
388
|
+
} catch {}
|
|
394
389
|
try {
|
|
395
|
-
e =
|
|
396
|
-
} catch
|
|
397
|
-
console.error(e);
|
|
398
|
-
}
|
|
390
|
+
e = k();
|
|
391
|
+
} catch {}
|
|
399
392
|
let c = navigator, l = c.connection ?? c.mozConnection ?? c.webkitConnection;
|
|
400
393
|
if (l && (i.network_type = l.effectiveType), i.width = window?.innerWidth, i.height = window?.innerHeight, i.pixel_ratio = window?.devicePixelRatio, screen && (i.screen_width = screen?.width, i.screen_height = screen?.height, i.color_depth = screen?.colorDepth, i.orientation = screen?.orientation?.type), o.status === "fulfilled") {
|
|
401
394
|
let e = o.value;
|
|
@@ -405,157 +398,133 @@ var k = 30, A = 1e3, j = 3, M = [], N = (e, t, n) => {
|
|
|
405
398
|
let e = s.value;
|
|
406
399
|
i.camera_supported = e.some((e) => e?.kind === "videoinput"), i.microphone_supported = e.some((e) => e?.kind === "audioinput");
|
|
407
400
|
}
|
|
408
|
-
return i.gpu =
|
|
401
|
+
return i.gpu = K(), {
|
|
409
402
|
locale: e,
|
|
410
403
|
timezone: t,
|
|
411
404
|
dark_mode: n,
|
|
412
405
|
private_mode: r,
|
|
413
406
|
properties: i
|
|
414
407
|
};
|
|
415
|
-
},
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
408
|
+
}, J = (e, t) => {
|
|
409
|
+
if (e.get()) return t(), () => {};
|
|
410
|
+
let n = e.listen((e) => {
|
|
411
|
+
e && (n(), t());
|
|
412
|
+
});
|
|
413
|
+
return n;
|
|
414
|
+
}, Y = (n, i, a) => {
|
|
415
|
+
let { debug: s } = o();
|
|
416
|
+
if (!n) return null;
|
|
417
|
+
let c = {
|
|
418
|
+
name: n.workspace,
|
|
420
419
|
track: ({ payload: e }) => {
|
|
421
|
-
if (!
|
|
420
|
+
if (!a()) return;
|
|
422
421
|
let t = e?.properties || {};
|
|
423
|
-
|
|
422
|
+
i(e.event, t);
|
|
424
423
|
},
|
|
425
424
|
page: ({ payload: e }) => {
|
|
426
|
-
|
|
425
|
+
a() && (r(), i("page.view", {
|
|
427
426
|
...e?.properties || {},
|
|
428
427
|
resource: "page"
|
|
429
428
|
}));
|
|
430
429
|
},
|
|
431
430
|
identify: ({ payload: r }) => {
|
|
432
|
-
if (!
|
|
433
|
-
let { workspace:
|
|
434
|
-
if (!
|
|
435
|
-
let
|
|
436
|
-
private_mode: r.traits?.private_mode ??
|
|
437
|
-
dark_mode: r.traits?.dark_mode ??
|
|
438
|
-
timezone: r.traits?.timezone ??
|
|
439
|
-
locale: r.traits?.locale ??
|
|
440
|
-
referrer: r.traits?.referrer ??
|
|
431
|
+
if (!a()) return;
|
|
432
|
+
let { workspace: i, site_id: s, debug: c } = o(), { mode: l, isIdentified: u, isIdentifying: d, sessionToken: f, deviceToken: p, insightsBaseUrl: m, identity: h } = _(), v = x(), y = _().allTabs.length;
|
|
433
|
+
if (!m || !h) return;
|
|
434
|
+
let b = {
|
|
435
|
+
private_mode: r.traits?.private_mode ?? h.privateMode ?? !1,
|
|
436
|
+
dark_mode: r.traits?.dark_mode ?? h.darkMode ?? !1,
|
|
437
|
+
timezone: r.traits?.timezone ?? h.timezone ?? "",
|
|
438
|
+
locale: r.traits?.locale ?? h.locale ?? "",
|
|
439
|
+
referrer: r.traits?.referrer ?? h.referrer ?? {
|
|
441
440
|
type: "",
|
|
442
441
|
referrer: {},
|
|
443
442
|
data: {}
|
|
444
443
|
},
|
|
445
444
|
properties: {
|
|
446
|
-
...
|
|
445
|
+
...h.properties,
|
|
447
446
|
...r.traits?.properties
|
|
448
447
|
},
|
|
449
|
-
workspace_id:
|
|
450
|
-
site_id:
|
|
448
|
+
workspace_id: i ?? "",
|
|
449
|
+
site_id: s ?? void 0,
|
|
451
450
|
hostname: window.location.hostname,
|
|
452
451
|
pathname: window.location.pathname,
|
|
453
452
|
page_title: document.title,
|
|
454
453
|
url: window.location.href,
|
|
455
454
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
456
|
-
tab_id:
|
|
457
|
-
tab_count:
|
|
455
|
+
tab_id: v ?? "",
|
|
456
|
+
tab_count: y ?? 0
|
|
458
457
|
};
|
|
459
|
-
if (
|
|
460
|
-
isIdentified:
|
|
461
|
-
isIdentifying:
|
|
462
|
-
welcomeInput:
|
|
463
|
-
}),
|
|
464
|
-
if (
|
|
465
|
-
console.log("[@levo-so/insights] Debug mode enabled. Mocking session identification."),
|
|
458
|
+
if (c && console.log("[@levo-so/insights] Identification triggered:", {
|
|
459
|
+
isIdentified: u,
|
|
460
|
+
isIdentifying: d,
|
|
461
|
+
welcomeInput: b
|
|
462
|
+
}), u || d) return;
|
|
463
|
+
if (e({ isIdentifying: !0 }), c) {
|
|
464
|
+
console.log("[@levo-so/insights] Debug mode enabled. Mocking session identification."), e({
|
|
466
465
|
isIdentified: !0,
|
|
467
466
|
isIdentifying: !1,
|
|
468
467
|
sessionId: "debug-session",
|
|
469
468
|
deviceId: "debug-device"
|
|
470
|
-
}),
|
|
469
|
+
}), t(T());
|
|
471
470
|
return;
|
|
472
471
|
}
|
|
473
472
|
let S = {
|
|
474
473
|
Accept: "application/json",
|
|
475
474
|
"Content-Type": "application/json",
|
|
476
|
-
...
|
|
477
|
-
sessionToken:
|
|
478
|
-
deviceToken:
|
|
479
|
-
mode:
|
|
475
|
+
...g({
|
|
476
|
+
sessionToken: f,
|
|
477
|
+
deviceToken: p,
|
|
478
|
+
mode: l
|
|
480
479
|
})
|
|
481
|
-
}, w = (e = 0) => {
|
|
482
|
-
t.fetch.url(g, !0).url("/v1/insights/event/welcome").options({
|
|
483
|
-
keepalive: !0,
|
|
484
|
-
credentials: d === "proxy" ? "include" : "omit"
|
|
485
|
-
}).headers(S).post(x).json().then((e) => {
|
|
486
|
-
if (!i()) {
|
|
487
|
-
n({ isIdentifying: !1 });
|
|
488
|
-
return;
|
|
489
|
-
}
|
|
490
|
-
let { isIdentified: t } = s();
|
|
491
|
-
if (t) n({ isIdentifying: !1 });
|
|
492
|
-
else {
|
|
493
|
-
let t = {
|
|
494
|
-
isIdentified: !0,
|
|
495
|
-
isIdentifying: !1
|
|
496
|
-
};
|
|
497
|
-
if (e?.content?.data?.session && (t.sessionId = e?.content?.data?.session), e?.content?.data?.device && (t.deviceId = e?.content?.data?.device), d === "direct" && e?.content?.meta) {
|
|
498
|
-
let n = e.content.meta;
|
|
499
|
-
n.device_token && (t.deviceToken = n.device_token), n.session_token && (t.sessionToken = n.session_token);
|
|
500
|
-
}
|
|
501
|
-
n(t), C(c());
|
|
502
|
-
}
|
|
503
|
-
}).catch((r) => {
|
|
504
|
-
if (t.logger?.error("/welcome failed with error", T(r)), e < 2 && i()) {
|
|
505
|
-
let t = 5e3 * 2 ** e;
|
|
506
|
-
setTimeout(() => {
|
|
507
|
-
i() && !s().isIdentified ? w(e + 1) : n({ isIdentifying: !1 });
|
|
508
|
-
}, t);
|
|
509
|
-
} else n({ isIdentifying: !1 });
|
|
510
|
-
});
|
|
511
480
|
};
|
|
512
|
-
|
|
481
|
+
n.fetch.url(m, !0).url("/v1/insights/event/welcome").options({
|
|
482
|
+
keepalive: !0,
|
|
483
|
+
credentials: l === "proxy" ? "include" : "omit"
|
|
484
|
+
}).headers(S).post(b).json().then((n) => {
|
|
485
|
+
if (!a()) {
|
|
486
|
+
e({ isIdentifying: !1 });
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
let { isIdentified: r } = _();
|
|
490
|
+
if (r) e({ isIdentifying: !1 });
|
|
491
|
+
else {
|
|
492
|
+
let r = {
|
|
493
|
+
isIdentified: !0,
|
|
494
|
+
isIdentifying: !1
|
|
495
|
+
};
|
|
496
|
+
if (n?.content?.data?.session && (r.sessionId = n?.content?.data?.session), n?.content?.data?.device && (r.deviceId = n?.content?.data?.device), l === "direct" && n?.content?.meta) {
|
|
497
|
+
let e = n.content.meta;
|
|
498
|
+
e.device_token && (r.deviceToken = e.device_token), e.session_token && (r.sessionToken = e.session_token);
|
|
499
|
+
}
|
|
500
|
+
e(r), t(T());
|
|
501
|
+
}
|
|
502
|
+
}).catch((t) => {
|
|
503
|
+
_().isIdentified || n.logger?.error("/welcome failed with error", { exception: D(t) }), e({ isIdentifying: !1 });
|
|
504
|
+
});
|
|
513
505
|
}
|
|
514
506
|
};
|
|
515
|
-
return
|
|
516
|
-
app:
|
|
517
|
-
debug: !!
|
|
518
|
-
plugins: [
|
|
507
|
+
return A({
|
|
508
|
+
app: n.workspace || "",
|
|
509
|
+
debug: !!s,
|
|
510
|
+
plugins: [c]
|
|
519
511
|
});
|
|
520
|
-
},
|
|
521
|
-
let { insightsUrl:
|
|
522
|
-
|
|
523
|
-
workspace:
|
|
524
|
-
debug:
|
|
525
|
-
site_id:
|
|
526
|
-
|
|
527
|
-
let r = t?.type ? {
|
|
528
|
-
type: t.type,
|
|
529
|
-
referrer: t.referrer,
|
|
530
|
-
data: t.data,
|
|
531
|
-
raw: t.raw ?? ""
|
|
532
|
-
} : null;
|
|
533
|
-
n({ identity: {
|
|
534
|
-
locale: e.locale,
|
|
535
|
-
timezone: e.timezone,
|
|
536
|
-
darkMode: e.dark_mode,
|
|
537
|
-
privateMode: e.private_mode,
|
|
538
|
-
referrer: r,
|
|
539
|
-
properties: e.properties
|
|
540
|
-
} });
|
|
541
|
-
}).catch(() => {
|
|
542
|
-
n({ identity: {
|
|
543
|
-
locale: null,
|
|
544
|
-
timezone: null,
|
|
545
|
-
darkMode: null,
|
|
546
|
-
privateMode: null,
|
|
547
|
-
referrer: null,
|
|
548
|
-
properties: null
|
|
549
|
-
} });
|
|
512
|
+
}, X = null, Z = !1, Q = [], $ = (r, a) => {
|
|
513
|
+
let { insightsUrl: d = null, debug: g = !1, site: v = null } = a;
|
|
514
|
+
s({
|
|
515
|
+
workspace: r.workspace,
|
|
516
|
+
debug: g,
|
|
517
|
+
site_id: v,
|
|
518
|
+
insightsUrl: d ?? null
|
|
550
519
|
});
|
|
551
|
-
let
|
|
520
|
+
let C = async (e, t) => {
|
|
552
521
|
if (typeof window > "u") return;
|
|
553
|
-
let { page_id:
|
|
554
|
-
|
|
555
|
-
event:
|
|
556
|
-
version:
|
|
522
|
+
let { page_id: n } = o(), { allTabs: r } = _(), i = x(), a = r.length;
|
|
523
|
+
l({
|
|
524
|
+
event: e,
|
|
525
|
+
version: t?.version || 1,
|
|
557
526
|
properties: {
|
|
558
|
-
...
|
|
527
|
+
...t,
|
|
559
528
|
version: void 0,
|
|
560
529
|
resource: void 0,
|
|
561
530
|
identifier: void 0,
|
|
@@ -567,64 +536,80 @@ var k = 30, A = 1e3, j = 3, M = [], N = (e, t, n) => {
|
|
|
567
536
|
},
|
|
568
537
|
hostname: window.location.hostname,
|
|
569
538
|
pathname: window.location.pathname,
|
|
570
|
-
url:
|
|
571
|
-
page_title:
|
|
572
|
-
resource:
|
|
573
|
-
identifier:
|
|
574
|
-
created_at:
|
|
575
|
-
tab_id:
|
|
576
|
-
tab_count:
|
|
539
|
+
url: t?.url ?? window.location.href,
|
|
540
|
+
page_title: t?.page_title ?? document.title,
|
|
541
|
+
resource: t?.resource ?? "page",
|
|
542
|
+
identifier: t?.id ?? n ?? void 0,
|
|
543
|
+
created_at: t?.created_at ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
544
|
+
tab_id: i ?? "",
|
|
545
|
+
tab_count: a
|
|
546
|
+
});
|
|
547
|
+
}, E = (e) => {
|
|
548
|
+
!X || !Z || X.identify("", { withLock: e?.withLock ?? !0 });
|
|
549
|
+
}, D = (e) => {
|
|
550
|
+
let { page_id: t } = o();
|
|
551
|
+
t !== e && i("page_id", e);
|
|
552
|
+
}, O = () => Promise.allSettled([q(), Promise.resolve().then(() => W())]).then(([t, n]) => {
|
|
553
|
+
let r = t.status === "fulfilled" ? t.value : null, i = n.status === "fulfilled" ? n.value : null, a = i?.type ? {
|
|
554
|
+
type: i.type,
|
|
555
|
+
referrer: i.referrer,
|
|
556
|
+
data: i.data,
|
|
557
|
+
raw: i.raw ?? ""
|
|
558
|
+
} : null;
|
|
559
|
+
e({ identity: {
|
|
560
|
+
locale: r?.locale ?? null,
|
|
561
|
+
timezone: r?.timezone ?? null,
|
|
562
|
+
darkMode: r?.dark_mode ?? null,
|
|
563
|
+
privateMode: r?.private_mode ?? null,
|
|
564
|
+
referrer: a,
|
|
565
|
+
properties: r?.properties ?? null
|
|
566
|
+
} });
|
|
567
|
+
}), k = () => {
|
|
568
|
+
let { insightsBaseUrl: t } = _();
|
|
569
|
+
return t ? Promise.resolve() : U(a).then(({ mode: t, url: n }) => {
|
|
570
|
+
Z && n && e({
|
|
571
|
+
mode: t,
|
|
572
|
+
insightsBaseUrl: n
|
|
573
|
+
});
|
|
574
|
+
}).catch(() => {
|
|
575
|
+
Z && d && e({
|
|
576
|
+
mode: "proxy",
|
|
577
|
+
insightsBaseUrl: d
|
|
578
|
+
});
|
|
577
579
|
});
|
|
578
|
-
}, x = (e) => {
|
|
579
|
-
!q || !J || q.identify("", { withLock: e?.withLock ?? !0 });
|
|
580
|
-
}, w = (t) => {
|
|
581
|
-
let { page_id: n } = e();
|
|
582
|
-
n !== t && i("page_id", t);
|
|
583
580
|
};
|
|
584
581
|
return {
|
|
585
|
-
init: (
|
|
582
|
+
init: (t = {}) => {
|
|
586
583
|
if (typeof window > "u") throw Error("[@levo-so/insights] init() should only be called on the client side.");
|
|
587
|
-
let { pageId: i } =
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
J = !0;
|
|
594
|
-
let c = s();
|
|
595
|
-
c.mode === "direct" && c.isIdentified && (!c.sessionToken || !c.deviceToken) && n({ isIdentified: !1 }), r(() => {
|
|
596
|
-
if (!J) return;
|
|
597
|
-
let { insightsBaseUrl: e } = s();
|
|
598
|
-
e || V(o).then(({ mode: e, url: t }) => {
|
|
599
|
-
J && t && n({
|
|
600
|
-
mode: e,
|
|
601
|
-
insightsBaseUrl: t
|
|
602
|
-
});
|
|
603
|
-
}).catch(() => {
|
|
604
|
-
J && l && n({
|
|
605
|
-
mode: "proxy",
|
|
606
|
-
insightsBaseUrl: l
|
|
607
|
-
});
|
|
584
|
+
let { pageId: i } = t;
|
|
585
|
+
i && D(i), !Z && (r.NODE_ENV === "development" && !g || (Z = !0, Q.push(J(n, () => {
|
|
586
|
+
if (!Z) return;
|
|
587
|
+
let t = _();
|
|
588
|
+
t.mode === "direct" && t.isIdentified && (!t.sessionToken || !t.deviceToken) && e({ isIdentified: !1 }), O().finally(() => {
|
|
589
|
+
Z && u.set(!0);
|
|
608
590
|
});
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
q = e, s().insightsBaseUrl && q && (Y.push(h(q), u(q), I(q), L(q), v(q), R(q), z(q), d(q), g(q)), x(), q.page({ resource: "page" }));
|
|
613
|
-
}
|
|
591
|
+
})), d && Q.push(J(n, () => {
|
|
592
|
+
Z && k().finally(() => {
|
|
593
|
+
Z && m.set(!0);
|
|
614
594
|
});
|
|
615
|
-
|
|
616
|
-
|
|
595
|
+
})), Q.push(J(p, () => {
|
|
596
|
+
if (!Z || X) return;
|
|
597
|
+
let e = Y(r, C, () => X === e);
|
|
598
|
+
e && (X = e, Q.push(y(e), f(e), R(e), z(e), S(e), B(e), V(e), h(e), b(e)));
|
|
599
|
+
})), Q.push(J(w, () => {
|
|
600
|
+
!Z || !X || (E(), X.page({ resource: "page" }));
|
|
601
|
+
}))));
|
|
617
602
|
},
|
|
618
603
|
destroy: () => {
|
|
619
|
-
|
|
604
|
+
Z && (t(T()), c(), Q.forEach((e) => {
|
|
620
605
|
e();
|
|
621
|
-
}),
|
|
606
|
+
}), Q.length = 0, X = null, Z = !1, u.set(!1), m.set(!1));
|
|
622
607
|
},
|
|
623
|
-
track:
|
|
608
|
+
track: C,
|
|
624
609
|
get instance() {
|
|
625
|
-
return
|
|
610
|
+
return X;
|
|
626
611
|
}
|
|
627
612
|
};
|
|
628
613
|
};
|
|
629
614
|
//#endregion
|
|
630
|
-
export {
|
|
615
|
+
export { E as AnalyticsEvents, $ as createLevoInsights };
|
package/dist/lib/insights.d.ts
CHANGED
|
@@ -4,13 +4,14 @@ import { IInsightOptions } from '../types/options';
|
|
|
4
4
|
/**
|
|
5
5
|
* Creates the Levo Audience analytics module.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* Two independent pipelines run on init():
|
|
8
|
+
* - Identity pipeline: session hydration → user properties + referrer.
|
|
9
|
+
* Always runs. Powers DOM trackers and store-only consumers (popups).
|
|
10
|
+
* - Network pipeline: detectMode → /welcome → event flushing.
|
|
11
|
+
* Runs only when insightsUrl is configured.
|
|
10
12
|
*
|
|
11
13
|
* @param client - The Levo control instance containing workspace config
|
|
12
14
|
* @param options - Configuration options for the insights module
|
|
13
|
-
* @returns The audience module with tracking methods
|
|
14
15
|
*/
|
|
15
16
|
declare const createLevoInsights: (client: ILevoClient, options: IInsightOptions) => {
|
|
16
17
|
init: (initOptions?: {
|