Skip to content

Expand self-hosted video milestone tracking#15933

Open
SHession wants to merge 8 commits into
mainfrom
sh/expand-milestone-tracking
Open

Expand self-hosted video milestone tracking#15933
SHession wants to merge 8 commits into
mainfrom
sh/expand-milestone-tracking

Conversation

@SHession
Copy link
Copy Markdown
Contributor

@SHession SHession commented May 20, 2026

What does this change?

Continues the work of #15916 and uses the hook for tracking PLAY and END (new for the self-hosted player) milestone events. Furthermore it allows PLAY and other milestones to be called multiple times for a single atom by introducing a resetMilestones function. When this is called milestones tracking events will be triggered again when reached.

Using the hook to store the hasSentX reduces boilerplate and makes the consuming code cleaner as it has fewer concerns. It should also provide stronger guarantees of consistent tracking behaviour between the YouTube and SelfHosted videos.

Testing

I have tested across the major browsers, Chrome, Safari and Firefox. I noticed some issues on Firefox with END event requests seemingly not firing inconsistently. I'm not sure if this was an issue with the developer tools or the implementation. I would value a second opinion.

@SHession SHession force-pushed the sh/expand-milestone-tracking branch from 7bda2e8 to e3248c9 Compare May 20, 2026 14:33
@SHession SHession added the feature Departmental tracking: work on a new feature label May 20, 2026
@SHession SHession changed the title Sh/expand milestone tracking Expand self-hosted video milestone tracking May 20, 2026
@SHession SHession force-pushed the sh/expand-milestone-tracking branch from e3248c9 to ff80f1d Compare May 20, 2026 14:40
@SHession SHession requested a review from Copilot May 20, 2026 14:44
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 20, 2026

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR extends the existing video milestone tracking hook so it can also track play and end events (in addition to 25/50/75%), and introduces a reset mechanism so milestones can be emitted again for the same video atom (e.g. replay). It updates both the YouTube and self-hosted players to use the hook-driven state rather than local booleans.

Changes:

  • Expand useVideoMilestoneTracking to handle play/end and provide a resetMilestones function.
  • Update YoutubeAtomPlayer to use the hook for play/end/milestones and remove bespoke progress event refs.
  • Update the self-hosted player to fire ended events, integrate the hook, and support milestone resets.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
dotcom-rendering/src/lib/useVideoMilestoneTracking.ts Extends the hook API to support started/ended events and milestone reset.
dotcom-rendering/src/components/YoutubeAtom/YoutubeAtomPlayer.tsx Replaces local progress tracking with the hook and adds reset on end.
dotcom-rendering/src/components/SelfHostedVideoPlayer.tsx Adds an ENDED state and wires an onEnded handler through to the <video> element.
dotcom-rendering/src/components/SelfHostedVideo.island.tsx Switches play/end/milestone tracking to the hook and introduces milestone reset logic.
Comments suppressed due to low confidence (3)

dotcom-rendering/src/lib/useVideoMilestoneTracking.ts:98

  • resetMilestones is recreated on every render, which makes it an unstable dependency for consumers (e.g. it’s included in YoutubeAtomPlayer’s useEffect deps). Consider wrapping resetMilestones (and clearMilestones) in useCallback (or storing clearMilestones in a ref) so callers can treat it as stable and avoid unnecessary effect re-runs.
	const resetMilestones = () => {
		if (milestones.current.hasSentEnd) {
			milestones.current = clearMilestones();
		}
	};

dotcom-rendering/src/components/SelfHostedVideo.island.tsx:940

  • The comment says this tracks the first successful play, but onPlaying can fire multiple times (initial play, resume after pause, possibly after seeking). If the intent is “track play/resume milestones via the hook”, please update the comment to avoid implying it only runs once.
	/**
	 * Track the first successful video play in Ophan.
	 */
	const handlePlaying = () => {
		trackMilestones({ started: true });

dotcom-rendering/src/components/SelfHostedVideo.island.tsx:1094

  • With loop/cinemagraph styles (videoStyle !== 'Default'), percentage milestones are disabled but the hook still emits end once percent >= 99. Combined with resetting milestones when currentTime < 1, looping videos are likely to emit end + play repeatedly on every loop iteration, which can flood Ophan with events. Consider gating end/reset behavior behind videoStyleSettings.loop === false, or disabling play/end milestone tracking for looping styles.
			if (video.currentTime < 1) {
				resetMilestones();
			}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread dotcom-rendering/src/lib/useVideoMilestoneTracking.ts
Comment on lines +224 to +228
/**
* Set a timeout to check progress in the future
*/
setTimeout(() => {
checkProgress();
Comment thread dotcom-rendering/src/components/SelfHostedVideo.island.tsx Outdated
@SHession SHession marked this pull request as ready for review May 20, 2026 15:28
@SHession SHession force-pushed the sh/expand-milestone-tracking branch from fba7286 to 5fb7e3b Compare May 20, 2026 15:28
@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.

@SHession SHession force-pushed the sh/expand-milestone-tracking branch from b3a1d4e to 5fb7e3b Compare May 21, 2026 07:05
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants