From be151fd6f7e7860cc60bee67bab815c155e86fcd Mon Sep 17 00:00:00 2001 From: Fuwn Date: Fri, 29 May 2026 23:05:37 +0000 Subject: feat(analytics): track umami events across core actions Add a guarded track() wrapper (src/lib/analytics.ts) so programmatic events no-op instead of throwing when umami is absent (localhost), lazily loaded, or ad-blocked. Instrument the core loop (progress increment, roulette, list filter, force refresh), the auth funnel (log in/out, command palette), settings toggles/selects at the wrapper level, sync/debug/feed actions, and tool/sharing actions. --- src/lib/analytics.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/lib/analytics.ts (limited to 'src/lib/analytics.ts') diff --git a/src/lib/analytics.ts b/src/lib/analytics.ts new file mode 100644 index 00000000..014f72db --- /dev/null +++ b/src/lib/analytics.ts @@ -0,0 +1,11 @@ +/** + * Safe wrapper around umami's programmatic `track`. The analytics script is + * skipped on localhost, lazily loaded elsewhere, and routinely blocked by + * content blockers, so a bare `umami.track(...)` throws a ReferenceError that + * would take core actions (incrementing progress, syncing settings) down with + * it. Declarative `data-umami-event` attributes are handled by the script + * itself and never need this; reach for it only from event handlers. + */ +export const track = (event: string, data?: Record): void => { + if (typeof umami !== "undefined") umami.track(event, data); +}; -- cgit v1.2.3