Files
movie-advisor/lib/analytics/events.ts
T
nerandClaude Opus 5 01753d4eb6 refactor(analytics): method per event instead of track(name, props)
analytics.showViewed({...}) reads better than track('show_viewed', {...}) and
drops the track_ alias Captions needed, where vidstack already exports track.

The methods are derived from the event catalogue with a mapped type plus a
Proxy rather than written out, so the catalogue stays the only place an event
is declared and the two cannot drift. Names stay snake_case on the wire.
Emitters are cached so a method is referentially stable and safe to pass to a
hook or use as an effect dependency.

Events with no payload are typed void and take no arguments.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-14 12:39:54 +03:00

30 lines
1.2 KiB
TypeScript

type ShowRef = { showId: Show['id']; showType: Show['type'] };
export type ListName = 'popular' | 'top' | 'search' | 'favorite' | 'watchlist' | 'random';
/**
* The whole analytics surface of the app. Adding an event means adding a line here first,
* which keeps names and payloads consistent and makes `track` calls type checked.
*/
export type AnalyticsEvents = {
show_viewed: ShowRef & { title: string; surface: 'page' | 'modal' };
person_viewed: { personId: string };
list_loaded_more: { list: ListName; page: number };
random_shuffled: { index: number };
search_performed: { query: string; showType: Show['type']; results: number };
gallery_tab_changed: { tab: string };
library_toggled: ShowRef & { list: 'favorite' | 'watchlist'; value: boolean };
auth_completed: void;
auth_signed_out: void;
torrents_searched: ShowRef & { provider: string; results: number };
torrent_selected: { provider: string; seeders: number; quality?: string; source?: string; codec?: string };
playback_started: ShowRef & { quality?: string };
playback_failed: ShowRef & { reason: string };
subtitles_selected: { language: string };
};
export type AnalyticsEvent = keyof AnalyticsEvents;