Replaces Vercel Analytics with OpenPanel, driven entirely by env vars so the whole layer is inert until NEXT_PUBLIC_OPENPANEL_CLIENT_ID is set. Zero initial load cost. next/script emits a rel=preload even on lazyOnload, which pulls the sdk during the first paint, so the component skips it: it inlines the 416 byte official stub (window.op queues calls immediately) and appends the real script itself on window load plus requestIdleCallback. The built html carries no preload and no script src for the analytics host. Events live in one typed catalogue (lib/analytics/events.ts) and track() is keyed to it, so a wrong name or payload is a type error rather than a silent bad row. Emitters sit in the hooks that already own the behaviour instead of being sprinkled through components: - useShowState covers every favourite and watchlist toggle - useInfiniteList covers pagination for all six lists - useTorrents covers all three providers - Preview, Person and useSearch use a shared useTrackOnce hook Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
32 lines
1.2 KiB
TypeScript
32 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: EmptyPayload;
|
|
auth_signed_out: EmptyPayload;
|
|
|
|
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 EmptyPayload = Record<string, never>;
|
|
|
|
export type AnalyticsEvent = keyof AnalyticsEvents;
|