@levo-so/insights 0.1.86 → 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 +194 -202
- 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-DC99Tbqq.js → textSelection-eSp_MmZH.js} +132 -119
- 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 O = 30, k = 1e3, A = 3, j = [], M = (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 O = 30, k = 1e3, A = 3, j = [], M = (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 O = 30, k = 1e3, A = 3, j = [], M = (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 O = 30, k = 1e3, A = 3, j = [], M = (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 O = 30, k = 1e3, A = 3, j = [], M = (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,52 +143,52 @@ var O = 30, k = 1e3, A = 3, j = [], M = (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 } =
|
|
183
|
+
let { page_id: t } = a.get(), n = t || "", r = typeof window < "u" ? window.location.href : "", i = () => {
|
|
184
184
|
try {
|
|
185
185
|
e.page({ resource: "page" });
|
|
186
186
|
} catch (e) {
|
|
187
|
-
console.error("[insights] Failed to send page view",
|
|
187
|
+
console.error("[insights] Failed to send page view", D(e));
|
|
188
188
|
}
|
|
189
189
|
};
|
|
190
190
|
if (t) {
|
|
191
|
-
let e =
|
|
191
|
+
let e = a.listen((e, t, r) => {
|
|
192
192
|
let { page_id: a } = e;
|
|
193
193
|
r === "page_id" && a && n !== a && (n = a, i());
|
|
194
194
|
});
|
|
@@ -209,7 +209,7 @@ var O = 30, k = 1e3, A = 3, j = [], M = (e, t, n) => {
|
|
|
209
209
|
window.removeEventListener("popstate", e), window.history.pushState = t;
|
|
210
210
|
};
|
|
211
211
|
}
|
|
212
|
-
},
|
|
212
|
+
}, H = async (e, t) => {
|
|
213
213
|
let n = null;
|
|
214
214
|
try {
|
|
215
215
|
let r = new AbortController();
|
|
@@ -223,7 +223,7 @@ var O = 30, k = 1e3, A = 3, j = [], M = (e, t, n) => {
|
|
|
223
223
|
} finally {
|
|
224
224
|
n && clearTimeout(n);
|
|
225
225
|
}
|
|
226
|
-
},
|
|
226
|
+
}, U = async (e) => {
|
|
227
227
|
let { mode: t = "auto", insightsUrl: n, directInsightsUrl: r, pingTimeout: i = 1e3, debug: a = !1 } = e;
|
|
228
228
|
if (a) return {
|
|
229
229
|
mode: "proxy",
|
|
@@ -238,7 +238,7 @@ var O = 30, k = 1e3, A = 3, j = [], M = (e, t, n) => {
|
|
|
238
238
|
mode: "proxy",
|
|
239
239
|
url: n ?? null
|
|
240
240
|
};
|
|
241
|
-
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)]);
|
|
242
242
|
return s ? {
|
|
243
243
|
mode: "proxy",
|
|
244
244
|
url: n ?? null
|
|
@@ -249,9 +249,9 @@ var O = 30, k = 1e3, A = 3, j = [], M = (e, t, n) => {
|
|
|
249
249
|
mode: "proxy",
|
|
250
250
|
url: n ?? null
|
|
251
251
|
};
|
|
252
|
-
},
|
|
252
|
+
}, W = () => {
|
|
253
253
|
if (typeof document > "u") return {};
|
|
254
|
-
let { type: e, referrer: t, data: n = {} } =
|
|
254
|
+
let { type: e, referrer: t, data: n = {} } = O({
|
|
255
255
|
referrer: document.referrer,
|
|
256
256
|
currentUrl: window.location.href,
|
|
257
257
|
mapper: null
|
|
@@ -263,7 +263,7 @@ var O = 30, k = 1e3, A = 3, j = [], M = (e, t, n) => {
|
|
|
263
263
|
data: n,
|
|
264
264
|
raw: document.referrer
|
|
265
265
|
};
|
|
266
|
-
},
|
|
266
|
+
}, G = () => new Promise((e, t) => {
|
|
267
267
|
let n = "Unknown";
|
|
268
268
|
function r(t) {
|
|
269
269
|
e({
|
|
@@ -360,12 +360,12 @@ var O = 30, k = 1e3, A = 3, j = [], M = (e, t, n) => {
|
|
|
360
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"));
|
|
361
361
|
}
|
|
362
362
|
y();
|
|
363
|
-
}),
|
|
363
|
+
}), K = () => {
|
|
364
364
|
let e = document.createElement("canvas"), t = e?.getContext("webgl") || e?.getContext("experimental-webgl");
|
|
365
365
|
if (!t) return null;
|
|
366
366
|
let n = t?.getExtension("WEBGL_debug_renderer_info");
|
|
367
367
|
return n ? t?.getParameter(n.UNMASKED_RENDERER_WEBGL) : null;
|
|
368
|
-
},
|
|
368
|
+
}, q = async () => {
|
|
369
369
|
let e = "", t = "", n = !1, r = !1, i = {};
|
|
370
370
|
if (!window) return {
|
|
371
371
|
locale: e,
|
|
@@ -375,7 +375,7 @@ var O = 30, k = 1e3, A = 3, j = [], M = (e, t, n) => {
|
|
|
375
375
|
properties: i
|
|
376
376
|
};
|
|
377
377
|
let [a, o, s] = await Promise.allSettled([
|
|
378
|
-
|
|
378
|
+
G(),
|
|
379
379
|
navigator.getBattery?.() ?? Promise.reject(),
|
|
380
380
|
"mediaDevices" in navigator ? navigator.mediaDevices.enumerateDevices() : Promise.reject()
|
|
381
381
|
]);
|
|
@@ -387,7 +387,7 @@ var O = 30, k = 1e3, A = 3, j = [], M = (e, t, n) => {
|
|
|
387
387
|
t = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
388
388
|
} catch {}
|
|
389
389
|
try {
|
|
390
|
-
e =
|
|
390
|
+
e = k();
|
|
391
391
|
} catch {}
|
|
392
392
|
let c = navigator, l = c.connection ?? c.mozConnection ?? c.webkitConnection;
|
|
393
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") {
|
|
@@ -398,157 +398,133 @@ var O = 30, k = 1e3, A = 3, j = [], M = (e, t, n) => {
|
|
|
398
398
|
let e = s.value;
|
|
399
399
|
i.camera_supported = e.some((e) => e?.kind === "videoinput"), i.microphone_supported = e.some((e) => e?.kind === "audioinput");
|
|
400
400
|
}
|
|
401
|
-
return i.gpu =
|
|
401
|
+
return i.gpu = K(), {
|
|
402
402
|
locale: e,
|
|
403
403
|
timezone: t,
|
|
404
404
|
dark_mode: n,
|
|
405
405
|
private_mode: r,
|
|
406
406
|
properties: i
|
|
407
407
|
};
|
|
408
|
-
},
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
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,
|
|
413
419
|
track: ({ payload: e }) => {
|
|
414
|
-
if (!
|
|
420
|
+
if (!a()) return;
|
|
415
421
|
let t = e?.properties || {};
|
|
416
|
-
|
|
422
|
+
i(e.event, t);
|
|
417
423
|
},
|
|
418
424
|
page: ({ payload: e }) => {
|
|
419
|
-
|
|
425
|
+
a() && (r(), i("page.view", {
|
|
420
426
|
...e?.properties || {},
|
|
421
427
|
resource: "page"
|
|
422
428
|
}));
|
|
423
429
|
},
|
|
424
430
|
identify: ({ payload: r }) => {
|
|
425
|
-
if (!
|
|
426
|
-
let { workspace:
|
|
427
|
-
if (!
|
|
428
|
-
let
|
|
429
|
-
private_mode: r.traits?.private_mode ??
|
|
430
|
-
dark_mode: r.traits?.dark_mode ??
|
|
431
|
-
timezone: r.traits?.timezone ??
|
|
432
|
-
locale: r.traits?.locale ??
|
|
433
|
-
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 ?? {
|
|
434
440
|
type: "",
|
|
435
441
|
referrer: {},
|
|
436
442
|
data: {}
|
|
437
443
|
},
|
|
438
444
|
properties: {
|
|
439
|
-
...
|
|
445
|
+
...h.properties,
|
|
440
446
|
...r.traits?.properties
|
|
441
447
|
},
|
|
442
|
-
workspace_id:
|
|
443
|
-
site_id:
|
|
448
|
+
workspace_id: i ?? "",
|
|
449
|
+
site_id: s ?? void 0,
|
|
444
450
|
hostname: window.location.hostname,
|
|
445
451
|
pathname: window.location.pathname,
|
|
446
452
|
page_title: document.title,
|
|
447
453
|
url: window.location.href,
|
|
448
454
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
449
|
-
tab_id:
|
|
450
|
-
tab_count:
|
|
455
|
+
tab_id: v ?? "",
|
|
456
|
+
tab_count: y ?? 0
|
|
451
457
|
};
|
|
452
|
-
if (
|
|
453
|
-
isIdentified:
|
|
454
|
-
isIdentifying:
|
|
455
|
-
welcomeInput:
|
|
456
|
-
}),
|
|
457
|
-
if (
|
|
458
|
-
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({
|
|
459
465
|
isIdentified: !0,
|
|
460
466
|
isIdentifying: !1,
|
|
461
467
|
sessionId: "debug-session",
|
|
462
468
|
deviceId: "debug-device"
|
|
463
|
-
}),
|
|
469
|
+
}), t(T());
|
|
464
470
|
return;
|
|
465
471
|
}
|
|
466
|
-
let
|
|
472
|
+
let S = {
|
|
467
473
|
Accept: "application/json",
|
|
468
474
|
"Content-Type": "application/json",
|
|
469
|
-
...
|
|
470
|
-
sessionToken:
|
|
471
|
-
deviceToken:
|
|
472
|
-
mode:
|
|
475
|
+
...g({
|
|
476
|
+
sessionToken: f,
|
|
477
|
+
deviceToken: p,
|
|
478
|
+
mode: l
|
|
473
479
|
})
|
|
474
|
-
}, T = (e = 0) => {
|
|
475
|
-
t.fetch.url(g, !0).url("/v1/insights/event/welcome").options({
|
|
476
|
-
keepalive: !0,
|
|
477
|
-
credentials: d === "proxy" ? "include" : "omit"
|
|
478
|
-
}).headers(C).post(x).json().then((e) => {
|
|
479
|
-
if (!i()) {
|
|
480
|
-
n({ isIdentifying: !1 });
|
|
481
|
-
return;
|
|
482
|
-
}
|
|
483
|
-
let { isIdentified: t } = s();
|
|
484
|
-
if (t) n({ isIdentifying: !1 });
|
|
485
|
-
else {
|
|
486
|
-
let t = {
|
|
487
|
-
isIdentified: !0,
|
|
488
|
-
isIdentifying: !1
|
|
489
|
-
};
|
|
490
|
-
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) {
|
|
491
|
-
let n = e.content.meta;
|
|
492
|
-
n.device_token && (t.deviceToken = n.device_token), n.session_token && (t.sessionToken = n.session_token);
|
|
493
|
-
}
|
|
494
|
-
n(t), S(c());
|
|
495
|
-
}
|
|
496
|
-
}).catch((r) => {
|
|
497
|
-
if (t.logger?.error("/welcome failed with error", w(r)), e < 2 && i()) {
|
|
498
|
-
let t = 5e3 * 2 ** e;
|
|
499
|
-
setTimeout(() => {
|
|
500
|
-
i() && !s().isIdentified ? T(e + 1) : n({ isIdentifying: !1 });
|
|
501
|
-
}, t);
|
|
502
|
-
} else n({ isIdentifying: !1 });
|
|
503
|
-
});
|
|
504
480
|
};
|
|
505
|
-
|
|
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
|
+
});
|
|
506
505
|
}
|
|
507
506
|
};
|
|
508
|
-
return
|
|
509
|
-
app:
|
|
510
|
-
debug: !!
|
|
511
|
-
plugins: [
|
|
507
|
+
return A({
|
|
508
|
+
app: n.workspace || "",
|
|
509
|
+
debug: !!s,
|
|
510
|
+
plugins: [c]
|
|
512
511
|
});
|
|
513
|
-
},
|
|
514
|
-
let { insightsUrl:
|
|
515
|
-
|
|
516
|
-
workspace:
|
|
517
|
-
debug:
|
|
518
|
-
site_id:
|
|
519
|
-
|
|
520
|
-
let r = t?.type ? {
|
|
521
|
-
type: t.type,
|
|
522
|
-
referrer: t.referrer,
|
|
523
|
-
data: t.data,
|
|
524
|
-
raw: t.raw ?? ""
|
|
525
|
-
} : null;
|
|
526
|
-
n({ identity: {
|
|
527
|
-
locale: e.locale,
|
|
528
|
-
timezone: e.timezone,
|
|
529
|
-
darkMode: e.dark_mode,
|
|
530
|
-
privateMode: e.private_mode,
|
|
531
|
-
referrer: r,
|
|
532
|
-
properties: e.properties
|
|
533
|
-
} });
|
|
534
|
-
}).catch(() => {
|
|
535
|
-
n({ identity: {
|
|
536
|
-
locale: null,
|
|
537
|
-
timezone: null,
|
|
538
|
-
darkMode: null,
|
|
539
|
-
privateMode: null,
|
|
540
|
-
referrer: null,
|
|
541
|
-
properties: null
|
|
542
|
-
} });
|
|
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
|
|
543
519
|
});
|
|
544
|
-
let
|
|
520
|
+
let C = async (e, t) => {
|
|
545
521
|
if (typeof window > "u") return;
|
|
546
|
-
let { page_id:
|
|
547
|
-
|
|
548
|
-
event:
|
|
549
|
-
version:
|
|
522
|
+
let { page_id: n } = o(), { allTabs: r } = _(), i = x(), a = r.length;
|
|
523
|
+
l({
|
|
524
|
+
event: e,
|
|
525
|
+
version: t?.version || 1,
|
|
550
526
|
properties: {
|
|
551
|
-
...
|
|
527
|
+
...t,
|
|
552
528
|
version: void 0,
|
|
553
529
|
resource: void 0,
|
|
554
530
|
identifier: void 0,
|
|
@@ -560,64 +536,80 @@ var O = 30, k = 1e3, A = 3, j = [], M = (e, t, n) => {
|
|
|
560
536
|
},
|
|
561
537
|
hostname: window.location.hostname,
|
|
562
538
|
pathname: window.location.pathname,
|
|
563
|
-
url:
|
|
564
|
-
page_title:
|
|
565
|
-
resource:
|
|
566
|
-
identifier:
|
|
567
|
-
created_at:
|
|
568
|
-
tab_id:
|
|
569
|
-
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
|
+
});
|
|
570
579
|
});
|
|
571
|
-
}, C = (e) => {
|
|
572
|
-
!K || !q || K.identify("", { withLock: e?.withLock ?? !0 });
|
|
573
|
-
}, w = (t) => {
|
|
574
|
-
let { page_id: n } = e();
|
|
575
|
-
n !== t && i("page_id", t);
|
|
576
580
|
};
|
|
577
581
|
return {
|
|
578
|
-
init: (
|
|
582
|
+
init: (t = {}) => {
|
|
579
583
|
if (typeof window > "u") throw Error("[@levo-so/insights] init() should only be called on the client side.");
|
|
580
|
-
let { pageId: i } =
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
q = !0;
|
|
587
|
-
let c = s();
|
|
588
|
-
c.mode === "direct" && c.isIdentified && (!c.sessionToken || !c.deviceToken) && n({ isIdentified: !1 }), r(() => {
|
|
589
|
-
if (!q) return;
|
|
590
|
-
let { insightsBaseUrl: e } = s();
|
|
591
|
-
e || B(o).then(({ mode: e, url: t }) => {
|
|
592
|
-
q && t && n({
|
|
593
|
-
mode: e,
|
|
594
|
-
insightsBaseUrl: t
|
|
595
|
-
});
|
|
596
|
-
}).catch(() => {
|
|
597
|
-
q && l && n({
|
|
598
|
-
mode: "proxy",
|
|
599
|
-
insightsBaseUrl: l
|
|
600
|
-
});
|
|
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);
|
|
601
590
|
});
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
K = e, s().insightsBaseUrl && K && (J.push(h(K), u(K), F(K), I(K), v(K), L(K), R(K), d(K), g(K)), C(), K.page({ resource: "page" }));
|
|
606
|
-
}
|
|
591
|
+
})), d && Q.push(J(n, () => {
|
|
592
|
+
Z && k().finally(() => {
|
|
593
|
+
Z && m.set(!0);
|
|
607
594
|
});
|
|
608
|
-
|
|
609
|
-
|
|
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
|
+
}))));
|
|
610
602
|
},
|
|
611
603
|
destroy: () => {
|
|
612
|
-
|
|
604
|
+
Z && (t(T()), c(), Q.forEach((e) => {
|
|
613
605
|
e();
|
|
614
|
-
}),
|
|
606
|
+
}), Q.length = 0, X = null, Z = !1, u.set(!1), m.set(!1));
|
|
615
607
|
},
|
|
616
|
-
track:
|
|
608
|
+
track: C,
|
|
617
609
|
get instance() {
|
|
618
|
-
return
|
|
610
|
+
return X;
|
|
619
611
|
}
|
|
620
612
|
};
|
|
621
613
|
};
|
|
622
614
|
//#endregion
|
|
623
|
-
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?: {
|
package/dist/stores/config.d.ts
CHANGED
|
@@ -7,6 +7,11 @@ interface IInsightsConfig {
|
|
|
7
7
|
page_id: string | null;
|
|
8
8
|
site_id: string | null;
|
|
9
9
|
debug: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Reverse-proxy URL passed at init. Null when the consumer opts out of
|
|
12
|
+
* network tracking — gates queueEvent and the network-readiness pipeline.
|
|
13
|
+
*/
|
|
14
|
+
insightsUrl: string | null;
|
|
10
15
|
}
|
|
11
16
|
declare const $config: import('nanostores').PreinitializedMapStore<IInsightsConfig> & object;
|
|
12
17
|
declare const getConfig: () => IInsightsConfig;
|