@@ -2,7 +2,10 @@ import { css } from '@emotion/react';
22import { log , storage } from '@guardian/libs' ;
33import { SvgAudio , SvgAudioMute } from '@guardian/source/react-components' ;
44import { useCallback , useEffect , useRef , useState } from 'react' ;
5- import { submitClickComponentEvent } from '../client/ophan/ophan' ;
5+ import {
6+ submitClickComponentEvent ,
7+ submitComponentEvent ,
8+ } from '../client/ophan/ophan' ;
69import { getZIndex } from '../lib/getZIndex' ;
710import { useIsInView } from '../lib/useIsInView' ;
811import { useShouldAdapt } from '../lib/useShouldAdapt' ;
@@ -14,6 +17,7 @@ import {
1417import { useConfig } from './ConfigContext' ;
1518import type { PLAYER_STATES , PlayerStates } from './LoopVideoPlayer' ;
1619import { LoopVideoPlayer } from './LoopVideoPlayer' ;
20+ import { ophanTrackerWeb } from './YoutubeAtom/eventEmitters' ;
1721
1822const videoContainerStyles = css `
1923 z-index : ${ getZIndex ( 'loop-video-container' ) } ;
@@ -212,9 +216,23 @@ export const LoopVideo = ({
212216
213217 useEffect ( ( ) => {
214218 if ( isInView && ! hasBeenInView ) {
219+ /**
220+ * Track the first time the video comes into view.
221+ */
222+ void submitComponentEvent (
223+ {
224+ component : {
225+ componentType : 'LOOP_VIDEO' ,
226+ id : `gu-video-loop-${ atomId } ` ,
227+ } ,
228+ action : 'VIEW' ,
229+ } ,
230+ 'Web' ,
231+ ) ;
232+
215233 setHasBeenInView ( true ) ;
216234 }
217- } , [ isInView , hasBeenInView ] ) ;
235+ } , [ isInView , hasBeenInView , atomId ] ) ;
218236
219237 /**
220238 * Autoplay the video when it comes into view.
@@ -230,9 +248,25 @@ export const LoopVideo = ({
230248 ( playerState === 'NOT_STARTED' ||
231249 playerState === 'PAUSED_BY_INTERSECTION_OBSERVER' )
232250 ) {
251+ /**
252+ * check if the video has not been in view before tracking the play.
253+ * This is so we only track the first play.
254+ */
255+ if ( ! hasBeenInView ) {
256+ ophanTrackerWeb ( atomId , 'loop' ) ( 'play' ) ;
257+ }
258+
233259 void playVideo ( ) ;
234260 }
235- } , [ isAutoplayAllowed , isInView , isPlayable , playerState , playVideo ] ) ;
261+ } , [
262+ isAutoplayAllowed ,
263+ isInView ,
264+ isPlayable ,
265+ playerState ,
266+ playVideo ,
267+ hasBeenInView ,
268+ atomId ,
269+ ] ) ;
236270
237271 /**
238272 * Stops playback when the video is scrolled out of view, resumes playbacks
0 commit comments