@@ -8,6 +8,9 @@ import MediaLoader from '#app/components/MediaLoader';
8
8
import filterForBlockType from '#app/lib/utilities/blockHandlers' ;
9
9
import { ServiceContext } from '#app/contexts/ServiceContext' ;
10
10
import { RequestContext } from '#app/contexts/RequestContext' ;
11
+ import useViewTracker from '#app/hooks/useViewTracker' ;
12
+ import useClickTrackerHandler from '#app/hooks/useClickTrackerHandler' ;
13
+ import { EventTrackingMetadata } from '#app/models/types/eventTracking' ;
11
14
import { regexPunctuationSymbols } from '#app/lib/utilities/idSanitiser' ;
12
15
import styles from './index.styles' ;
13
16
import WARNING_LEVELS from '../MediaLoader/configs/warningLevels' ;
@@ -21,7 +24,7 @@ type WarningItem = {
21
24
short_description : string ;
22
25
} ;
23
26
24
- type Props = {
27
+ type LiveHeaderMediaProps = {
25
28
mediaCollection : MediaCollection [ ] | null ;
26
29
clickCallback ?: ( ) => void ;
27
30
} ;
@@ -36,11 +39,17 @@ const MemoizedMediaPlayer = memo(MediaLoader);
36
39
const LiveHeaderMedia = ( {
37
40
mediaCollection,
38
41
clickCallback = ( ) => null ,
39
- } : Props ) => {
42
+ } : LiveHeaderMediaProps ) => {
40
43
const { translations } = useContext ( ServiceContext ) ;
41
44
const { isLite } = useContext ( RequestContext ) ;
42
45
const [ showMedia , setShowMedia ] = useState ( false ) ;
43
46
47
+ const eventTrackingData : EventTrackingMetadata = {
48
+ componentName : 'live-header-media' ,
49
+ } ;
50
+ const clickTrackerHandler = useClickTrackerHandler ( eventTrackingData ) ;
51
+ const viewRef = useViewTracker ( eventTrackingData ) ;
52
+
44
53
let warningLevel = WARNING_LEVELS . NO_WARNING ;
45
54
46
55
if ( isLite || mediaCollection == null || mediaCollection . length === 0 ) {
@@ -83,7 +92,7 @@ const LiveHeaderMedia = ({
83
92
84
93
const titleHasPunctuation = short . slice ( - 1 ) . match ( regexPunctuationSymbols ) ;
85
94
86
- const handleClick = ( ) => {
95
+ const clickToggleMedia = ( ) => {
87
96
const mediaPlayer = window . mediaPlayers ?. [ vpid ] ;
88
97
if ( showMedia ) {
89
98
mediaPlayer ?. pause ( ) ;
@@ -98,6 +107,11 @@ const LiveHeaderMedia = ({
98
107
clickCallback ( ) ;
99
108
} ;
100
109
110
+ const handleClick = ( e : React . MouseEvent < HTMLElement , MouseEvent > ) => {
111
+ clickTrackerHandler ( e ) ;
112
+ clickToggleMedia ( ) ;
113
+ } ;
114
+
101
115
const description = (
102
116
< >
103
117
< Text
@@ -131,10 +145,10 @@ const LiveHeaderMedia = ({
131
145
< p > { description } </ p >
132
146
< strong > { noJs } </ strong >
133
147
</ noscript >
134
- < div css = { styles . componentContainer } >
148
+ < div css = { styles . componentContainer } ref = { viewRef } >
135
149
< button
136
150
type = "button"
137
- onClick = { ( ) => handleClick ( ) }
151
+ onClick = { e => handleClick ( e ) }
138
152
data-testid = "watch-now-close-button"
139
153
className = "focusIndicatorInvert"
140
154
css = { [
0 commit comments