@plasius/analytics 1.0.0
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/LICENSE +203 -0
- package/README.md +128 -0
- package/dist/index.cjs +457 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +94 -0
- package/dist/index.d.ts +94 -0
- package/dist/index.js +426 -0
- package/dist/index.js.map +1 -0
- package/package.json +86 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
// src/core/client.ts
|
|
2
|
+
var DEFAULT_FLUSH_INTERVAL_MS = 5e3;
|
|
3
|
+
var DEFAULT_BATCH_SIZE = 20;
|
|
4
|
+
var DEFAULT_MAX_QUEUE_SIZE = 500;
|
|
5
|
+
var DEFAULT_STORAGE_KEY = "plasius.analytics.local-space.queue";
|
|
6
|
+
var JSON_CONTENT_TYPE_HEADER = "application/json";
|
|
7
|
+
function createId(prefix) {
|
|
8
|
+
return `${prefix}_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 10)}`;
|
|
9
|
+
}
|
|
10
|
+
async function defaultTransport({
|
|
11
|
+
endpoint,
|
|
12
|
+
body,
|
|
13
|
+
headers,
|
|
14
|
+
keepalive
|
|
15
|
+
}) {
|
|
16
|
+
if (typeof fetch !== "function") {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const response = await fetch(endpoint, {
|
|
20
|
+
method: "POST",
|
|
21
|
+
headers,
|
|
22
|
+
body,
|
|
23
|
+
keepalive
|
|
24
|
+
});
|
|
25
|
+
if (!response.ok) {
|
|
26
|
+
throw new Error(`Analytics transport failed with status ${response.status}.`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function toPositiveInteger(value, fallback) {
|
|
30
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
31
|
+
return fallback;
|
|
32
|
+
}
|
|
33
|
+
const rounded = Math.floor(value);
|
|
34
|
+
return rounded > 0 ? rounded : fallback;
|
|
35
|
+
}
|
|
36
|
+
function resolveConfig(config, previous) {
|
|
37
|
+
const source = (config.source ?? previous?.source ?? "").trim();
|
|
38
|
+
if (!source) {
|
|
39
|
+
throw new Error("Local space analytics requires a non-empty source.");
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
source,
|
|
43
|
+
endpoint: config.endpoint?.trim(),
|
|
44
|
+
enabled: config.enabled ?? previous?.enabled ?? true,
|
|
45
|
+
defaultContext: {
|
|
46
|
+
...previous?.defaultContext ?? {},
|
|
47
|
+
...config.defaultContext ?? {}
|
|
48
|
+
},
|
|
49
|
+
headers: {
|
|
50
|
+
"content-type": JSON_CONTENT_TYPE_HEADER,
|
|
51
|
+
...previous?.headers ?? {},
|
|
52
|
+
...config.headers ?? {}
|
|
53
|
+
},
|
|
54
|
+
flushIntervalMs: toPositiveInteger(
|
|
55
|
+
config.flushIntervalMs ?? previous?.flushIntervalMs,
|
|
56
|
+
DEFAULT_FLUSH_INTERVAL_MS
|
|
57
|
+
),
|
|
58
|
+
batchSize: toPositiveInteger(config.batchSize ?? previous?.batchSize, DEFAULT_BATCH_SIZE),
|
|
59
|
+
maxQueueSize: toPositiveInteger(
|
|
60
|
+
config.maxQueueSize ?? previous?.maxQueueSize,
|
|
61
|
+
DEFAULT_MAX_QUEUE_SIZE
|
|
62
|
+
),
|
|
63
|
+
storageKey: (config.storageKey ?? previous?.storageKey ?? DEFAULT_STORAGE_KEY).trim(),
|
|
64
|
+
transport: config.transport ?? previous?.transport ?? defaultTransport,
|
|
65
|
+
onError: config.onError ?? previous?.onError
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
function isBrowserEnvironment() {
|
|
69
|
+
return typeof window !== "undefined" && typeof document !== "undefined";
|
|
70
|
+
}
|
|
71
|
+
function readQueue(storageKey) {
|
|
72
|
+
if (!isBrowserEnvironment() || typeof window.localStorage === "undefined") {
|
|
73
|
+
return [];
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
const rawValue = window.localStorage.getItem(storageKey);
|
|
77
|
+
if (!rawValue) {
|
|
78
|
+
return [];
|
|
79
|
+
}
|
|
80
|
+
const parsed = JSON.parse(rawValue);
|
|
81
|
+
if (!Array.isArray(parsed)) {
|
|
82
|
+
return [];
|
|
83
|
+
}
|
|
84
|
+
return parsed.filter(isStoredRecordCandidate);
|
|
85
|
+
} catch {
|
|
86
|
+
return [];
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function isStoredRecordCandidate(value) {
|
|
90
|
+
if (!value || typeof value !== "object") {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
const candidate = value;
|
|
94
|
+
return typeof candidate.id === "string" && typeof candidate.component === "string" && typeof candidate.action === "string" && typeof candidate.source === "string" && typeof candidate.sessionId === "string" && typeof candidate.timestamp === "number";
|
|
95
|
+
}
|
|
96
|
+
function writeQueue(storageKey, queue) {
|
|
97
|
+
if (!isBrowserEnvironment() || typeof window.localStorage === "undefined") {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
try {
|
|
101
|
+
if (queue.length === 0) {
|
|
102
|
+
window.localStorage.removeItem(storageKey);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
window.localStorage.setItem(storageKey, JSON.stringify(queue));
|
|
106
|
+
} catch {
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function createPayload(source, events) {
|
|
110
|
+
return JSON.stringify({
|
|
111
|
+
source,
|
|
112
|
+
sentAt: Date.now(),
|
|
113
|
+
events
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
function createLocalSpaceAnalyticsClient(config) {
|
|
117
|
+
let resolvedConfig = resolveConfig(config);
|
|
118
|
+
const sessionId = createId("session");
|
|
119
|
+
let queue = readQueue(resolvedConfig.storageKey).slice(-resolvedConfig.maxQueueSize);
|
|
120
|
+
let flushTimer = null;
|
|
121
|
+
let isFlushing = false;
|
|
122
|
+
let flushQueuedAfterCurrent = false;
|
|
123
|
+
let isDestroyed = false;
|
|
124
|
+
const persistQueue = () => writeQueue(resolvedConfig.storageKey, queue);
|
|
125
|
+
const trimQueue = () => {
|
|
126
|
+
if (queue.length <= resolvedConfig.maxQueueSize) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
queue = queue.slice(queue.length - resolvedConfig.maxQueueSize);
|
|
130
|
+
};
|
|
131
|
+
const flushWithBeacon = () => {
|
|
132
|
+
if (!resolvedConfig.endpoint || queue.length === 0) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
if (typeof navigator === "undefined" || typeof navigator.sendBeacon !== "function") {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
const events = queue.slice(0, resolvedConfig.batchSize);
|
|
139
|
+
try {
|
|
140
|
+
const body = createPayload(resolvedConfig.source, events);
|
|
141
|
+
const blob = new Blob([body], { type: JSON_CONTENT_TYPE_HEADER });
|
|
142
|
+
const sent = navigator.sendBeacon(resolvedConfig.endpoint, blob);
|
|
143
|
+
if (sent) {
|
|
144
|
+
queue = queue.slice(events.length);
|
|
145
|
+
persistQueue();
|
|
146
|
+
}
|
|
147
|
+
return sent;
|
|
148
|
+
} catch {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
const flush = async () => {
|
|
153
|
+
if (isDestroyed || !resolvedConfig.enabled || !resolvedConfig.endpoint) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (queue.length === 0) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (isFlushing) {
|
|
160
|
+
flushQueuedAfterCurrent = true;
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const events = queue.slice(0, resolvedConfig.batchSize);
|
|
164
|
+
const body = createPayload(resolvedConfig.source, events);
|
|
165
|
+
isFlushing = true;
|
|
166
|
+
try {
|
|
167
|
+
await resolvedConfig.transport({
|
|
168
|
+
endpoint: resolvedConfig.endpoint,
|
|
169
|
+
body,
|
|
170
|
+
headers: resolvedConfig.headers,
|
|
171
|
+
keepalive: true
|
|
172
|
+
});
|
|
173
|
+
queue = queue.slice(events.length);
|
|
174
|
+
persistQueue();
|
|
175
|
+
} catch (error) {
|
|
176
|
+
resolvedConfig.onError?.(error);
|
|
177
|
+
} finally {
|
|
178
|
+
isFlushing = false;
|
|
179
|
+
if (flushQueuedAfterCurrent) {
|
|
180
|
+
flushQueuedAfterCurrent = false;
|
|
181
|
+
if (queue.length > 0) {
|
|
182
|
+
void flush();
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
const startFlushTimer = () => {
|
|
188
|
+
if (flushTimer) {
|
|
189
|
+
clearInterval(flushTimer);
|
|
190
|
+
flushTimer = null;
|
|
191
|
+
}
|
|
192
|
+
if (!resolvedConfig.enabled) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
flushTimer = setInterval(() => {
|
|
196
|
+
void flush();
|
|
197
|
+
}, resolvedConfig.flushIntervalMs);
|
|
198
|
+
};
|
|
199
|
+
const handleVisibilityChange = () => {
|
|
200
|
+
if (typeof document === "undefined") {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
if (document.visibilityState !== "hidden") {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
if (!flushWithBeacon()) {
|
|
207
|
+
void flush();
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
const handlePageHide = () => {
|
|
211
|
+
if (!flushWithBeacon()) {
|
|
212
|
+
void flush();
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
if (isBrowserEnvironment()) {
|
|
216
|
+
document.addEventListener("visibilitychange", handleVisibilityChange);
|
|
217
|
+
window.addEventListener("pagehide", handlePageHide);
|
|
218
|
+
}
|
|
219
|
+
startFlushTimer();
|
|
220
|
+
return {
|
|
221
|
+
get source() {
|
|
222
|
+
return resolvedConfig.source;
|
|
223
|
+
},
|
|
224
|
+
track(event) {
|
|
225
|
+
if (isDestroyed || !resolvedConfig.enabled) {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
const record = {
|
|
229
|
+
id: createId("event"),
|
|
230
|
+
component: event.component,
|
|
231
|
+
action: event.action,
|
|
232
|
+
label: event.label,
|
|
233
|
+
href: event.href,
|
|
234
|
+
variant: event.variant,
|
|
235
|
+
source: resolvedConfig.source,
|
|
236
|
+
sessionId,
|
|
237
|
+
timestamp: event.timestamp ?? Date.now(),
|
|
238
|
+
context: {
|
|
239
|
+
...resolvedConfig.defaultContext,
|
|
240
|
+
...event.context ?? {}
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
queue.push(record);
|
|
244
|
+
trimQueue();
|
|
245
|
+
persistQueue();
|
|
246
|
+
if (queue.length >= resolvedConfig.batchSize) {
|
|
247
|
+
void flush();
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
flush,
|
|
251
|
+
updateConfig(nextConfig) {
|
|
252
|
+
if (isDestroyed) {
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
const previousStorageKey = resolvedConfig.storageKey;
|
|
256
|
+
resolvedConfig = resolveConfig(
|
|
257
|
+
{
|
|
258
|
+
...resolvedConfig,
|
|
259
|
+
...nextConfig,
|
|
260
|
+
source: nextConfig.source ?? resolvedConfig.source
|
|
261
|
+
},
|
|
262
|
+
resolvedConfig
|
|
263
|
+
);
|
|
264
|
+
if (previousStorageKey !== resolvedConfig.storageKey) {
|
|
265
|
+
writeQueue(previousStorageKey, []);
|
|
266
|
+
persistQueue();
|
|
267
|
+
}
|
|
268
|
+
startFlushTimer();
|
|
269
|
+
if (resolvedConfig.endpoint && queue.length > 0) {
|
|
270
|
+
void flush();
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
getConfig() {
|
|
274
|
+
return resolvedConfig;
|
|
275
|
+
},
|
|
276
|
+
destroy() {
|
|
277
|
+
if (isDestroyed) {
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
isDestroyed = true;
|
|
281
|
+
if (flushTimer) {
|
|
282
|
+
clearInterval(flushTimer);
|
|
283
|
+
flushTimer = null;
|
|
284
|
+
}
|
|
285
|
+
if (isBrowserEnvironment()) {
|
|
286
|
+
document.removeEventListener("visibilitychange", handleVisibilityChange);
|
|
287
|
+
window.removeEventListener("pagehide", handlePageHide);
|
|
288
|
+
}
|
|
289
|
+
void flush();
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
function createNoopLocalSpaceAnalyticsClient(source = "noop") {
|
|
294
|
+
const noopConfig = {
|
|
295
|
+
source,
|
|
296
|
+
enabled: false,
|
|
297
|
+
endpoint: void 0,
|
|
298
|
+
defaultContext: {},
|
|
299
|
+
headers: { "content-type": JSON_CONTENT_TYPE_HEADER },
|
|
300
|
+
flushIntervalMs: DEFAULT_FLUSH_INTERVAL_MS,
|
|
301
|
+
batchSize: DEFAULT_BATCH_SIZE,
|
|
302
|
+
maxQueueSize: DEFAULT_MAX_QUEUE_SIZE,
|
|
303
|
+
storageKey: DEFAULT_STORAGE_KEY,
|
|
304
|
+
transport: async () => void 0,
|
|
305
|
+
onError: void 0
|
|
306
|
+
};
|
|
307
|
+
return {
|
|
308
|
+
source,
|
|
309
|
+
track: () => void 0,
|
|
310
|
+
flush: async () => void 0,
|
|
311
|
+
updateConfig: () => void 0,
|
|
312
|
+
getConfig: () => noopConfig,
|
|
313
|
+
destroy: () => void 0
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// src/react/provider.tsx
|
|
318
|
+
import { createContext, useContext, useEffect, useMemo } from "react";
|
|
319
|
+
import { jsx } from "react/jsx-runtime";
|
|
320
|
+
var AnalyticsContext = createContext(null);
|
|
321
|
+
function AnalyticsProvider({
|
|
322
|
+
children,
|
|
323
|
+
source = "react-app",
|
|
324
|
+
endpoint,
|
|
325
|
+
enabled = true,
|
|
326
|
+
defaultContext,
|
|
327
|
+
headers,
|
|
328
|
+
flushIntervalMs,
|
|
329
|
+
batchSize,
|
|
330
|
+
maxQueueSize,
|
|
331
|
+
storageKey,
|
|
332
|
+
transport,
|
|
333
|
+
onError,
|
|
334
|
+
client
|
|
335
|
+
}) {
|
|
336
|
+
const managedClient = useMemo(() => {
|
|
337
|
+
if (client) {
|
|
338
|
+
return client;
|
|
339
|
+
}
|
|
340
|
+
if (!enabled) {
|
|
341
|
+
return createNoopLocalSpaceAnalyticsClient(source);
|
|
342
|
+
}
|
|
343
|
+
return createLocalSpaceAnalyticsClient({
|
|
344
|
+
source,
|
|
345
|
+
endpoint,
|
|
346
|
+
enabled,
|
|
347
|
+
defaultContext,
|
|
348
|
+
headers,
|
|
349
|
+
flushIntervalMs,
|
|
350
|
+
batchSize,
|
|
351
|
+
maxQueueSize,
|
|
352
|
+
storageKey,
|
|
353
|
+
transport,
|
|
354
|
+
onError
|
|
355
|
+
});
|
|
356
|
+
}, [
|
|
357
|
+
client,
|
|
358
|
+
source,
|
|
359
|
+
endpoint,
|
|
360
|
+
enabled,
|
|
361
|
+
defaultContext,
|
|
362
|
+
headers,
|
|
363
|
+
flushIntervalMs,
|
|
364
|
+
batchSize,
|
|
365
|
+
maxQueueSize,
|
|
366
|
+
storageKey,
|
|
367
|
+
transport,
|
|
368
|
+
onError
|
|
369
|
+
]);
|
|
370
|
+
useEffect(() => {
|
|
371
|
+
return () => {
|
|
372
|
+
if (!client) {
|
|
373
|
+
managedClient.destroy();
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
}, [client, managedClient]);
|
|
377
|
+
const value = useMemo(
|
|
378
|
+
() => ({
|
|
379
|
+
client: managedClient,
|
|
380
|
+
trackInteraction: (event) => {
|
|
381
|
+
managedClient.track(event);
|
|
382
|
+
},
|
|
383
|
+
flush: () => managedClient.flush()
|
|
384
|
+
}),
|
|
385
|
+
[managedClient]
|
|
386
|
+
);
|
|
387
|
+
return /* @__PURE__ */ jsx(AnalyticsContext.Provider, { value, children });
|
|
388
|
+
}
|
|
389
|
+
function useAnalytics() {
|
|
390
|
+
const context = useContext(AnalyticsContext);
|
|
391
|
+
if (!context) {
|
|
392
|
+
throw new Error("useAnalytics must be used within AnalyticsProvider.");
|
|
393
|
+
}
|
|
394
|
+
return context;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// src/react/hooks.ts
|
|
398
|
+
import { useCallback } from "react";
|
|
399
|
+
function useComponentInteractionTracker(component, baseContext = {}) {
|
|
400
|
+
const { trackInteraction } = useAnalytics();
|
|
401
|
+
return useCallback(
|
|
402
|
+
(action, details) => {
|
|
403
|
+
trackInteraction({
|
|
404
|
+
component,
|
|
405
|
+
action,
|
|
406
|
+
label: details?.label,
|
|
407
|
+
href: details?.href,
|
|
408
|
+
variant: details?.variant,
|
|
409
|
+
timestamp: details?.timestamp,
|
|
410
|
+
context: {
|
|
411
|
+
...baseContext,
|
|
412
|
+
...details?.context ?? {}
|
|
413
|
+
}
|
|
414
|
+
});
|
|
415
|
+
},
|
|
416
|
+
[baseContext, component, trackInteraction]
|
|
417
|
+
);
|
|
418
|
+
}
|
|
419
|
+
export {
|
|
420
|
+
AnalyticsProvider,
|
|
421
|
+
createLocalSpaceAnalyticsClient,
|
|
422
|
+
createNoopLocalSpaceAnalyticsClient,
|
|
423
|
+
useAnalytics,
|
|
424
|
+
useComponentInteractionTracker
|
|
425
|
+
};
|
|
426
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/client.ts","../src/react/provider.tsx","../src/react/hooks.ts"],"sourcesContent":["import type {\n AnalyticsTransport,\n LocalSpaceAnalyticsClient,\n LocalSpaceAnalyticsConfig,\n LocalSpaceAnalyticsEvent,\n LocalSpaceAnalyticsRecord,\n ResolvedLocalSpaceAnalyticsConfig,\n} from \"./types.js\";\n\nconst DEFAULT_FLUSH_INTERVAL_MS = 5000;\nconst DEFAULT_BATCH_SIZE = 20;\nconst DEFAULT_MAX_QUEUE_SIZE = 500;\nconst DEFAULT_STORAGE_KEY = \"plasius.analytics.local-space.queue\";\n\nconst JSON_CONTENT_TYPE_HEADER = \"application/json\";\n\nfunction createId(prefix: string): string {\n return `${prefix}_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 10)}`;\n}\n\nasync function defaultTransport({\n endpoint,\n body,\n headers,\n keepalive,\n}: {\n endpoint: string;\n body: string;\n headers: Record<string, string>;\n keepalive: boolean;\n}): Promise<void> {\n if (typeof fetch !== \"function\") {\n return;\n }\n\n const response = await fetch(endpoint, {\n method: \"POST\",\n headers,\n body,\n keepalive,\n });\n\n if (!response.ok) {\n throw new Error(`Analytics transport failed with status ${response.status}.`);\n }\n}\n\nfunction toPositiveInteger(value: number | undefined, fallback: number): number {\n if (typeof value !== \"number\" || !Number.isFinite(value)) {\n return fallback;\n }\n\n const rounded = Math.floor(value);\n return rounded > 0 ? rounded : fallback;\n}\n\nfunction resolveConfig(\n config: LocalSpaceAnalyticsConfig,\n previous?: ResolvedLocalSpaceAnalyticsConfig\n): ResolvedLocalSpaceAnalyticsConfig {\n const source = (config.source ?? previous?.source ?? \"\").trim();\n\n if (!source) {\n throw new Error(\"Local space analytics requires a non-empty source.\");\n }\n\n return {\n source,\n endpoint: config.endpoint?.trim(),\n enabled: config.enabled ?? previous?.enabled ?? true,\n defaultContext: {\n ...(previous?.defaultContext ?? {}),\n ...(config.defaultContext ?? {}),\n },\n headers: {\n \"content-type\": JSON_CONTENT_TYPE_HEADER,\n ...(previous?.headers ?? {}),\n ...(config.headers ?? {}),\n },\n flushIntervalMs: toPositiveInteger(\n config.flushIntervalMs ?? previous?.flushIntervalMs,\n DEFAULT_FLUSH_INTERVAL_MS\n ),\n batchSize: toPositiveInteger(config.batchSize ?? previous?.batchSize, DEFAULT_BATCH_SIZE),\n maxQueueSize: toPositiveInteger(\n config.maxQueueSize ?? previous?.maxQueueSize,\n DEFAULT_MAX_QUEUE_SIZE\n ),\n storageKey: (config.storageKey ?? previous?.storageKey ?? DEFAULT_STORAGE_KEY).trim(),\n transport: (config.transport ?? previous?.transport ?? defaultTransport) as AnalyticsTransport,\n onError: config.onError ?? previous?.onError,\n };\n}\n\nfunction isBrowserEnvironment(): boolean {\n return typeof window !== \"undefined\" && typeof document !== \"undefined\";\n}\n\nfunction readQueue(storageKey: string): LocalSpaceAnalyticsRecord[] {\n if (!isBrowserEnvironment() || typeof window.localStorage === \"undefined\") {\n return [];\n }\n\n try {\n const rawValue = window.localStorage.getItem(storageKey);\n if (!rawValue) {\n return [];\n }\n\n const parsed = JSON.parse(rawValue);\n if (!Array.isArray(parsed)) {\n return [];\n }\n\n return parsed.filter(isStoredRecordCandidate);\n } catch {\n return [];\n }\n}\n\nfunction isStoredRecordCandidate(value: unknown): value is LocalSpaceAnalyticsRecord {\n if (!value || typeof value !== \"object\") {\n return false;\n }\n\n const candidate = value as Partial<LocalSpaceAnalyticsRecord>;\n return (\n typeof candidate.id === \"string\" &&\n typeof candidate.component === \"string\" &&\n typeof candidate.action === \"string\" &&\n typeof candidate.source === \"string\" &&\n typeof candidate.sessionId === \"string\" &&\n typeof candidate.timestamp === \"number\"\n );\n}\n\nfunction writeQueue(storageKey: string, queue: LocalSpaceAnalyticsRecord[]): void {\n if (!isBrowserEnvironment() || typeof window.localStorage === \"undefined\") {\n return;\n }\n\n try {\n if (queue.length === 0) {\n window.localStorage.removeItem(storageKey);\n return;\n }\n\n window.localStorage.setItem(storageKey, JSON.stringify(queue));\n } catch {\n // Ignored by design: storage quota errors should never break host app UX.\n }\n}\n\nfunction createPayload(source: string, events: LocalSpaceAnalyticsRecord[]): string {\n return JSON.stringify({\n source,\n sentAt: Date.now(),\n events,\n });\n}\n\nexport function createLocalSpaceAnalyticsClient(\n config: LocalSpaceAnalyticsConfig\n): LocalSpaceAnalyticsClient {\n let resolvedConfig = resolveConfig(config);\n const sessionId = createId(\"session\");\n let queue = readQueue(resolvedConfig.storageKey).slice(-resolvedConfig.maxQueueSize);\n\n let flushTimer: ReturnType<typeof setInterval> | null = null;\n let isFlushing = false;\n let flushQueuedAfterCurrent = false;\n let isDestroyed = false;\n\n const persistQueue = () => writeQueue(resolvedConfig.storageKey, queue);\n\n const trimQueue = () => {\n if (queue.length <= resolvedConfig.maxQueueSize) {\n return;\n }\n\n queue = queue.slice(queue.length - resolvedConfig.maxQueueSize);\n };\n\n const flushWithBeacon = (): boolean => {\n if (!resolvedConfig.endpoint || queue.length === 0) {\n return false;\n }\n\n if (\n typeof navigator === \"undefined\" ||\n typeof navigator.sendBeacon !== \"function\"\n ) {\n return false;\n }\n\n const events = queue.slice(0, resolvedConfig.batchSize);\n\n try {\n const body = createPayload(resolvedConfig.source, events);\n const blob = new Blob([body], { type: JSON_CONTENT_TYPE_HEADER });\n const sent = navigator.sendBeacon(resolvedConfig.endpoint, blob);\n\n if (sent) {\n queue = queue.slice(events.length);\n persistQueue();\n }\n\n return sent;\n } catch {\n return false;\n }\n };\n\n const flush = async (): Promise<void> => {\n if (isDestroyed || !resolvedConfig.enabled || !resolvedConfig.endpoint) {\n return;\n }\n\n if (queue.length === 0) {\n return;\n }\n\n if (isFlushing) {\n flushQueuedAfterCurrent = true;\n return;\n }\n\n const events = queue.slice(0, resolvedConfig.batchSize);\n const body = createPayload(resolvedConfig.source, events);\n\n isFlushing = true;\n\n try {\n await resolvedConfig.transport({\n endpoint: resolvedConfig.endpoint,\n body,\n headers: resolvedConfig.headers,\n keepalive: true,\n });\n\n queue = queue.slice(events.length);\n persistQueue();\n } catch (error) {\n resolvedConfig.onError?.(error);\n } finally {\n isFlushing = false;\n\n if (flushQueuedAfterCurrent) {\n flushQueuedAfterCurrent = false;\n if (queue.length > 0) {\n void flush();\n }\n }\n }\n };\n\n const startFlushTimer = () => {\n if (flushTimer) {\n clearInterval(flushTimer);\n flushTimer = null;\n }\n\n if (!resolvedConfig.enabled) {\n return;\n }\n\n flushTimer = setInterval(() => {\n void flush();\n }, resolvedConfig.flushIntervalMs);\n };\n\n const handleVisibilityChange = () => {\n if (typeof document === \"undefined\") {\n return;\n }\n\n if (document.visibilityState !== \"hidden\") {\n return;\n }\n\n if (!flushWithBeacon()) {\n void flush();\n }\n };\n\n const handlePageHide = () => {\n if (!flushWithBeacon()) {\n void flush();\n }\n };\n\n if (isBrowserEnvironment()) {\n document.addEventListener(\"visibilitychange\", handleVisibilityChange);\n window.addEventListener(\"pagehide\", handlePageHide);\n }\n\n startFlushTimer();\n\n return {\n get source() {\n return resolvedConfig.source;\n },\n\n track(event: LocalSpaceAnalyticsEvent) {\n if (isDestroyed || !resolvedConfig.enabled) {\n return;\n }\n\n const record: LocalSpaceAnalyticsRecord = {\n id: createId(\"event\"),\n component: event.component,\n action: event.action,\n label: event.label,\n href: event.href,\n variant: event.variant,\n source: resolvedConfig.source,\n sessionId,\n timestamp: event.timestamp ?? Date.now(),\n context: {\n ...resolvedConfig.defaultContext,\n ...(event.context ?? {}),\n },\n };\n\n queue.push(record);\n trimQueue();\n persistQueue();\n\n if (queue.length >= resolvedConfig.batchSize) {\n void flush();\n }\n },\n\n flush,\n\n updateConfig(nextConfig: Partial<LocalSpaceAnalyticsConfig>) {\n if (isDestroyed) {\n return;\n }\n\n const previousStorageKey = resolvedConfig.storageKey;\n resolvedConfig = resolveConfig(\n {\n ...resolvedConfig,\n ...nextConfig,\n source: nextConfig.source ?? resolvedConfig.source,\n },\n resolvedConfig\n );\n\n if (previousStorageKey !== resolvedConfig.storageKey) {\n writeQueue(previousStorageKey, []);\n persistQueue();\n }\n\n startFlushTimer();\n\n if (resolvedConfig.endpoint && queue.length > 0) {\n void flush();\n }\n },\n\n getConfig() {\n return resolvedConfig;\n },\n\n destroy() {\n if (isDestroyed) {\n return;\n }\n\n isDestroyed = true;\n\n if (flushTimer) {\n clearInterval(flushTimer);\n flushTimer = null;\n }\n\n if (isBrowserEnvironment()) {\n document.removeEventListener(\"visibilitychange\", handleVisibilityChange);\n window.removeEventListener(\"pagehide\", handlePageHide);\n }\n\n void flush();\n },\n };\n}\n\nexport function createNoopLocalSpaceAnalyticsClient(\n source = \"noop\"\n): LocalSpaceAnalyticsClient {\n const noopConfig: ResolvedLocalSpaceAnalyticsConfig = {\n source,\n enabled: false,\n endpoint: undefined,\n defaultContext: {},\n headers: { \"content-type\": JSON_CONTENT_TYPE_HEADER },\n flushIntervalMs: DEFAULT_FLUSH_INTERVAL_MS,\n batchSize: DEFAULT_BATCH_SIZE,\n maxQueueSize: DEFAULT_MAX_QUEUE_SIZE,\n storageKey: DEFAULT_STORAGE_KEY,\n transport: async () => undefined,\n onError: undefined,\n };\n\n return {\n source,\n track: () => undefined,\n flush: async () => undefined,\n updateConfig: () => undefined,\n getConfig: () => noopConfig,\n destroy: () => undefined,\n };\n}\n","import { createContext, useContext, useEffect, useMemo, type ReactNode } from \"react\";\nimport {\n createLocalSpaceAnalyticsClient,\n createNoopLocalSpaceAnalyticsClient,\n} from \"../core/client.js\";\nimport type {\n LocalSpaceAnalyticsClient,\n LocalSpaceAnalyticsConfig,\n LocalSpaceAnalyticsEvent,\n} from \"../core/types.js\";\n\nexport interface AnalyticsProviderProps {\n children: ReactNode;\n source?: string;\n endpoint?: string;\n enabled?: boolean;\n defaultContext?: LocalSpaceAnalyticsConfig[\"defaultContext\"];\n headers?: LocalSpaceAnalyticsConfig[\"headers\"];\n flushIntervalMs?: number;\n batchSize?: number;\n maxQueueSize?: number;\n storageKey?: string;\n transport?: LocalSpaceAnalyticsConfig[\"transport\"];\n onError?: LocalSpaceAnalyticsConfig[\"onError\"];\n client?: LocalSpaceAnalyticsClient;\n}\n\nexport interface AnalyticsContextValue {\n client: LocalSpaceAnalyticsClient;\n trackInteraction: (event: LocalSpaceAnalyticsEvent) => void;\n flush: () => Promise<void>;\n}\n\nconst AnalyticsContext = createContext<AnalyticsContextValue | null>(null);\n\nexport function AnalyticsProvider({\n children,\n source = \"react-app\",\n endpoint,\n enabled = true,\n defaultContext,\n headers,\n flushIntervalMs,\n batchSize,\n maxQueueSize,\n storageKey,\n transport,\n onError,\n client,\n}: AnalyticsProviderProps) {\n const managedClient = useMemo(() => {\n if (client) {\n return client;\n }\n\n if (!enabled) {\n return createNoopLocalSpaceAnalyticsClient(source);\n }\n\n return createLocalSpaceAnalyticsClient({\n source,\n endpoint,\n enabled,\n defaultContext,\n headers,\n flushIntervalMs,\n batchSize,\n maxQueueSize,\n storageKey,\n transport,\n onError,\n });\n }, [\n client,\n source,\n endpoint,\n enabled,\n defaultContext,\n headers,\n flushIntervalMs,\n batchSize,\n maxQueueSize,\n storageKey,\n transport,\n onError,\n ]);\n\n useEffect(() => {\n return () => {\n if (!client) {\n managedClient.destroy();\n }\n };\n }, [client, managedClient]);\n\n const value = useMemo<AnalyticsContextValue>(\n () => ({\n client: managedClient,\n trackInteraction: (event: LocalSpaceAnalyticsEvent) => {\n managedClient.track(event);\n },\n flush: () => managedClient.flush(),\n }),\n [managedClient]\n );\n\n return <AnalyticsContext.Provider value={value}>{children}</AnalyticsContext.Provider>;\n}\n\nexport function useAnalytics(): AnalyticsContextValue {\n const context = useContext(AnalyticsContext);\n\n if (!context) {\n throw new Error(\"useAnalytics must be used within AnalyticsProvider.\");\n }\n\n return context;\n}\n","import { useCallback } from \"react\";\nimport type { AnalyticsContext, LocalSpaceAnalyticsEvent } from \"../core/types.js\";\nimport { useAnalytics } from \"./provider.js\";\n\nexport interface TrackInteractionDetails\n extends Omit<LocalSpaceAnalyticsEvent, \"component\" | \"action\" | \"context\"> {\n context?: AnalyticsContext;\n}\n\nexport function useComponentInteractionTracker(\n component: string,\n baseContext: AnalyticsContext = {}\n): (action: string, details?: TrackInteractionDetails) => void {\n const { trackInteraction } = useAnalytics();\n\n return useCallback(\n (action: string, details?: TrackInteractionDetails) => {\n trackInteraction({\n component,\n action,\n label: details?.label,\n href: details?.href,\n variant: details?.variant,\n timestamp: details?.timestamp,\n context: {\n ...baseContext,\n ...(details?.context ?? {}),\n },\n });\n },\n [baseContext, component, trackInteraction]\n );\n}\n"],"mappings":";AASA,IAAM,4BAA4B;AAClC,IAAM,qBAAqB;AAC3B,IAAM,yBAAyB;AAC/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
"name": "@plasius/analytics",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Local-space analytics client and React helpers for interaction/event tracking with configurable ingestion endpoints.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"main": "./dist/index.cjs",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js",
|
|
17
|
+
"require": "./dist/index.cjs"
|
|
18
|
+
},
|
|
19
|
+
"./package.json": "./package.json"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsup",
|
|
23
|
+
"test": "vitest run",
|
|
24
|
+
"test:watch": "vitest",
|
|
25
|
+
"lint": "eslint .",
|
|
26
|
+
"prepare": "npm run build",
|
|
27
|
+
"clean": "rimraf dist",
|
|
28
|
+
"test:coverage": "vitest run --coverage",
|
|
29
|
+
"pack:check": "node scripts/verify-public-package.cjs",
|
|
30
|
+
"prepublishOnly": "npm run build && npm run pack:check"
|
|
31
|
+
},
|
|
32
|
+
"keywords": [
|
|
33
|
+
"analytics",
|
|
34
|
+
"interaction-tracking",
|
|
35
|
+
"telemetry",
|
|
36
|
+
"react",
|
|
37
|
+
"plasius"
|
|
38
|
+
],
|
|
39
|
+
"author": "Plasius LTD <development@plasius.co.uk>",
|
|
40
|
+
"license": "Apache-2.0",
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "git+https://github.com/Plasius-LTD/analytics.git"
|
|
44
|
+
},
|
|
45
|
+
"bugs": {
|
|
46
|
+
"url": "https://github.com/Plasius-LTD/analytics/issues"
|
|
47
|
+
},
|
|
48
|
+
"homepage": "https://github.com/Plasius-LTD/analytics#readme",
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"react": "^19"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@testing-library/react": "^16.3.0",
|
|
54
|
+
"@types/node": "^24.3.1",
|
|
55
|
+
"@types/react": "^19.1.8",
|
|
56
|
+
"@types/react-dom": "^19.1.2",
|
|
57
|
+
"@typescript-eslint/eslint-plugin": "^8.56.0",
|
|
58
|
+
"@typescript-eslint/parser": "^8.56.0",
|
|
59
|
+
"@vitest/coverage-v8": "^4.0.18",
|
|
60
|
+
"eslint": "^10.0.1",
|
|
61
|
+
"jsdom": "^26.1.0",
|
|
62
|
+
"react": "^19.1.0",
|
|
63
|
+
"react-dom": "^19.1.0",
|
|
64
|
+
"rimraf": "^6.1.0",
|
|
65
|
+
"tsup": "^8.5.0",
|
|
66
|
+
"tsx": "^4.20.5",
|
|
67
|
+
"typescript": "^5.9.2",
|
|
68
|
+
"vitest": "^4.0.18"
|
|
69
|
+
},
|
|
70
|
+
"publishConfig": {
|
|
71
|
+
"access": "public"
|
|
72
|
+
},
|
|
73
|
+
"funding": [
|
|
74
|
+
{
|
|
75
|
+
"type": "patreon",
|
|
76
|
+
"url": "https://www.patreon.com/c/plasiusltd/membership"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"type": "github",
|
|
80
|
+
"url": "https://github.com/sponsors/Plasius-LTD"
|
|
81
|
+
}
|
|
82
|
+
],
|
|
83
|
+
"overrides": {
|
|
84
|
+
"minimatch": "^10.2.1"
|
|
85
|
+
}
|
|
86
|
+
}
|