@levo-so/insights 0.1.82 → 0.1.85

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 CHANGED
@@ -1,665 +1,630 @@
1
- import { k as H, l as F, a as U, i as q, m as P, n as C, o as z, u as T, p as G, r as $, 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-N3vefCQW.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
- $();
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
- ...G({ 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
- };
662
- export {
663
- Pe as AnalyticsEvents,
664
- Le as createLevoInsights
1
+ import { A as e, C as t, D as n, E as r, M as i, O as a, S as o, T as s, b as c, c as l, f as u, i as d, j as f, k as p, l as m, m as h, n as g, o as _, s as v, u as y, v as b, w as x, x as S, y as C } from "./textSelection-DJ23SrA-.js";
2
+ import { AnalyticsEvents as w, getLevoError as T } from "@levo-so/core";
3
+ import { getVisitorSource as E } from "@analytics/visitor-source";
4
+ import D from "get-user-locale";
5
+ import { Analytics as O } from "analytics";
6
+ //#region src/utils/rageclick.ts
7
+ var k = 30, A = 1e3, j = 3, M = [], N = (e, t, n) => {
8
+ let r = M[M.length - 1];
9
+ if (r && Math.abs(e - r.x) + Math.abs(t - r.y) < k && n - r.timestamp < A) {
10
+ if (M.push({
11
+ x: e,
12
+ y: t,
13
+ timestamp: n
14
+ }), M.length >= j) return M = [], !0;
15
+ } else M = [{
16
+ x: e,
17
+ y: t,
18
+ timestamp: n
19
+ }];
20
+ return !1;
21
+ }, P = (e) => {
22
+ let t = e, n = 0;
23
+ for (; t && n < 10;) {
24
+ let e = t.getAttribute?.("href");
25
+ if (e) return e;
26
+ t = t.parentElement, n++;
27
+ }
28
+ return null;
29
+ }, F = (e) => {
30
+ let t = e.closest("a[href]"), n = t?.getAttribute("href") || P(e);
31
+ if (!n) return {
32
+ type: null,
33
+ href: null
34
+ };
35
+ if (t?.hasAttribute("download")) return {
36
+ type: "download",
37
+ href: n
38
+ };
39
+ if (n.startsWith("tel:")) return {
40
+ type: "tel",
41
+ href: n
42
+ };
43
+ if (n.startsWith("mailto:")) return {
44
+ type: "mailto",
45
+ href: n
46
+ };
47
+ if (n.startsWith("#")) return {
48
+ type: "anchor",
49
+ href: n
50
+ };
51
+ try {
52
+ return {
53
+ type: new URL(n, window.location.origin).origin === window.location.origin ? "internal" : "external",
54
+ href: n
55
+ };
56
+ } catch (e) {
57
+ return console.warn("[insights] Failed to classify link", T(e)), {
58
+ type: "internal",
59
+ href: n
60
+ };
61
+ }
62
+ }, I = (e) => {
63
+ if (typeof window > "u") return () => {};
64
+ let t = 0, n = null, r = (e, t = !1, n) => {
65
+ let r = n ?? m(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
+ hostname: window.location.hostname,
67
+ pathname: window.location.pathname,
68
+ page_title: document.title,
69
+ url: window.location.href,
70
+ created_at: (/* @__PURE__ */ new Date()).toISOString(),
71
+ event_type: t ? "dblclick" : "click",
72
+ button_type: "button" in e ? e.button : 0
73
+ };
74
+ return r instanceof HTMLElement && (o.rage_click = N(i, a, Date.now()), o = {
75
+ ...o,
76
+ ...l(r)
77
+ }), o;
78
+ }, i = (n, i, a) => {
79
+ try {
80
+ if (Date.now() - t < 300) return;
81
+ let o = r(n, !1, a);
82
+ e.track("page.click", {
83
+ ...o,
84
+ href: i.href || void 0,
85
+ link_type: i.type,
86
+ is_navigation: !0
87
+ });
88
+ } catch (e) {
89
+ console.error("[insights] Failed to track navigation click", T(e));
90
+ }
91
+ }, a = (n, i = !1, a) => {
92
+ try {
93
+ let o = a ?? m(n);
94
+ if (!o || Date.now() - t < 300) return;
95
+ let s = r(n, i, o), c = F(o);
96
+ e.track("page.click", {
97
+ ...s,
98
+ href: c.href || void 0,
99
+ link_type: c.type || void 0
100
+ });
101
+ } catch (e) {
102
+ console.error("[insights] Failed to track click", T(e));
103
+ }
104
+ }, o = (e) => {
105
+ let t = m(e);
106
+ if (!t) return;
107
+ let r = F(t);
108
+ if (r.type === "external" || r.type === "download") {
109
+ i(e, r, t);
110
+ return;
111
+ }
112
+ if (n) {
113
+ clearTimeout(n), n = null;
114
+ return;
115
+ }
116
+ n = setTimeout(() => {
117
+ a(e, !1, t), n = null;
118
+ }, 250);
119
+ }, s = (e) => {
120
+ n &&= (clearTimeout(n), null), a(e, !0, m(e) ?? void 0);
121
+ }, c = (n) => {
122
+ try {
123
+ let i = m(n);
124
+ if (!i) return;
125
+ t = Date.now();
126
+ let a = F(i);
127
+ if (a.type === "external" || a.type === "download") {
128
+ let t = r(n, !1, i);
129
+ e.track("page.click", {
130
+ ...t,
131
+ href: a.href || void 0,
132
+ link_type: a.type,
133
+ is_navigation: !0,
134
+ is_touch: !0
135
+ });
136
+ return;
137
+ }
138
+ let o = r(n, !1, i);
139
+ e.track("page.click", {
140
+ ...o,
141
+ href: a.href || void 0,
142
+ link_type: a.type || void 0,
143
+ is_touch: !0
144
+ });
145
+ } catch (e) {
146
+ console.error("[insights] Failed to track touch", T(e));
147
+ }
148
+ };
149
+ return document.addEventListener("click", o), document.addEventListener("dblclick", s), document.addEventListener("touchend", c, { passive: !0 }), () => {
150
+ document.removeEventListener("click", o), document.removeEventListener("dblclick", s), document.removeEventListener("touchend", c), n && clearTimeout(n);
151
+ };
152
+ }, L = (e) => {
153
+ if (typeof window > "u") return () => {};
154
+ let t = (t) => (n) => {
155
+ try {
156
+ let r = y(n, t);
157
+ r && e.track("page.copy", r);
158
+ } catch (e) {
159
+ console.error(`[insights] Failed to track clipboard ${t}`, T(e));
160
+ }
161
+ }, n = t("copy"), r = t("cut");
162
+ return document.addEventListener("copy", n, { capture: !0 }), document.addEventListener("cut", r, { capture: !0 }), () => {
163
+ document.removeEventListener("copy", n, { capture: !0 }), document.removeEventListener("cut", r, { capture: !0 });
164
+ };
165
+ }, R = (e) => {
166
+ if (typeof window > "u") return () => {};
167
+ let t = (t) => (n) => {
168
+ try {
169
+ let r = y(n, t);
170
+ if (r) {
171
+ let n = t === "submit" ? "form.submit" : "form.change";
172
+ e.track(n, r);
173
+ }
174
+ } catch (e) {
175
+ console.error(`[insights] Failed to track form ${t}`, T(e));
176
+ }
177
+ }, n = t("change"), r = t("submit");
178
+ return document.addEventListener("change", n, { capture: !0 }), document.addEventListener("submit", r, { capture: !0 }), () => {
179
+ document.removeEventListener("change", n, { capture: !0 }), document.removeEventListener("submit", r, { capture: !0 });
180
+ };
181
+ }, z = (e) => {
182
+ if (typeof window > "u") return () => {};
183
+ let { page_id: t } = p.get(), n = t || "", r = typeof window < "u" ? window.location.href : "", i = () => {
184
+ let { isIdentified: t } = x.get();
185
+ if (t) try {
186
+ e.page({ resource: "page" });
187
+ } catch (e) {
188
+ console.error("[insights] Failed to send page view", T(e));
189
+ }
190
+ };
191
+ if (t) {
192
+ let e = p.listen((e, t, r) => {
193
+ let { page_id: a } = e;
194
+ r === "page_id" && a && n !== a && (n = a, i());
195
+ });
196
+ return () => {
197
+ e();
198
+ };
199
+ } else {
200
+ let e = () => {
201
+ if (typeof window > "u") return;
202
+ let e = window.location.href;
203
+ e !== r && (r = e, i());
204
+ };
205
+ window.addEventListener("popstate", e);
206
+ let t = window.history.pushState;
207
+ return window.history.pushState = function(...n) {
208
+ t.apply(this, n), e();
209
+ }, () => {
210
+ window.removeEventListener("popstate", e), window.history.pushState = t;
211
+ };
212
+ }
213
+ }, B = async (e, t) => {
214
+ let n = null;
215
+ try {
216
+ let r = new AbortController();
217
+ return n = setTimeout(() => r.abort(), t), (await fetch(e, {
218
+ method: "GET",
219
+ signal: r.signal,
220
+ credentials: "omit"
221
+ })).ok;
222
+ } catch {
223
+ return !1;
224
+ } finally {
225
+ n && clearTimeout(n);
226
+ }
227
+ }, V = async (e) => {
228
+ let { mode: t = "auto", insightsUrl: n, directInsightsUrl: r, pingTimeout: i = 1e3, debug: a = !1 } = e;
229
+ if (a) return {
230
+ mode: "proxy",
231
+ url: n || "/debug-api"
232
+ };
233
+ let o = Number.isFinite(i) && i > 0 ? i : 1e3;
234
+ if (t === "direct") return {
235
+ mode: "direct",
236
+ url: r ?? null
237
+ };
238
+ if (t === "proxy" || !r) return {
239
+ mode: "proxy",
240
+ url: n ?? null
241
+ };
242
+ let [s, c] = await Promise.all([n ? B(`${n}/ping`, o) : Promise.resolve(!1), r ? B(`${r}/ping`, o) : Promise.resolve(!1)]);
243
+ return s ? {
244
+ mode: "proxy",
245
+ url: n ?? null
246
+ } : c ? {
247
+ mode: "direct",
248
+ url: r
249
+ } : {
250
+ mode: "proxy",
251
+ url: n ?? null
252
+ };
253
+ }, H = () => {
254
+ if (typeof document > "u") return {};
255
+ let { type: e, referrer: t, data: n = {} } = E({
256
+ referrer: document.referrer,
257
+ currentUrl: window.location.href,
258
+ mapper: null
259
+ }), r = Object.keys(n);
260
+ for (let e of r) n[e] && Array.isArray(n[e]) && n[e].length > 0 && (n[e] = n[e]?.[0]);
261
+ return {
262
+ type: e,
263
+ referrer: t,
264
+ data: n,
265
+ raw: document.referrer
266
+ };
267
+ }, U = () => new Promise((e, t) => {
268
+ let n = "Unknown";
269
+ function r(t) {
270
+ e({
271
+ isPrivate: t,
272
+ browserName: n
273
+ });
274
+ }
275
+ function i() {
276
+ let e = navigator.userAgent;
277
+ return e.match(/Chrome/) ? navigator.brave === void 0 ? e.match(/Edg/) ? "Edge" : e.match(/OPR/) ? "Opera" : "Chrome" : "Brave" : "Chromium";
278
+ }
279
+ function a(e) {
280
+ return e === eval.toString().length;
281
+ }
282
+ function o() {
283
+ let e = navigator.vendor;
284
+ return e !== void 0 && e.indexOf("Apple") === 0 && a(37);
285
+ }
286
+ function s() {
287
+ let e = navigator.vendor;
288
+ return e !== void 0 && e.indexOf("Google") === 0 && a(33);
289
+ }
290
+ function c() {
291
+ return document.documentElement !== void 0 && document.documentElement.style.MozAppearance !== void 0 && a(37);
292
+ }
293
+ function l() {
294
+ return navigator.msSaveBlob !== void 0 && a(39);
295
+ }
296
+ function u() {
297
+ let e = String(Math.random());
298
+ try {
299
+ let t = window.indexedDB.open(e, 1);
300
+ t.onupgradeneeded = (t) => {
301
+ let n = t.target?.result;
302
+ try {
303
+ n.createObjectStore("test", { autoIncrement: !0 }).put(new Blob()), r(!1);
304
+ } catch (e) {
305
+ let t = e;
306
+ return e instanceof Error && (t = e.message ?? e), r(typeof t == "string" ? /BlobURLs are not yet supported/.test(t) : !1);
307
+ } finally {
308
+ n.close(), window.indexedDB.deleteDatabase(e);
309
+ }
310
+ };
311
+ } catch {
312
+ return r(!1);
313
+ }
314
+ }
315
+ function d() {
316
+ let e = window.openDatabase, t = window.localStorage;
317
+ try {
318
+ e(null, null, null, null);
319
+ } catch {
320
+ return r(!0);
321
+ }
322
+ try {
323
+ t.setItem("test", "1"), t.removeItem("test");
324
+ } catch {
325
+ return r(!0);
326
+ }
327
+ return r(!1);
328
+ }
329
+ function f() {
330
+ navigator.maxTouchPoints === void 0 ? d() : u();
331
+ }
332
+ function p() {
333
+ let e = window;
334
+ return e.performance !== void 0 && e.performance.memory !== void 0 && e.performance.memory.jsHeapSizeLimit !== void 0 ? performance.memory.jsHeapSizeLimit : 1073741824;
335
+ }
336
+ function m() {
337
+ navigator.webkitTemporaryStorage.queryUsageAndQuota((e, t) => {
338
+ r(Math.round(t / (1024 * 1024)) < Math.round(p() / (1024 * 1024)) * 2);
339
+ }, (e) => {
340
+ t(/* @__PURE__ */ Error(`detectIncognito somehow failed to query storage quota: ${e.message}`));
341
+ });
342
+ }
343
+ function h() {
344
+ let e = window.webkitRequestFileSystem;
345
+ e(0, 1, () => {
346
+ r(!1);
347
+ }, () => {
348
+ r(!0);
349
+ });
350
+ }
351
+ function g() {
352
+ self.Promise !== void 0 && self.Promise.allSettled !== void 0 ? m() : h();
353
+ }
354
+ function _() {
355
+ r(navigator.serviceWorker === void 0);
356
+ }
357
+ function v() {
358
+ r(window.indexedDB === void 0);
359
+ }
360
+ function y() {
361
+ 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
+ }
363
+ y();
364
+ }), W = () => {
365
+ let e = document.createElement("canvas"), t = e?.getContext("webgl") || e?.getContext("experimental-webgl");
366
+ if (!t) return null;
367
+ let n = t?.getExtension("WEBGL_debug_renderer_info");
368
+ return n ? t?.getParameter(n.UNMASKED_RENDERER_WEBGL) : null;
369
+ }, G = async () => {
370
+ let e = "", t = "", n = !1, r = !1, i = {};
371
+ if (!window) return {
372
+ locale: e,
373
+ timezone: t,
374
+ dark_mode: n,
375
+ private_mode: r,
376
+ properties: i
377
+ };
378
+ let [a, o, s] = await Promise.allSettled([
379
+ U(),
380
+ navigator.getBattery?.() ?? Promise.reject(),
381
+ "mediaDevices" in navigator ? navigator.mediaDevices.enumerateDevices() : Promise.reject()
382
+ ]);
383
+ a.status === "fulfilled" && (r = a.value.isPrivate);
384
+ try {
385
+ n = window.matchMedia?.("(prefers-color-scheme: dark)").matches;
386
+ } catch (e) {
387
+ console.error(e);
388
+ }
389
+ try {
390
+ t = Intl.DateTimeFormat().resolvedOptions().timeZone;
391
+ } catch (e) {
392
+ console.error(e);
393
+ }
394
+ try {
395
+ e = D();
396
+ } catch (e) {
397
+ console.error(e);
398
+ }
399
+ let c = navigator, l = c.connection ?? c.mozConnection ?? c.webkitConnection;
400
+ 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
+ let e = o.value;
402
+ 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;
403
+ }
404
+ 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") {
405
+ let e = s.value;
406
+ i.camera_supported = e.some((e) => e?.kind === "videoinput"), i.microphone_supported = e.some((e) => e?.kind === "audioinput");
407
+ }
408
+ return i.gpu = W(), {
409
+ locale: e,
410
+ timezone: t,
411
+ dark_mode: n,
412
+ private_mode: r,
413
+ properties: i
414
+ };
415
+ }, K = (t, r, i) => {
416
+ let { debug: l } = e();
417
+ if (!t) return null;
418
+ let u = {
419
+ name: t.workspace,
420
+ track: ({ payload: e }) => {
421
+ if (!i()) return;
422
+ let t = e?.properties || {};
423
+ r(e.event, t);
424
+ },
425
+ page: ({ payload: e }) => {
426
+ i() && (o(), r("page.view", {
427
+ ...e?.properties || {},
428
+ resource: "page"
429
+ }));
430
+ },
431
+ identify: ({ payload: r }) => {
432
+ if (!i()) return;
433
+ let { workspace: o, site_id: l, debug: u } = e(), { mode: d, isIdentified: f, isIdentifying: p, sessionToken: m, deviceToken: h, insightsBaseUrl: g, identity: v } = s(), y = _(), b = s().allTabs.length;
434
+ if (!g || !v) return;
435
+ let x = {
436
+ private_mode: r.traits?.private_mode ?? v.privateMode ?? !1,
437
+ dark_mode: r.traits?.dark_mode ?? v.darkMode ?? !1,
438
+ timezone: r.traits?.timezone ?? v.timezone ?? "",
439
+ locale: r.traits?.locale ?? v.locale ?? "",
440
+ referrer: r.traits?.referrer ?? v.referrer ?? {
441
+ type: "",
442
+ referrer: {},
443
+ data: {}
444
+ },
445
+ properties: {
446
+ ...v.properties,
447
+ ...r.traits?.properties
448
+ },
449
+ workspace_id: o ?? "",
450
+ site_id: l ?? void 0,
451
+ hostname: window.location.hostname,
452
+ pathname: window.location.pathname,
453
+ page_title: document.title,
454
+ url: window.location.href,
455
+ created_at: (/* @__PURE__ */ new Date()).toISOString(),
456
+ tab_id: y ?? "",
457
+ tab_count: b ?? 0
458
+ };
459
+ if (u && console.log("[@levo-so/insights] Identification triggered:", {
460
+ isIdentified: f,
461
+ isIdentifying: p,
462
+ welcomeInput: x
463
+ }), f || p) return;
464
+ if (n({ isIdentifying: !0 }), u) {
465
+ console.log("[@levo-so/insights] Debug mode enabled. Mocking session identification."), n({
466
+ isIdentified: !0,
467
+ isIdentifying: !1,
468
+ sessionId: "debug-session",
469
+ deviceId: "debug-device"
470
+ }), C(c());
471
+ return;
472
+ }
473
+ let S = {
474
+ Accept: "application/json",
475
+ "Content-Type": "application/json",
476
+ ...a({
477
+ sessionToken: m,
478
+ deviceToken: h,
479
+ mode: d
480
+ })
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
+ };
512
+ w();
513
+ }
514
+ };
515
+ return O({
516
+ app: t.workspace || "",
517
+ debug: !!l,
518
+ plugins: [u]
519
+ });
520
+ }, q = null, J = !1, Y = [], X = (a, o) => {
521
+ let { insightsUrl: l, debug: p = !1, site: m = null } = o;
522
+ f({
523
+ workspace: a.workspace,
524
+ debug: p,
525
+ site_id: m
526
+ }), typeof window < "u" && Promise.all([G(), H()]).then(([e, t]) => {
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
+ } });
550
+ });
551
+ let y = async (t, n) => {
552
+ if (typeof window > "u") return;
553
+ let { page_id: r } = e(), { allTabs: i } = s(), a = _(), o = i.length;
554
+ S({
555
+ event: t,
556
+ version: n?.version || 1,
557
+ properties: {
558
+ ...n,
559
+ version: void 0,
560
+ resource: void 0,
561
+ identifier: void 0,
562
+ hostname: void 0,
563
+ pathname: void 0,
564
+ url: void 0,
565
+ page_title: void 0,
566
+ created_at: void 0
567
+ },
568
+ hostname: window.location.hostname,
569
+ pathname: window.location.pathname,
570
+ url: n?.url ?? window.location.href,
571
+ page_title: n?.page_title ?? document.title,
572
+ resource: n?.resource ?? "page",
573
+ identifier: n?.id ?? r ?? void 0,
574
+ created_at: n?.created_at ?? (/* @__PURE__ */ new Date()).toISOString(),
575
+ tab_id: a ?? "",
576
+ tab_count: o
577
+ });
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
+ };
584
+ return {
585
+ init: (e = {}) => {
586
+ if (typeof window > "u") throw Error("[@levo-so/insights] init() should only be called on the client side.");
587
+ let { pageId: i } = e;
588
+ if (i && w(i), J || a.NODE_ENV === "development" && !p) return;
589
+ if (!l) {
590
+ console.error("[@levo-so/insights] The utility could not be initialized due to missing insights endpoint.");
591
+ return;
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
+ });
608
+ });
609
+ let r = t.subscribe((e) => {
610
+ if (!(!e || !J) && !q) {
611
+ let e = K(a, y, () => q === e);
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
+ }
614
+ });
615
+ Y.push(r);
616
+ });
617
+ },
618
+ destroy: () => {
619
+ J &&= (C(c()), b(), Y.forEach((e) => {
620
+ e();
621
+ }), Y.length = 0, q = null, !1);
622
+ },
623
+ track: y,
624
+ get instance() {
625
+ return q;
626
+ }
627
+ };
665
628
  };
629
+ //#endregion
630
+ export { w as AnalyticsEvents, X as createLevoInsights };