Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experiment with posthog tracking for video embeds starts #2699

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 { onVideoStart } from 'hooks/use-posthog-analytics'

/**
* 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={() => {
onVideoStart(url)
}}
onDuration={setDuration}
progressInterval={PROGRESS_INTERVAL}
onProgress={({ playedSeconds }: { playedSeconds: number }) => {
Expand Down
10 changes: 10 additions & 0 deletions src/hooks/use-posthog-analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ function onRouteChangeComplete() {
window.posthog.capture('$pageview')
}

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

/**
* Enables PostHog page view tracking on route changes
*/
Expand Down
Loading