docs: added video track event (#2010)

This commit is contained in:
Shahed Nasser
2022-08-08 11:27:48 +03:00
committed by GitHub
parent edd93bbecb
commit 1c6fcb2ede

View File

@@ -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 (
<>
<Layout {...props} />
</>
);
}