@levo-so/insights 0.1.82 → 0.1.86

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,623 @@
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, x, y as S } from "./textSelection-DC99Tbqq.js";
2
+ import { AnalyticsEvents as C, getLevoError as w } from "@levo-so/core";
3
+ import { getVisitorSource as T } from "@analytics/visitor-source";
4
+ import E from "get-user-locale";
5
+ import { Analytics as D } from "analytics";
6
+ //#region src/utils/rageclick.ts
7
+ var O = 30, k = 1e3, A = 3, j = [], M = (e, t, n) => {
8
+ let r = j[j.length - 1];
9
+ if (r && Math.abs(e - r.x) + Math.abs(t - r.y) < O && n - r.timestamp < k) {
10
+ if (j.push({
11
+ x: e,
12
+ y: t,
13
+ timestamp: n
14
+ }), j.length >= A) return j = [], !0;
15
+ } else j = [{
16
+ x: e,
17
+ y: t,
18
+ timestamp: n
19
+ }];
20
+ return !1;
21
+ }, N = (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
+ }, P = (e) => {
30
+ let t = e.closest("a[href]"), n = t?.getAttribute("href") || N(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", w(e)), {
58
+ type: "internal",
59
+ href: n
60
+ };
61
+ }
62
+ }, F = (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 = M(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", w(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 = P(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", w(e));
103
+ }
104
+ }, o = (e) => {
105
+ let t = m(e);
106
+ if (!t) return;
107
+ let r = P(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 = P(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", w(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
+ }, I = (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}`, w(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
+ }, L = (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}`, w(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
+ }, R = (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
+ try {
185
+ e.page({ resource: "page" });
186
+ } catch (e) {
187
+ console.error("[insights] Failed to send page view", w(e));
188
+ }
189
+ };
190
+ if (t) {
191
+ let e = p.listen((e, t, r) => {
192
+ let { page_id: a } = e;
193
+ r === "page_id" && a && n !== a && (n = a, i());
194
+ });
195
+ return () => {
196
+ e();
197
+ };
198
+ } else {
199
+ let e = () => {
200
+ if (typeof window > "u") return;
201
+ let e = window.location.href;
202
+ e !== r && (r = e, i());
203
+ };
204
+ window.addEventListener("popstate", e);
205
+ let t = window.history.pushState;
206
+ return window.history.pushState = function(...n) {
207
+ t.apply(this, n), e();
208
+ }, () => {
209
+ window.removeEventListener("popstate", e), window.history.pushState = t;
210
+ };
211
+ }
212
+ }, z = async (e, t) => {
213
+ let n = null;
214
+ try {
215
+ let r = new AbortController();
216
+ return n = setTimeout(() => r.abort(), t), (await fetch(e, {
217
+ method: "GET",
218
+ signal: r.signal,
219
+ credentials: "omit"
220
+ })).ok;
221
+ } catch {
222
+ return !1;
223
+ } finally {
224
+ n && clearTimeout(n);
225
+ }
226
+ }, B = async (e) => {
227
+ let { mode: t = "auto", insightsUrl: n, directInsightsUrl: r, pingTimeout: i = 1e3, debug: a = !1 } = e;
228
+ if (a) return {
229
+ mode: "proxy",
230
+ url: n || "/debug-api"
231
+ };
232
+ let o = Number.isFinite(i) && i > 0 ? i : 1e3;
233
+ if (t === "direct") return {
234
+ mode: "direct",
235
+ url: r ?? null
236
+ };
237
+ if (t === "proxy" || !r) return {
238
+ mode: "proxy",
239
+ url: n ?? null
240
+ };
241
+ let [s, c] = await Promise.all([n ? z(`${n}/ping`, o) : Promise.resolve(!1), r ? z(`${r}/ping`, o) : Promise.resolve(!1)]);
242
+ return s ? {
243
+ mode: "proxy",
244
+ url: n ?? null
245
+ } : c ? {
246
+ mode: "direct",
247
+ url: r
248
+ } : {
249
+ mode: "proxy",
250
+ url: n ?? null
251
+ };
252
+ }, V = () => {
253
+ if (typeof document > "u") return {};
254
+ let { type: e, referrer: t, data: n = {} } = T({
255
+ referrer: document.referrer,
256
+ currentUrl: window.location.href,
257
+ mapper: null
258
+ }), r = Object.keys(n);
259
+ for (let e of r) n[e] && Array.isArray(n[e]) && n[e].length > 0 && (n[e] = n[e]?.[0]);
260
+ return {
261
+ type: e,
262
+ referrer: t,
263
+ data: n,
264
+ raw: document.referrer
265
+ };
266
+ }, H = () => new Promise((e, t) => {
267
+ let n = "Unknown";
268
+ function r(t) {
269
+ e({
270
+ isPrivate: t,
271
+ browserName: n
272
+ });
273
+ }
274
+ function i() {
275
+ let e = navigator.userAgent;
276
+ return e.match(/Chrome/) ? navigator.brave === void 0 ? e.match(/Edg/) ? "Edge" : e.match(/OPR/) ? "Opera" : "Chrome" : "Brave" : "Chromium";
277
+ }
278
+ function a(e) {
279
+ return e === eval.toString().length;
280
+ }
281
+ function o() {
282
+ let e = navigator.vendor;
283
+ return e !== void 0 && e.indexOf("Apple") === 0 && a(37);
284
+ }
285
+ function s() {
286
+ let e = navigator.vendor;
287
+ return e !== void 0 && e.indexOf("Google") === 0 && a(33);
288
+ }
289
+ function c() {
290
+ return document.documentElement !== void 0 && document.documentElement.style.MozAppearance !== void 0 && a(37);
291
+ }
292
+ function l() {
293
+ return navigator.msSaveBlob !== void 0 && a(39);
294
+ }
295
+ function u() {
296
+ let e = String(Math.random());
297
+ try {
298
+ let t = window.indexedDB.open(e, 1);
299
+ t.onupgradeneeded = (t) => {
300
+ let n = t.target?.result;
301
+ try {
302
+ n.createObjectStore("test", { autoIncrement: !0 }).put(new Blob()), r(!1);
303
+ } catch (e) {
304
+ let t = e;
305
+ return e instanceof Error && (t = e.message ?? e), r(typeof t == "string" ? /BlobURLs are not yet supported/.test(t) : !1);
306
+ } finally {
307
+ n.close(), window.indexedDB.deleteDatabase(e);
308
+ }
309
+ };
310
+ } catch {
311
+ return r(!1);
312
+ }
313
+ }
314
+ function d() {
315
+ let e = window.openDatabase, t = window.localStorage;
316
+ try {
317
+ e(null, null, null, null);
318
+ } catch {
319
+ return r(!0);
320
+ }
321
+ try {
322
+ t.setItem("test", "1"), t.removeItem("test");
323
+ } catch {
324
+ return r(!0);
325
+ }
326
+ return r(!1);
327
+ }
328
+ function f() {
329
+ navigator.maxTouchPoints === void 0 ? d() : u();
330
+ }
331
+ function p() {
332
+ let e = window;
333
+ return e.performance !== void 0 && e.performance.memory !== void 0 && e.performance.memory.jsHeapSizeLimit !== void 0 ? performance.memory.jsHeapSizeLimit : 1073741824;
334
+ }
335
+ function m() {
336
+ navigator.webkitTemporaryStorage.queryUsageAndQuota((e, t) => {
337
+ r(Math.round(t / (1024 * 1024)) < Math.round(p() / (1024 * 1024)) * 2);
338
+ }, (e) => {
339
+ t(/* @__PURE__ */ Error(`detectIncognito somehow failed to query storage quota: ${e.message}`));
340
+ });
341
+ }
342
+ function h() {
343
+ let e = window.webkitRequestFileSystem;
344
+ e(0, 1, () => {
345
+ r(!1);
346
+ }, () => {
347
+ r(!0);
348
+ });
349
+ }
350
+ function g() {
351
+ self.Promise !== void 0 && self.Promise.allSettled !== void 0 ? m() : h();
352
+ }
353
+ function _() {
354
+ r(navigator.serviceWorker === void 0);
355
+ }
356
+ function v() {
357
+ r(window.indexedDB === void 0);
358
+ }
359
+ function y() {
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
+ }
362
+ y();
363
+ }), U = () => {
364
+ let e = document.createElement("canvas"), t = e?.getContext("webgl") || e?.getContext("experimental-webgl");
365
+ if (!t) return null;
366
+ let n = t?.getExtension("WEBGL_debug_renderer_info");
367
+ return n ? t?.getParameter(n.UNMASKED_RENDERER_WEBGL) : null;
368
+ }, W = async () => {
369
+ let e = "", t = "", n = !1, r = !1, i = {};
370
+ if (!window) return {
371
+ locale: e,
372
+ timezone: t,
373
+ dark_mode: n,
374
+ private_mode: r,
375
+ properties: i
376
+ };
377
+ let [a, o, s] = await Promise.allSettled([
378
+ H(),
379
+ navigator.getBattery?.() ?? Promise.reject(),
380
+ "mediaDevices" in navigator ? navigator.mediaDevices.enumerateDevices() : Promise.reject()
381
+ ]);
382
+ a.status === "fulfilled" && (r = a.value.isPrivate);
383
+ try {
384
+ n = window.matchMedia?.("(prefers-color-scheme: dark)").matches;
385
+ } catch {}
386
+ try {
387
+ t = Intl.DateTimeFormat().resolvedOptions().timeZone;
388
+ } catch {}
389
+ try {
390
+ e = E();
391
+ } catch {}
392
+ let c = navigator, l = c.connection ?? c.mozConnection ?? c.webkitConnection;
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") {
394
+ let e = o.value;
395
+ 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;
396
+ }
397
+ 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") {
398
+ let e = s.value;
399
+ i.camera_supported = e.some((e) => e?.kind === "videoinput"), i.microphone_supported = e.some((e) => e?.kind === "audioinput");
400
+ }
401
+ return i.gpu = U(), {
402
+ locale: e,
403
+ timezone: t,
404
+ dark_mode: n,
405
+ private_mode: r,
406
+ properties: i
407
+ };
408
+ }, G = (t, r, i) => {
409
+ let { debug: l } = e();
410
+ if (!t) return null;
411
+ let u = {
412
+ name: t.workspace,
413
+ track: ({ payload: e }) => {
414
+ if (!i()) return;
415
+ let t = e?.properties || {};
416
+ r(e.event, t);
417
+ },
418
+ page: ({ payload: e }) => {
419
+ i() && (o(), r("page.view", {
420
+ ...e?.properties || {},
421
+ resource: "page"
422
+ }));
423
+ },
424
+ identify: ({ payload: r }) => {
425
+ if (!i()) return;
426
+ 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;
427
+ if (!g || !v) return;
428
+ let x = {
429
+ private_mode: r.traits?.private_mode ?? v.privateMode ?? !1,
430
+ dark_mode: r.traits?.dark_mode ?? v.darkMode ?? !1,
431
+ timezone: r.traits?.timezone ?? v.timezone ?? "",
432
+ locale: r.traits?.locale ?? v.locale ?? "",
433
+ referrer: r.traits?.referrer ?? v.referrer ?? {
434
+ type: "",
435
+ referrer: {},
436
+ data: {}
437
+ },
438
+ properties: {
439
+ ...v.properties,
440
+ ...r.traits?.properties
441
+ },
442
+ workspace_id: o ?? "",
443
+ site_id: l ?? void 0,
444
+ hostname: window.location.hostname,
445
+ pathname: window.location.pathname,
446
+ page_title: document.title,
447
+ url: window.location.href,
448
+ created_at: (/* @__PURE__ */ new Date()).toISOString(),
449
+ tab_id: y ?? "",
450
+ tab_count: b ?? 0
451
+ };
452
+ if (u && console.log("[@levo-so/insights] Identification triggered:", {
453
+ isIdentified: f,
454
+ isIdentifying: p,
455
+ welcomeInput: x
456
+ }), f || p) return;
457
+ if (n({ isIdentifying: !0 }), u) {
458
+ console.log("[@levo-so/insights] Debug mode enabled. Mocking session identification."), n({
459
+ isIdentified: !0,
460
+ isIdentifying: !1,
461
+ sessionId: "debug-session",
462
+ deviceId: "debug-device"
463
+ }), S(c());
464
+ return;
465
+ }
466
+ let C = {
467
+ Accept: "application/json",
468
+ "Content-Type": "application/json",
469
+ ...a({
470
+ sessionToken: m,
471
+ deviceToken: h,
472
+ mode: d
473
+ })
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
+ };
505
+ T();
506
+ }
507
+ };
508
+ return D({
509
+ app: t.workspace || "",
510
+ debug: !!l,
511
+ plugins: [u]
512
+ });
513
+ }, K = null, q = !1, J = [], Y = (a, o) => {
514
+ let { insightsUrl: l, debug: p = !1, site: m = null } = o;
515
+ f({
516
+ workspace: a.workspace,
517
+ debug: p,
518
+ site_id: m
519
+ }), typeof window < "u" && Promise.all([W(), V()]).then(([e, t]) => {
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
+ } });
543
+ });
544
+ let y = async (t, n) => {
545
+ if (typeof window > "u") return;
546
+ let { page_id: r } = e(), { allTabs: i } = s(), a = _(), o = i.length;
547
+ x({
548
+ event: t,
549
+ version: n?.version || 1,
550
+ properties: {
551
+ ...n,
552
+ version: void 0,
553
+ resource: void 0,
554
+ identifier: void 0,
555
+ hostname: void 0,
556
+ pathname: void 0,
557
+ url: void 0,
558
+ page_title: void 0,
559
+ created_at: void 0
560
+ },
561
+ hostname: window.location.hostname,
562
+ pathname: window.location.pathname,
563
+ url: n?.url ?? window.location.href,
564
+ page_title: n?.page_title ?? document.title,
565
+ resource: n?.resource ?? "page",
566
+ identifier: n?.id ?? r ?? void 0,
567
+ created_at: n?.created_at ?? (/* @__PURE__ */ new Date()).toISOString(),
568
+ tab_id: a ?? "",
569
+ tab_count: o
570
+ });
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
+ };
577
+ return {
578
+ init: (e = {}) => {
579
+ if (typeof window > "u") throw Error("[@levo-so/insights] init() should only be called on the client side.");
580
+ let { pageId: i } = e;
581
+ if (i && w(i), q || a.NODE_ENV === "development" && !p) return;
582
+ if (!l) {
583
+ console.error("[@levo-so/insights] The utility could not be initialized due to missing insights endpoint.");
584
+ return;
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
+ });
601
+ });
602
+ let r = t.subscribe((e) => {
603
+ if (!(!e || !q) && !K) {
604
+ let e = G(a, y, () => K === e);
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
+ }
607
+ });
608
+ J.push(r);
609
+ });
610
+ },
611
+ destroy: () => {
612
+ q &&= (S(c()), b(), J.forEach((e) => {
613
+ e();
614
+ }), J.length = 0, K = null, !1);
615
+ },
616
+ track: y,
617
+ get instance() {
618
+ return K;
619
+ }
620
+ };
665
621
  };
622
+ //#endregion
623
+ export { C as AnalyticsEvents, Y as createLevoInsights };