Skip to content

Add video progress milestone tracking hook#15916

Merged
SHession merged 5 commits into
mainfrom
sh/add-video-milestone-tracking
May 20, 2026
Merged

Add video progress milestone tracking hook#15916
SHession merged 5 commits into
mainfrom
sh/add-video-milestone-tracking

Conversation

@SHession
Copy link
Copy Markdown
Contributor

What does this change?

This change implements video progress milestone tracking using a React hook and updates both the SelfHosted and YouTube players to use it. It will send events to Ophan when the video has progressed 25/50/75 percent through the video. If a user skips forward, tracking events will be sent for all milestones they have surpassed.

Current YouTube Atom Player implementation:

const checkProgress = () => {
const currentTime = player.getCurrentTime();
const duration = player.getDuration();
if (!duration || !currentTime) {
return;
}
const percentPlayed = (currentTime / duration) * 100;
if (!progressEvents.hasSent25Event && 25 < percentPlayed) {
log('dotcom', {
from: loggerFrom,
videoId,
msg: 'played 25%',
event,
});
for (const eventEmitter of eventEmitters) {
eventEmitter('25');
}
progressEvents.hasSent25Event = true;
}
if (!progressEvents.hasSent50Event && 50 < percentPlayed) {
log('dotcom', {
from: loggerFrom,
videoId,
msg: 'played 50%',
event,
});
for (const eventEmitter of eventEmitters) {
eventEmitter('50');
}
progressEvents.hasSent50Event = true;
}
if (!progressEvents.hasSent75Event && 75 < percentPlayed) {
log('dotcom', {
from: loggerFrom,
videoId,
msg: 'played 75%',
event,
});
for (const eventEmitter of eventEmitters) {
eventEmitter('75');
}
progressEvents.hasSent75Event = true;
}
const currentPlayerState = player.getPlayerState();
if (currentPlayerState !== YT.PlayerState.ENDED) {
/**
* Set a timeout to check progress again in the future
*/
setTimeout(() => checkProgress(), 3000);
}
return null;
};

Why?

Implementing this tracking for long-form video will help inform us how far through videos readers progressed.

@SHession SHession force-pushed the sh/add-video-milestone-tracking branch from a74275e to 98fc40d Compare May 19, 2026 11:27
Copy link
Copy Markdown
Contributor Author

@SHession SHession May 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may have gotten a little carried away with the refactor here. I can split it out if needed.

@SHession SHession added the feature Departmental tracking: work on a new feature label May 19, 2026
@SHession SHession force-pushed the sh/add-video-milestone-tracking branch from 98fc40d to 7e36a11 Compare May 19, 2026 11:28
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 19, 2026

@SHession SHession changed the title Sh/add video milestone tracking Add video progress milestone tracking hook May 19, 2026
@SHession SHession marked this pull request as ready for review May 19, 2026 11:37
@SHession SHession force-pushed the sh/add-video-milestone-tracking branch from 7e36a11 to 3275779 Compare May 19, 2026 11:38
@github-actions
Copy link
Copy Markdown

Hello 👋! When you're ready to run Chromatic, please apply the run_chromatic label to this PR.

You will need to reapply the label each time you want to run Chromatic.

Click here to see the Chromatic project.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 19, 2026

Comment on lines +11 to +13
* Returns a function that should be called on each time update.
* It tracks when a video crosses the 25%, 50% and 75% milestones and
* calls the provided callback for each.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will currently only fire once per video. There is ongoing debate about whether this is desirable.

Copy link
Copy Markdown
Contributor

@abeddow91 abeddow91 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a really nice abstraction! Tested on CODE and looks good to me 👍

Comment thread dotcom-rendering/src/components/YoutubeAtom/YoutubeAtomPlayer.tsx Outdated
@SHession SHession force-pushed the sh/add-video-milestone-tracking branch from 3275779 to 2b4f035 Compare May 20, 2026 10:49
@SHession SHession merged commit 1856fa6 into main May 20, 2026
30 checks passed
@SHession SHession deleted the sh/add-video-milestone-tracking branch May 20, 2026 12:04
@gu-prout
Copy link
Copy Markdown

gu-prout Bot commented May 20, 2026

Seen on PROD (merged by @SHession 9 minutes and 21 seconds ago) Please check your changes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Departmental tracking: work on a new feature Seen-on-PROD

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants