@levo-so/insights 0.1.111 → 0.2.1

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,4 +1,4 @@
1
- import { A as e, C as t, D as n, E as r, F as i, I as a, L as o, M as s, N as c, O as l, P as u, T as d, _ as f, c as p, d as m, g as h, h as g, i as _, j as v, l as y, n as b, o as x, p as S, s as C, u as w, v as T, w as E, y as ee } from "./textSelection-D9P2LBjT.js";
1
+ import { A as e, C as t, D as n, E as r, F as i, I as a, L as o, M as s, N as c, O as l, P as u, T as d, _ as f, c as p, d as m, g as h, h as g, i as _, j as v, l as y, n as b, o as x, p as S, s as C, u as w, v as T, w as E, y as ee } from "./textSelection-Cwq6lqKg.js";
2
2
  import { AnalyticsEvents as D, getLevoError as O } from "@levo-so/core";
3
3
  import { getVisitorSource as k } from "@analytics/visitor-source";
4
4
  import A from "get-user-locale";
@@ -1,15 +1,13 @@
1
1
  import { ILevoAudience } from '../types/analytics';
2
2
  /**
3
3
  * An event pending delivery in the queue.
4
- * Carries only the data captured at track time; store context (session, workspace, etc.)
5
- * is merged in at flush time by {@link flushEventQueue}.
4
+ *
5
+ * track() captures every per-event field at track time (host/page/tab context,
6
+ * resource, identifier, timestamp), so they are all required here — flush trusts
7
+ * the queued event and does not re-default them. The only fields absent are the
8
+ * session/config ones, which {@link flushEventQueue} merges in at send time.
6
9
  */
7
- type IQueuedEvent = Partial<ILevoAudience.CollectInput> & {
8
- /** The event name (e.g. "page.view", "element.click"). */
9
- event: string;
10
- /** ISO 8601 timestamp when the event was recorded. */
11
- created_at: string;
12
- };
10
+ type IQueuedEvent = Omit<ILevoAudience.CollectInput, "workspace_id" | "site_id" | "session_id" | "device_id">;
13
11
  declare const $eventQueue: import('nanostores').PreinitializedWritableAtom<IQueuedEvent[]> & object;
14
12
  declare const $lifetimePageCount: import('nanostores').PreinitializedWritableAtom<number> & object;
15
13
  declare const $totalEventCount: import('nanostores').ReadableAtom<number>;
package/dist/stores.d.ts CHANGED
@@ -4,6 +4,6 @@ export { $isIdentityContextReady } from './stores/readiness';
4
4
  export { $session } from './stores/session';
5
5
  export { $activity } from './tracking/activity';
6
6
  export { $pageLifecycle } from './tracking/bounce';
7
- export { $currentTab } from './tracking/currentTab';
7
+ export { $currentTab, getTabCount } from './tracking/currentTab';
8
8
  export { $scrollBehavior } from './tracking/scrollBehavior';
9
9
  export { $selectedText } from './tracking/textSelection';
package/dist/stores.js CHANGED
@@ -1,2 +1,2 @@
1
- import { P as e, S as t, _ as n, a as r, b as i, f as a, k as o, m as s, r as c, t as l, x as u } from "./textSelection-D9P2LBjT.js";
2
- export { s as $activity, e as $config, r as $currentTab, i as $eventQueue, n as $isIdentityContextReady, u as $lifetimePageCount, a as $pageLifecycle, c as $scrollBehavior, l as $selectedText, o as $session, t as $totalEventCount };
1
+ import { P as e, S as t, _ as n, a as r, b as i, f as a, k as o, m as s, r as c, s as l, t as u, x as d } from "./textSelection-Cwq6lqKg.js";
2
+ export { s as $activity, e as $config, r as $currentTab, i as $eventQueue, n as $isIdentityContextReady, d as $lifetimePageCount, a as $pageLifecycle, c as $scrollBehavior, u as $selectedText, o as $session, t as $totalEventCount, l as getTabCount };
@@ -111,48 +111,37 @@ var b = () => g.get(), ee = (e) => {
111
111
  ...e
112
112
  });
