Skip to content
Merged
4 changes: 4 additions & 0 deletions src/components/video-embed/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
useMilestones,
} from './helpers'
import s from './video-embed.module.css'
import { trackVideoStart } from 'lib/posthog-events'

/**
* MAX_PLAYBACK_SPEED is based on max speeds for YouTube & Wistia.
Expand Down Expand Up @@ -142,6 +143,9 @@ function VideoEmbed({
{...reactPlayerProps}
config={config}
url={url}
onStart={() => {
trackVideoStart(url)
}}
onDuration={setDuration}
progressInterval={PROGRESS_INTERVAL}
onProgress={({ playedSeconds }: { playedSeconds: number }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import React from 'react'
import { DocsEnterpriseAlert } from './components/enterprise-alert'
import Image from 'components/image'
import { ImageProps } from 'components/image/types'
import VideoEmbed from 'components/video-embed'

// This function returns a simple object containing the default components
// The `additionalComponents` param is purely for convenience.
Expand Down Expand Up @@ -37,5 +38,6 @@ function _defaultComponents() {
return {
EnterpriseAlert: DocsEnterpriseAlert,
img: makeImageElement({ noBorder: true }),
VideoEmbed,
}
}
12 changes: 12 additions & 0 deletions src/lib/posthog-events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/

/**
* Enables PostHog video start tracking
*/
export function trackVideoStart(video_id: string) {
if (!window?.posthog) return
window.posthog.capture('video_start', { video_id })
}
Loading