@levo-so/insights 0.1.85 → 0.1.105

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