113
113
  }, te = 10, ne = 2e3, x = 1e3, S = e([]), C = e(0), w = t(S, (e) => e.length ?? 0), T = e(null), E = () => S.get(), re = () => w.get(), D = (e) => {
114
- let { workspace: t, debug: n, site_id: r, page_id: i } = s(), { isIdentified: a, mode: o, sessionId: c, deviceId: l, sessionToken: d, deviceToken: f, insightsBaseUrl: p } = b();
115
- if (e.length === 0 || !a || !p || !t) return;
116
- let m = e.map((e) => ({
114
+ let { workspace: t, debug: n, site_id: r } = s(), { isIdentified: i, mode: a, sessionId: o, deviceId: c, sessionToken: l, deviceToken: d, insightsBaseUrl: f } = b();
115
+ if (e.length === 0 || !i || !f || !t) return;
116
+ let p = e.map((e) => ({
117
117
  workspace_id: t,
118
118
  site_id: r ?? void 0,
119
- session_id: c ?? void 0,
120
- device_id: l ?? void 0,
121
- identifier: i ?? void 0,
122
- hostname: window.location.hostname,
123
- pathname: window.location.pathname,
124
- page_title: document.title,
125
- url: window.location.href,
126
- tab_id: "",
127
- tab_count: 0,
128
- ...e,
129
- event: e.event,
130
- created_at: e.created_at,
131
- resource: e.resource ?? "page",
132
- properties: e.properties ?? {}
119
+ session_id: o ?? void 0,
120
+ device_id: c ?? void 0,
121
+ ...e
133
122
  }));
134
123
  if (S.set([]), n) {
135
- console.log("[@levo-so/insights] Debug mode enabled. Events batch:", m);
124
+ console.log("[@levo-so/insights] Debug mode enabled. Events batch:", p);
136
125
  return;
137
126
  }
138
- let h = new URLSearchParams({ workspace: t });
139
- o === "direct" && (f && h.set("device_token", f), d && h.set("session_token", d));
140
- let g = `${p}/v1/insights/event/bulk?${h.toString()}`;
141
- if (navigator.sendBeacon && navigator.sendBeacon(g, JSON.stringify(m))) return;
142
- let _ = {
127
+ let m = new URLSearchParams({ workspace: t });
128
+ a === "direct" && (d && m.set("device_token", d), l && m.set("session_token", l));
129
+ let h = `${f}/v1/insights/event/bulk?${m.toString()}`;
130
+ if (navigator.sendBeacon && navigator.sendBeacon(h, JSON.stringify(p))) return;
131
+ let g = {
143
132
  "Content-Type": "application/json",
144
133
  ...u({
145
- deviceToken: f,
146
- sessionToken: d,
147
- mode: o
134
+ deviceToken: d,
135
+ sessionToken: l,
136
+ mode: a
148
137
  })
149
138
  };
150
- fetch(g, {
139
+ fetch(h, {
151
140
  method: "POST",
152
- body: JSON.stringify(m),
153
- headers: _,
141
+ body: JSON.stringify(p),
142
+ headers: g,
154
143
  keepalive: !0,
155
- credentials: o === "proxy" ? "include" : "omit"
144
+ credentials: a === "proxy" ? "include" : "omit"
156
145
  }).catch((e) => {
157
146
  console.warn("[@levo-so/insights] Event flush failed, batch lost:", e);
158
147
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@levo-so/insights",
3
3
  "description": "Levo analytics",
4
- "version": "0.1.111",
4
+ "version": "0.2.1",
5
5
  "author": "Levo Engineering <devs@theinternetfolks.com>",
6
6
  "dependencies": {
7
7
  "@analytics/activity-utils": "0.2.2",
@@ -12,13 +12,12 @@
12
12
  "nanostores": "0.11.4"
13
13
  },
14
14
  "devDependencies": {
15
- "@playwright/test": "1.58.2",
16
15
  "@types/lodash-es": "4.17.12",
17
16
  "typescript": "5.9.3",
18
17
  "vite": "8.0.8",
19
18
  "vite-plugin-dts": "4.5.4",
20
19
  "@levo/ts-config": "0.0.0",
21
- "@levo-so/core": "0.1.111"
20
+ "@levo-so/core": "0.2.1"
22
21
  },
23
22
  "exports": {
24
23
  ".": {
@@ -38,7 +37,7 @@
38
37
  "main": "./dist/index.js",
39
38
  "module": "./dist/index.js",
40
39
  "peerDependencies": {
41
- "@levo-so/core": "0.1.111"
40
+ "@levo-so/core": "0.2.1"
42
41
  },
43
42
  "publishConfig": {
44
43
  "access": "public"
@@ -1,66 +0,0 @@
1
- import { STORAGE_KEYS } from '../constants/storageKeys';
2
- import { AnalyticsEventType, ILevoAudience } from '../types/analytics';
3
- export interface PluginContext {
4
- workspace: string;
5
- insightsUrl: string;
6
- site?: string | null;
7
- session: {
8
- get: () => string;
9
- set: (v: string) => void;
10
- };
11
- device: {
12
- get: () => string;
13
- set: (v: string) => void;
14
- };
15
- isIdentified: {
16
- get: () => boolean;
17
- set: (v: boolean) => void;
18
- };
19
- pendingIdentify: {
20
- get: () => boolean;
21
- set: (v: boolean) => void;
22
- };
23
- insightsMode: {
24
- get: () => "proxy" | "direct";
25
- };
26
- getCurrentTabId: () => string;
27
- getTabCount: () => number;
28
- queueEvent: (event: ILevoAudience.CollectInput) => void;
29
- broadcastSession: () => void;
30
- request: <R, T>(url: string, data: T) => Promise<R | null>;
31
- setInStorage: (key: string, value: string) => void;
32
- resetEventCount: () => void;
33
- storage_keys: typeof STORAGE_KEYS;
34
- properties: ILevoAudience.Properties;
35
- track: (event: AnalyticsEventType, props: any) => void;
36
- debugEvents?: {
37
- input: Partial<ILevoAudience.CollectInput>;
38
- payload: ILevoAudience.CollectInput;
39
- queued: boolean;
40
- }[];
41
- }
42
- /**
43
- * Factory function to create the analytics plugin.
44
- * Extracted from initiate() to improve maintainability.
45
- */
46
- export declare const createPlugin: (context: PluginContext) => {
47
- name: string;
48
- /**
49
- * Handle track events (custom events like clicks, scrolls, etc.)
50
- */
51
- track: ({ payload }: {
52
- payload: ILevoAudience.Properties;
53
- }) => void;
54
- /**
55
- * Handle page view events.
56
- */
57
- page: ({ payload }: {
58
- payload: ILevoAudience.EventProperties;
59
- }) => void;
60
- /**
61
- * Handle identify events (session establishment).
62
- */
63
- identify: ({ payload }: {
64
- payload: ILevoAudience.EventProperties;
65
- }) => void;
66
- };