Files
movie-advisor/components/Analytics/index.tsx
T
nerandClaude Opus 5 66776c582f refactor(analytics): send titles alongside ids, drop comments
Bare ids are unreadable in the dashboard, so every event that points at a
show or a person now carries its title or name. Ids stay for disambiguation,
since titles collide across remakes.

- ShowRef gains showTitle, so show_viewed, library_toggled, torrents_searched,
  torrent_selected, playback_started and playback_failed all report it
- person_viewed sends personName
- random_shuffled sends the title of the movie scrolled to
- torrent_selected sends the torrent title next to the show title
- subtitles_selected sends the track label, such as English, rather than the
  internal track value

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

62 lines
1.4 KiB
TypeScript

'use client';
import { useEffect } from 'react';
import { getInitSnippet } from '@openpanel/web';
import { OPENPANEL_API_URL, OPENPANEL_CLIENT_ID, OPENPANEL_SCRIPT_URL } from '@/env';
const SCRIPT_ID = 'openpanel-sdk';
const SRC = OPENPANEL_SCRIPT_URL || 'https://openpanel.dev/op1.js';
const OPTIONS = {
clientId: OPENPANEL_CLIENT_ID,
apiUrl: OPENPANEL_API_URL,
trackScreenViews: true,
trackOutgoingLinks: true
};
const Analytics = () => {
useEffect(() => {
if (!OPENPANEL_CLIENT_ID) return;
let cancelled = false;
const append = () => {
if (cancelled || document.getElementById(SCRIPT_ID)) return;
const script = document.createElement('script');
script.id = SCRIPT_ID;
script.src = SRC;
script.async = true;
document.body.appendChild(script);
};
const schedule = () =>
typeof window.requestIdleCallback === 'function'
? window.requestIdleCallback(append, { timeout: 5000 })
: window.setTimeout(append, 2000);
if (document.readyState === 'complete') schedule();
else window.addEventListener('load', schedule, { once: true });
return () => {
cancelled = true;
};
}, []);
if (!OPENPANEL_CLIENT_ID) return null;
return (
<script
dangerouslySetInnerHTML={{
__html: `${getInitSnippet()}window.op('init', ${JSON.stringify(OPTIONS)});`
}}
/>
);
};
export default Analytics;