@@ -4,7 +4,9 @@ import {Icon} from '@gravity-ui/uikit';
44import _ from 'lodash' ;
55import { v4 as uuidv4 } from 'uuid' ;
66
7+ import { useAnalytics } from '../../hooks/useAnalytics' ;
78import { PlayVideo } from '../../icons' ;
9+ import { AnalyticsEventsBase , DefaultEventNames } from '../../models/common' ;
810import { block , getPageSearchParams } from '../../utils' ;
911import Image from '../Image/Image' ;
1012
@@ -47,7 +49,7 @@ export function getHeight(width: number): number {
4749 return ( width / 16 ) * 9 ;
4850}
4951
50- export interface VideoBlockProps {
52+ export interface VideoBlockProps extends AnalyticsEventsBase {
5153 id ?: string ;
5254 stream ?: string ;
5355 record ?: string ;
@@ -60,8 +62,20 @@ export interface VideoBlockProps {
6062}
6163
6264const VideoBlock = ( props : VideoBlockProps ) => {
63- const { stream, record, attributes, className, id, previewImg, playButton, height, fullscreen} =
64- props ;
65+ const {
66+ stream,
67+ record,
68+ attributes,
69+ className,
70+ id,
71+ previewImg,
72+ playButton,
73+ height,
74+ fullscreen,
75+ analyticsEvents,
76+ } = props ;
77+ const handleAnalytics = useAnalytics ( DefaultEventNames . VideoPreview ) ;
78+
6579 const src = getVideoSrc ( stream , record ) ;
6680 const ref = useRef < HTMLDivElement > ( null ) ;
6781 const iframeRef = useRef < HTMLIFrameElement > ( ) ;
@@ -70,6 +84,8 @@ const VideoBlock = (props: VideoBlockProps) => {
7084 const [ currentHeight , setCurrentHeight ] = useState ( height || undefined ) ;
7185 const fullId = id || uuidv4 ( ) ;
7286 const onPreviewClick = useCallback ( ( ) => {
87+ handleAnalytics ( analyticsEvents ) ;
88+
7389 if ( iframeRef . current ) {
7490 iframeRef . current . src = `${ src } ?${ getPageSearchParams ( {
7591 ...AUTOPLAY_ATTRIBUTES ,
@@ -78,7 +94,7 @@ const VideoBlock = (props: VideoBlockProps) => {
7894 }
7995
8096 setTimeout ( ( ) => setHidePreview ( true ) , AUTOPLAY_DELAY ) ;
81- } , [ src , attributes ] ) ;
97+ } , [ handleAnalytics , analyticsEvents , src , attributes ] ) ;
8298
8399 useEffect ( ( ) => {
84100 const updateSize = _ . debounce ( ( ) => {
0 commit comments