diff --git a/src/components/Player/Player.tsx b/src/components/Player/Player.tsx index 98efda785..a8e51fbf9 100644 --- a/src/components/Player/Player.tsx +++ b/src/components/Player/Player.tsx @@ -11,8 +11,6 @@ import useOttAnalytics from '#src/hooks/useOttAnalytics'; import { logDev, testId } from '#src/utils/common'; import { useConfigStore } from '#src/stores/ConfigStore'; import type { AdSchedule } from '#types/ad-schedule'; -import { useAccountStore } from '#src/stores/AccountStore'; -import { useProfileStore } from '#src/stores/ProfileStore'; import { attachAnalyticsParams } from '#src/utils/analytics'; type Props = { @@ -60,10 +58,6 @@ const Player: React.FC = ({ const [libLoaded, setLibLoaded] = useState(!!window.jwplayer); const startTimeRef = useRef(startTime); - const { config } = useConfigStore((s) => s); - const { user } = useAccountStore((s) => s); - const { profile } = useProfileStore(); - const setPlayer = useOttAnalytics(item, feedId); const { settings } = useConfigStore((s) => s); @@ -71,10 +65,6 @@ const Player: React.FC = ({ const playerId = settings.playerId; const playerLicenseKey = settings.playerLicenseKey; - const isJwIntegration = !!config?.integrations?.jwp; - const userId = user?.id; - const profileId = profile?.id; - const handleBeforePlay = useEventCallback(onBeforePlay); const handlePlay = useEventCallback(onPlay); const handlePause = useEventCallback(onPause); @@ -174,7 +164,7 @@ const Player: React.FC = ({ playerRef.current = window.jwplayer(playerElementRef.current) as JWPlayer; // Inject user_id and profile_id into the CDN analytics - attachAnalyticsParams(item, isJwIntegration, userId, profileId); + attachAnalyticsParams(item); // Player options are untyped const playerOptions: { [key: string]: unknown } = { @@ -228,7 +218,7 @@ const Player: React.FC = ({ if (libLoaded) { initializePlayer(); } - }, [libLoaded, item, detachEvents, attachEvents, playerId, setPlayer, autostart, adsData, playerLicenseKey, feedId, isJwIntegration, profileId, userId]); + }, [libLoaded, item, detachEvents, attachEvents, playerId, setPlayer, autostart, adsData, playerLicenseKey, feedId]); useEffect(() => { return () => { diff --git a/src/utils/analytics.ts b/src/utils/analytics.ts index 3deaa69c1..11501f7ee 100644 --- a/src/utils/analytics.ts +++ b/src/utils/analytics.ts @@ -1,8 +1,19 @@ +import { useAccountStore } from '#src/stores/AccountStore'; +import { useConfigStore } from '#src/stores/ConfigStore'; +import { useProfileStore } from '#src/stores/ProfileStore'; import type { PlaylistItem, Source } from '#types/playlist'; -export const attachAnalyticsParams = (item: PlaylistItem, isJwIntegration: boolean, userId?: string, profileId?: string) => { +export const attachAnalyticsParams = (item: PlaylistItem) => { + const { config } = useConfigStore.getState(); + const { user } = useAccountStore.getState(); + const { profile } = useProfileStore.getState(); + const { sources, mediaid } = item; + const userId = user?.id; + const profileId = profile?.id; + const isJwIntegration = !!config?.integrations?.jwp; + return sources.map((source: Source) => { const url = new URL(source.file);