From 1c6fcb2ede9b7b8ea67a87d4e2fdecf0f3bb7c6c Mon Sep 17 00:00:00 2001 From: Shahed Nasser Date: Mon, 8 Aug 2022 11:27:48 +0300 Subject: [PATCH] docs: added video track event (#2010) --- www/docs/src/theme/Layout/index.js | 37 ++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 www/docs/src/theme/Layout/index.js diff --git a/www/docs/src/theme/Layout/index.js b/www/docs/src/theme/Layout/index.js new file mode 100644 index 0000000000..4c36cc6004 --- /dev/null +++ b/www/docs/src/theme/Layout/index.js @@ -0,0 +1,37 @@ +import React, { useEffect } from 'react'; + +import Layout from '@theme-original/Layout'; +import useIsBrowser from '@docusaurus/useIsBrowser'; +import {useLocation} from '@docusaurus/router'; + +export default function LayoutWrapper(props) { + + const isBrowser = useIsBrowser(); + const location = useLocation(); + + useEffect(() => { + if (isBrowser) { + if (window.analytics) { + function handlePlay() { + window.analytics.track('video_played'); + } + + const videos = document.querySelectorAll('video'); + videos.forEach((video) => video.addEventListener('play', handlePlay, { + once: true, + capture: true + })) + + return () => { + videos.forEach((video) => video.removeEventListener('play', handlePlay)); + } + } + } + }, [isBrowser, location.pathname]); + + return ( + <> + + + ); +}