diff --git a/src/constants.ts b/src/constants.ts index b2ae940..3e7cd20 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -48,4 +48,6 @@ export enum TrackingEvent { USED_RANDOM_TEAM_GENERATOR = 'usedRandomTeamGenerator', COMPLETED_GAME = 'completedGame', SEARCH = 'search', + VIDEO_PLAYED = 'videoPlayed', + VIDEO_CLOSED = 'videoClosed', } diff --git a/src/helpers/useVideoInModal.tsx b/src/helpers/useVideoInModal.tsx index cd460a5..ac985a6 100644 --- a/src/helpers/useVideoInModal.tsx +++ b/src/helpers/useVideoInModal.tsx @@ -1,5 +1,7 @@ -import React from 'react'; +import React, { useRef } from 'react'; import { useStore } from '../useStore'; +import { track } from './track'; +import { TrackingEvent } from '../constants'; type Props = { videoEmbedUrl: string; @@ -8,6 +10,7 @@ type Props = { export default function useVideoInModal({ videoEmbedUrl, videoTitle }: Props) { const { showModal } = useStore(); + const videoStartTime = useRef(0); const showVideo = () => { showModal({ @@ -19,12 +22,22 @@ export default function useVideoInModal({ videoEmbedUrl, videoTitle }: Props) { allowFullScreen allow="autoplay;" src={videoEmbedUrl} + onLoad={() => { + track(TrackingEvent.VIDEO_PLAYED, { videoTitle }); + videoStartTime.current = new Date().valueOf(); + }} frameBorder="0" /> ), okText: '', cancelText: '', size: '70%', + cancelCallback: () => { + track(TrackingEvent.VIDEO_CLOSED, { + videoTitle, + durationInSeconds: Math.round((new Date().valueOf() - videoStartTime.current) / 1000), + }); + }, }); };