Files
smart-rgb/frontend/src/browser/analytics/wasmAnalytics.ts
2025-10-16 00:02:34 -05:00

31 lines
696 B
TypeScript

import type { AnalyticsAPI } from "@/shared/analytics/AnalyticsAPI";
/**
* Browser/WASM implementation of AnalyticsAPI.
*
* Events are sent through the WASM worker which handles batching and
* sending to PostHog.
*/
export class WasmAnalytics implements AnalyticsAPI {
private worker: Worker | null = null;
constructor(worker: Worker) {
this.worker = worker;
}
track(event: string, properties?: Record<string, any>): void {
if (!this.worker) {
console.error("Worker not set for analytics");
return;
}
this.worker.postMessage({
type: "ANALYTICS_EVENT",
payload: {
event,
properties: properties || {},
},
});
}
}