From 4d1b85440c1114e972d1e6680d0a637c6133d302 Mon Sep 17 00:00:00 2001 From: Alex Sanders Date: Mon, 21 Oct 2024 16:08:28 +0100 Subject: [PATCH] report ophan events --- .../components/AudioPlayer/AudioPlayer.tsx | 171 +++++++++--------- 1 file changed, 85 insertions(+), 86 deletions(-) diff --git a/dotcom-rendering/src/components/AudioPlayer/AudioPlayer.tsx b/dotcom-rendering/src/components/AudioPlayer/AudioPlayer.tsx index 6c9d4f13e8..affa1e415f 100644 --- a/dotcom-rendering/src/components/AudioPlayer/AudioPlayer.tsx +++ b/dotcom-rendering/src/components/AudioPlayer/AudioPlayer.tsx @@ -1,7 +1,7 @@ import { log } from '@guardian/libs'; import type { AudioEvent, TAudioEventType } from '@guardian/ophan-tracker-js'; import { useCallback, useEffect, useRef, useState } from 'react'; -// import { submitComponentEvent } from '../../client/ophan/ophan'; +import { getOphan } from '../../client/ophan/ophan'; import { Playback } from './components/Playback'; import { ProgressBar } from './components/ProgressBar'; import { CurrentTime, Duration } from './components/time'; @@ -51,23 +51,23 @@ export const AudioPlayer = ({ // we'll send listening progress reports to ophan at these percentage points // through playback (100% is handled by the 'ended' event) - const ophanProgressEvents = useRef>( + const audioProgressEvents = useRef>( new Set([25, 50, 75]), ); // wrapper to send audio events to ophan - - const sendToOphan = useCallback( + const reportAudioEvent = useCallback( (eventName: AudioEvents) => { - const ophanEvent: AudioEvent = { + const audioEvent: AudioEvent = { id: mediaId, eventType: `audio:content:${eventName}`, }; - // TODO: figure out how to send events to ophan, for now just log them - console.log(ophanEvent); - - // return submitComponentEvent(ophanEvent, 'dotcom-rendering'); + void getOphan('Web').then((ophan) => { + ophan.record({ + audio: audioEvent, + }); + }); }, [mediaId], ); @@ -87,6 +87,79 @@ export const AudioPlayer = ({ // ref to the