feat(analytics): bridge analytics.ts to platform telemetry client
This commit is contained in:
parent
1713ce058b
commit
9d50a196bc
@ -1,44 +1,29 @@
|
||||
// ── Analytics Stub ───────────────────────────────────────────────
|
||||
// Console-logs in dev, no-op in prod. Easy to swap in Plausible or
|
||||
// platform-service telemetry later.
|
||||
// ── Analytics ────────────────────────────────────────────────────
|
||||
// Forwards events to platform-service telemetry client.
|
||||
// Keeps the same public API so existing callers (store.ts, InstallPrompt) are unchanged.
|
||||
|
||||
type AnalyticsEvent =
|
||||
| { name: 'timer_created'; props: { type: 'alarm' | 'countdown' | 'pomodoro' | 'event'; urgency: string; cascade: string } }
|
||||
| { name: 'timer_completed'; props: { type: string; durationMs: number } }
|
||||
| { name: 'cascade_fired'; props: { timerId: string; minutesBefore: number } }
|
||||
| { name: 'pomodoro_completed'; props: { rounds: number; totalMinutes: number } }
|
||||
| { name: 'pwa_installed'; props: Record<string, never> }
|
||||
| { name: 'pwa_install_dismissed'; props: Record<string, never> };
|
||||
|
||||
const isDev = process.env.NODE_ENV === 'development';
|
||||
|
||||
function track(event: AnalyticsEvent): void {
|
||||
if (isDev) {
|
||||
console.log(`[analytics] ${event.name}`, event.props);
|
||||
}
|
||||
// Future: send to Plausible, platform-service telemetry, etc.
|
||||
}
|
||||
import { trackTimerEvent, trackEvent } from './telemetry';
|
||||
|
||||
export function trackTimerCreated(type: 'alarm' | 'countdown' | 'pomodoro' | 'event', urgency: string, cascade: string): void {
|
||||
track({ name: 'timer_created', props: { type, urgency, cascade } });
|
||||
trackTimerEvent('timer_created', { type, urgency, cascade });
|
||||
}
|
||||
|
||||
export function trackTimerCompleted(type: string, durationMs: number): void {
|
||||
track({ name: 'timer_completed', props: { type, durationMs } });
|
||||
trackTimerEvent('timer_completed', { type }, { durationMs });
|
||||
}
|
||||
|
||||
export function trackCascadeFired(timerId: string, minutesBefore: number): void {
|
||||
track({ name: 'cascade_fired', props: { timerId, minutesBefore } });
|
||||
trackTimerEvent('cascade_fired', { timerId }, { minutesBefore });
|
||||
}
|
||||
|
||||
export function trackPomodoroCompleted(rounds: number, totalMinutes: number): void {
|
||||
track({ name: 'pomodoro_completed', props: { rounds, totalMinutes } });
|
||||
trackTimerEvent('pomodoro_completed', undefined, { rounds, totalMinutes });
|
||||
}
|
||||
|
||||
export function trackPWAInstalled(): void {
|
||||
track({ name: 'pwa_installed', props: {} });
|
||||
trackEvent('info', 'pwa', 'pwa_installed');
|
||||
}
|
||||
|
||||
export function trackPWAInstallDismissed(): void {
|
||||
track({ name: 'pwa_install_dismissed', props: {} });
|
||||
trackEvent('info', 'pwa', 'pwa_install_dismissed');
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user