Skip to content

Commit 12d076a

Browse files
committed
add explicit clickComponent tracking for play and mute buttons on looping videos
1 parent 18b5fff commit 12d076a

File tree

2 files changed

+27
-16
lines changed

2 files changed

+27
-16
lines changed

dotcom-rendering/src/client/ophan/ophan.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ export const getOphan = async (
3232
);
3333
}
3434
},
35+
trackClickComponentEvent: (e) => {
36+
if (e instanceof Error) {
37+
window.guardian.modules.sentry.reportError(
38+
e,
39+
"We are in DCAR but Ophan trackClickComponentEvent method got called. This shouldn't have happened. Please investigate why",
40+
);
41+
}
42+
},
3543
viewId: 'Apps',
3644
pageViewId: 'Apps',
3745
};
@@ -73,6 +81,14 @@ export const submitComponentEvent = async (
7381
ophan.record({ componentEvent });
7482
};
7583

84+
export const submitClickComponentEvent = async (
85+
element: Element,
86+
renderingTarget: RenderingTarget,
87+
): Promise<void> => {
88+
const ophan = await getOphan(renderingTarget);
89+
ophan.trackClickComponentEvent(element);
90+
};
91+
7692
interface SdcTestMeta {
7793
abTestName: NonNullable<ComponentEvent['abTest']>['name'];
7894
abTestVariant: NonNullable<ComponentEvent['abTest']>['name'];

dotcom-rendering/src/components/LoopVideoPlayer.tsx

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import { space } from '@guardian/source/foundations';
33
import type { IconProps } from '@guardian/source/react-components';
44
import type { Dispatch, SetStateAction, SyntheticEvent } from 'react';
55
import { forwardRef } from 'react';
6+
import { submitClickComponentEvent } from '../client/ophan/ophan';
67
import { palette } from '../palette';
78
import { narrowPlayIconWidth, PlayIcon } from './Card/components/PlayIcon';
9+
import { useConfig } from './ConfigContext';
810
import { LoopVideoProgressBar } from './LoopVideoProgressBar';
911

1012
const videoStyles = (width: number, height: number) => css`
@@ -113,6 +115,7 @@ export const LoopVideoPlayer = forwardRef(
113115
) => {
114116
// Assumes that the video is unique on the page.
115117
const loopVideoId = `loop-video-${videoId}`;
118+
const { renderingTarget } = useConfig();
116119

117120
return (
118121
<>
@@ -161,14 +164,10 @@ export const LoopVideoPlayer = forwardRef(
161164
<button
162165
type="button"
163166
onClick={(event) => {
164-
if (
165-
window.guardian?.ophan
166-
?.trackClickComponentEvent
167-
) {
168-
window.guardian.ophan.trackClickComponentEvent(
169-
event.currentTarget,
170-
);
171-
}
167+
void submitClickComponentEvent(
168+
event.currentTarget,
169+
renderingTarget,
170+
);
172171
handleClick(event);
173172
}}
174173
css={playIconStyles}
@@ -187,14 +186,10 @@ export const LoopVideoPlayer = forwardRef(
187186
<button
188187
type="button"
189188
onClick={(event) => {
190-
if (
191-
window.guardian?.ophan
192-
?.trackClickComponentEvent
193-
) {
194-
window.guardian.ophan.trackClickComponentEvent(
195-
event.currentTarget,
196-
);
197-
}
189+
void submitClickComponentEvent(
190+
event.currentTarget,
191+
renderingTarget,
192+
);
198193
event.stopPropagation(); // Don't pause the video
199194
setIsMuted(!isMuted);
200195
}}

0 commit comments

Comments
 (0)