// Metro module 14059 (f14060). import { useMemo, useRef, useCallback, useEffect } from "react"; import NetworkStore from "../../../../stores/NetworkStore"; import { AnalyticEvents } from "../../../../Constants"; import { useQuestImpressionId } from "../../lib/analytics/ContentImpressionTrackerHooks"; import { v4 } from "../../../../_bundle/Module514"; import { formatVideoProgressRatio } from "../../utils/VideoQuestUtils"; import { trackAdContentEvent } from "../../lib/analytics/AnalyticsActions"; import { AdCreativeType } from "../../../../_bundle/Module6013"; import { PlaybackTriggerSource } from "../AdVideoPlayer"; import { isSourceError } from "../AdsVideoUtils"; import MonitoringAgent from "../../../monitoring/MonitoringAgent"; import { MetricEvents } from "../../../../_bundle/Module5872"; let c9831_6 = [25, 50, 75]; export function useBountiesModalVideoAnalytics(a0) { let ref, ref2, ref3, ref4, ref5, ref6, ref7, ref8, ref9, ref10, ref11, ref12, callback, memo2, callback2, callback3, callback4, callback5, callback6, callback7, callback8, callback9, callback10, callback11; const { bountyId, sourceQuestContent, rewardDurationMs, initialPlaybackTimeSec = 0, initialMaxVideoProgressSec = 0 } = a0; let c20876_3 = initialMaxVideoProgressSec; let initialVideoDurationSec = a0.initialVideoDurationSec; if (initialVideoDurationSec === void 0) { initialVideoDurationSec = 0; } let c20876_4 = initialVideoDurationSec; let wasPreloaded = a0.wasPreloaded; if (wasPreloaded === void 0) { wasPreloaded = false; } const was_preloaded = wasPreloaded; let startupPath = a0.startupPath; if (startupPath === void 0) { startupPath = "carousel"; } const startup_path = startupPath; let verticalScrollingPosition = a0.verticalScrollingPosition; if (verticalScrollingPosition === void 0) { verticalScrollingPosition = null; } const vertical_scrolling_position = verticalScrollingPosition; let isActive = a0.isActive; if (isActive === void 0) { isActive = true; } let c20876_8 = isActive; ref = void 0; ref2 = void 0; ref3 = void 0; ref4 = void 0; ref5 = void 0; ref6 = void 0; ref7 = void 0; ref8 = void 0; ref9 = void 0; ref10 = void 0; ref11 = void 0; ref12 = void 0; callback = void 0; memo2 = void 0; callback2 = void 0; callback3 = void 0; callback4 = void 0; callback5 = void 0; callback6 = void 0; callback7 = void 0; callback8 = void 0; callback9 = void 0; callback10 = void 0; callback11 = void 0; const questImpressionId = useQuestImpressionId(); const memo = useMemo(() => v4(), []); const set = new Set(); const r40 = initialPlaybackTimeSec > 0 || initialMaxVideoProgressSec > 0; if (r40) { set.add("start"); } if (1000 * initialMaxVideoProgressSec >= rewardDurationMs) { set.add("threshold"); } ref = useRef(set); ref2 = useRef(false); ref3 = useRef(initialPlaybackTimeSec); ref4 = useRef(initialVideoDurationSec); ref5 = useRef(null); ref6 = useRef(null); ref7 = useRef(false); ref8 = useRef(false); ref9 = useRef(null); ref10 = useRef(null); ref11 = useRef(-1); ref12 = useRef({ bitrateBps: null, width: null, height: null, levelIndex: null }); callback = useCallback(() => { if (ref9.current != null) { clearTimeout(ref9.current); ref9.current = null; } }, []); memo2 = useMemo(() => ({ was_preloaded, startup_path, vertical_scrolling_position, reward_timer_seconds: rewardDurationMs / 1000 }), [was_preloaded, startup_path, vertical_scrolling_position, rewardDurationMs]); callback2 = useCallback(() => { const current = ref12.current; return { hls_level_index: current.levelIndex, hls_segment_res_width: current.width, hls_segment_res_height: current.height }; }, []); callback3 = useCallback((a0) => { if (!ref2.current) { let r5 = a0; ref2.current = true; if (!(a0 > 0)) { r5 = c20876_4; } if (!(r5 <= 0)) { const r6 = formatVideoProgressRatio(c20876_3, r5); for (const item of c9831_6) { if (r6 >= item / 100) { ref.current.add(`p${item}`); } } } } }, [initialMaxVideoProgressSec, initialVideoDurationSec]); callback4 = useCallback((a0) => { trackAdContentEvent({ adContentId: bountyId, adCreativeType: AdCreativeType.BOUNTY, event: AnalyticEvents.AD_VIDEO_PROGRESSED, properties: { progress: a0.progress, video_timestamp_seconds: a0.videoTimestampSeconds, video_session_id: memo, impression_id: questImpressionId, threshold_met: a0.thresholdMet, reward_timer_seconds: rewardDurationMs / 1000 }, sourceQuestContent }); }, [bountyId, memo, questImpressionId, sourceQuestContent, rewardDurationMs]); callback5 = useCallback(() => { if (!ref.current.has("start")) { ref.current.add("start"); callback4({ videoTimestampSeconds: 0, progress: 0, thresholdMet: false }); } }, [callback4]); callback6 = useCallback((a0, a1) => { if (!ref.current.has("threshold")) { ref.current.add("threshold"); const videoTimestampSeconds = Math.max(rewardDurationMs / 1000, a0); callback4({ videoTimestampSeconds, progress: formatVideoProgressRatio(videoTimestampSeconds, a1), thresholdMet: true }); } }, [callback4, rewardDurationMs]); callback7 = useCallback((a0, a1) => { if (!ref.current.has("end")) { ref.current.add("end"); callback4({ videoTimestampSeconds: Math.max(a0, a1), progress: 1, thresholdMet: true }); } }, [callback4]); callback8 = useCallback((a0, a1) => { if (!(a1 <= 0)) { const progress = formatVideoProgressRatio(a0, a1); for (const item of c9831_6) { const r15 = `p${item}`; if (!ref.current.has(r15) && !(progress < item / 100)) { ref.current.add(r15); callback4({ videoTimestampSeconds: a0, progress, thresholdMet: 1000 * a0 >= rewardDurationMs }); } } } }, [callback4, rewardDurationMs]); const callback12 = useCallback((a0, a1, a2) => { ref3.current = a2; ref4.current = a1; callback3(a1); if (a0 === 0) { callback5(); } if (1000 * a0 >= rewardDurationMs) { callback6(a0, a1); } callback8(a0, a1); }, [callback3, callback5, callback6, callback8, rewardDurationMs]); const callback13 = useCallback((a0, a1, a2) => { ref3.current = a2; ref4.current = a1; callback3(a1); if (a0 === 0) { callback5(); } callback6(a0, a1); callback8(a0, a1); callback7(a0, a1); }, [callback3, callback5, callback6, callback8, callback7]); const callback14 = useCallback((a0) => { ref3.current = 0; trackAdContentEvent({ adContentId: bountyId, adCreativeType: AdCreativeType.BOUNTY, event: AnalyticEvents.AD_VIDEO_LOOPED, properties: { video_session_id: memo, impression_id: questImpressionId, loop_count: a0, reward_timer_seconds: rewardDurationMs / 1000 }, sourceQuestContent }); }, [bountyId, memo, questImpressionId, sourceQuestContent, rewardDurationMs]); const callback15 = useCallback((a0, a1) => { if (a1 === PlaybackTriggerSource.USER_INTERACTION) { trackAdContentEvent({ adContentId: bountyId, adCreativeType: AdCreativeType.BOUNTY, event: AnalyticEvents.AD_VIDEO_PAUSED, properties: { video_timestamp_seconds: a0, video_session_id: memo, impression_id: questImpressionId, reward_timer_seconds: rewardDurationMs / 1000 }, sourceQuestContent }); } }, [bountyId, memo, questImpressionId, sourceQuestContent, rewardDurationMs]); const callback16 = useCallback((a0, a1) => { if (a1 === PlaybackTriggerSource.USER_INTERACTION) { trackAdContentEvent({ adContentId: bountyId, adCreativeType: AdCreativeType.BOUNTY, event: AnalyticEvents.AD_VIDEO_RESUMED, properties: { video_timestamp_seconds: a0, video_session_id: memo, impression_id: questImpressionId, reward_timer_seconds: rewardDurationMs / 1000 }, sourceQuestContent }); } }, [bountyId, memo, questImpressionId, sourceQuestContent, rewardDurationMs]); const callback17 = useCallback((a0) => { const properties = { video_progress: formatVideoProgressRatio(ref3.current, ref4.current), video_error_type: null, network_connection_speed: null, video_session_id: memo, video_error_code: a0 == null ? void 0 : a0.error.code, video_error_message: null, video_network_state: null, impression_id: null, reward_timer_seconds: null }; let video_error_message = a0 == null ? void 0 : a0.error.localizedDescription; if (video_error_message == null) { video_error_message = a0 == null ? void 0 : a0.error.errorString; } properties.video_error_message = video_error_message; properties.impression_id = questImpressionId; properties.reward_timer_seconds = rewardDurationMs / 1000; trackAdContentEvent({ adContentId: bountyId, adCreativeType: AdCreativeType.BOUNTY, event: AnalyticEvents.AD_VIDEO_ERROR, properties, sourceQuestContent }); if (isSourceError(a0)) { MonitoringAgent.increment({ name: MetricEvents.QUEST_VIDEO_ERROR, tags: ["error_type:SOURCE_ERROR"] }); } }, [bountyId, memo, questImpressionId, sourceQuestContent, rewardDurationMs]); callback9 = useCallback(() => { if (ref10.current != null) { const duration = Date.now() - ref10.current; ref10.current = null; trackAdContentEvent({ adContentId: bountyId, adCreativeType: AdCreativeType.BOUNTY, event: AnalyticEvents.AD_VIDEO_BUFFERING_ENDED, properties: { video_session_id: memo, impression_id: questImpressionId, duration, network_connection_speed: NetworkStore.getEffectiveConnectionSpeed(), buffer_index: ref11.current, video_bitrate_bps: ref12.current.bitrateBps, ...callback2(), ...memo2 }, sourceQuestContent }); } }, [bountyId, memo, questImpressionId, callback2, memo2, sourceQuestContent]); callback10 = useCallback(() => { if (!(ref7.current || ref5.current == null || ref6.current == null)) { ref7.current = true; callback(); trackAdContentEvent({ adContentId: bountyId, adCreativeType: AdCreativeType.BOUNTY, event: AnalyticEvents.AD_VIDEO_TIME_TO_FIRST_FRAME, properties: { video_session_id: memo, impression_id: questImpressionId, duration_ms: ref6.current - ref5.current, network_connection_speed: NetworkStore.getEffectiveConnectionSpeed(), startup_bitrate_bps: ref12.current.bitrateBps, ...callback2(), ...memo2 }, sourceQuestContent }); } }, [bountyId, memo, questImpressionId, callback, callback2, memo2, sourceQuestContent]); callback11 = useCallback(() => { if (!(ref7.current || ref5.current == null || ref6.current == null)) { if (ref12.current.bitrateBps == null) { if (ref9.current == null) { ref9.current = setTimeout(() => { ref9.current = null; callback10(); }, 500); } } else { callback10(); } } }, [callback10]); useEffect(() => () => { if (ref9.current != null) { callback10(); } callback(); callback9(); }, [callback, callback9, callback10]); useEffect(() => { if (c20876_8) { callback11(); } else { if (ref9.current != null) { callback10(); } callback(); callback9(); } }, [isActive, callback11, callback, callback9, callback10]); return { handleVideoProgressAnalytics: callback12, handleVideoEndAnalytics: callback13, handleVideoLoopedAnalytics: callback14, handleVideoPausedAnalytics: callback15, handleVideoResumedAnalytics: callback16, handleVideoErrorAnalytics: callback17, handleLoadStartAnalytics: useCallback(() => { callback9(); callback(); ref5.current = Date.now(); ref6.current = null; ref7.current = false; ref8.current = false; ref12.current = { bitrateBps: null, width: null, height: null, levelIndex: null }; }, [callback, callback9]), handleVideoTracksAnalytics: useCallback(({ videoTracks, selectedVideoTrackId }) => { let current; if (videoTracks.length === 0) { current = { bitrateBps: null, width: null, height: null, levelIndex: null }; } else { const r7 = selectedVideoTrackId != null ? selectedVideoTrackId.length > 0 ? videoTracks.findIndex((videoTrack) => videoTrack.trackId === selectedVideoTrackId) : -1 : -1; const r16 = r7 >= 0 ? videoTracks[r7] : videoTracks[0]; current = { bitrateBps: r16.bitrate > 0 ? r16.bitrate : null, width: r16.width > 0 ? r16.width : null, height: r16.height > 0 ? r16.height : null, levelIndex: r7 >= 0 ? r7 : null }; } ref12.current = current; if (c20876_8 && ref6.current != null && ref12.current.bitrateBps != null) { callback10(); } }, [callback10, isActive]), handleReadyForDisplayAnalytics: useCallback(() => { ref8.current = true; if (ref6.current == null) { ref6.current = Date.now(); } if (c20876_8) { callback11(); } }, [isActive, callback11]), handleBufferAnalytics: useCallback((a0) => { if (ref8.current && c20876_8) { if (a0) { ref10.current = Date.now(); ref11.current = ref11.current + 1; trackAdContentEvent({ adContentId: bountyId, adCreativeType: AdCreativeType.BOUNTY, event: AnalyticEvents.AD_VIDEO_BUFFERING_STARTED, properties: { video_session_id: memo, impression_id: questImpressionId, network_connection_speed: NetworkStore.getEffectiveConnectionSpeed(), buffer_index: ref11.current, video_bitrate_bps: ref12.current.bitrateBps, ...callback2(), ...memo2 }, sourceQuestContent }); } else { callback9(); } return void 0; } }, [bountyId, memo, questImpressionId, callback9, callback2, isActive, memo2, sourceQuestContent]) }; }