@@ -2,7 +2,10 @@ import { css } from '@emotion/react';
2
2
import { log , storage } from '@guardian/libs' ;
3
3
import { SvgAudio , SvgAudioMute } from '@guardian/source/react-components' ;
4
4
import { useCallback , useEffect , useRef , useState } from 'react' ;
5
- import { submitClickComponentEvent } from '../client/ophan/ophan' ;
5
+ import {
6
+ submitClickComponentEvent ,
7
+ submitComponentEvent ,
8
+ } from '../client/ophan/ophan' ;
6
9
import { getZIndex } from '../lib/getZIndex' ;
7
10
import { useIsInView } from '../lib/useIsInView' ;
8
11
import { useShouldAdapt } from '../lib/useShouldAdapt' ;
@@ -14,6 +17,7 @@ import {
14
17
import { useConfig } from './ConfigContext' ;
15
18
import type { PLAYER_STATES , PlayerStates } from './LoopVideoPlayer' ;
16
19
import { LoopVideoPlayer } from './LoopVideoPlayer' ;
20
+ import { ophanTrackerWeb } from './YoutubeAtom/eventEmitters' ;
17
21
18
22
const videoContainerStyles = css `
19
23
z-index : ${ getZIndex ( 'loop-video-container' ) } ;
@@ -212,9 +216,23 @@ export const LoopVideo = ({
212
216
213
217
useEffect ( ( ) => {
214
218
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
+
215
233
setHasBeenInView ( true ) ;
216
234
}
217
- } , [ isInView , hasBeenInView ] ) ;
235
+ } , [ isInView , hasBeenInView , atomId ] ) ;
218
236
219
237
/**
220
238
* Autoplay the video when it comes into view.
@@ -230,9 +248,25 @@ export const LoopVideo = ({
230
248
( playerState === 'NOT_STARTED' ||
231
249
playerState === 'PAUSED_BY_INTERSECTION_OBSERVER' )
232
250
) {
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
+
233
259
void playVideo ( ) ;
234
260
}
235
- } , [ isAutoplayAllowed , isInView , isPlayable , playerState , playVideo ] ) ;
261
+ } , [
262
+ isAutoplayAllowed ,
263
+ isInView ,
264
+ isPlayable ,
265
+ playerState ,
266
+ playVideo ,
267
+ hasBeenInView ,
268
+ atomId ,
269
+ ] ) ;
236
270
237
271
/**
238
272
* Stops playback when the video is scrolled out of view, resumes playbacks
0 commit comments