Sub topic 7
Video engagement for embedded YouTube players
What this chapter assumes
You have a GA4 property with a web data stream and the Google tag (gtag.js or Google Tag Manager) installed. You know that GA4 records everything as events with parameters, and you can find the data stream settings in Admin. You can read basic HTML and JavaScript.
This chapter covers the video engagement option of enhanced measurement. You will learn which events it records, which parameters they carry, what a page must contain for them to fire, and how to test and troubleshoot them.
What the option records
When video engagement is on, GA4 records three events for embedded YouTube players. The events fire only for YouTube. Vimeo, Wistia, self-hosted <video> elements and other players are not covered.
| Event | When it fires |
|---|---|
| `video_start` | The video starts playing. |
| `video_progress` | The video passes 10%, 25%, 50% and 75% of its length. |
| `video_complete` | The video reaches its end. |
Each event carries the same set of parameters.
| Parameter | What it holds |
|---|---|
| `video_current_time` | Playback position, in seconds, when the event fired. |
| `video_duration` | Total length of the video, in seconds. |
| `video_percent` | The progress threshold reached (10, 25, 50, 75). Only `video_progress` carries it. |
| `video_provider` | The player provider. For this feature the value is `youtube`. |
| `video_title` | The video title. |
| `video_url` | The URL of the video. |
| `visible` | Whether the video was visible in the viewport (`true` or `false`). |
GA4 builds these events in the browser. The Google tag attaches to the YouTube player on the page and listens to its state changes. This is why the page's markup matters, as the next section explains.
The enablejsapi requirement
The tag can only listen to a YouTube player that exposes the YouTube IFrame Player API. An embed exposes it when its URL includes enablejsapi=1. Without that parameter, the player gives the tag no events, and GA4 records nothing for that video.
<iframe
width="560" height="315"
src="https://www.youtube.com/embed/VIDEO_ID?enablejsapi=1"
title="Product walkthrough"
allowfullscreen></iframe>Three practical points follow from this.
- The embed must be an iframe on the page that carries your Google tag. The tag cannot see into a video on a page that does not load it.
- Embed code copied from the YouTube "Share > Embed" dialog usually does not include
enablejsapi=1. You must add it yourself, or have your CMS or video plugin add it. Many WordPress video plugins have an option for this. - Videos injected after the page loads, for example in a modal window or tab, can be missed. The tag looks for players when it loads and when the page changes. If your video is added later, test it carefully, and see the section on pitfalls below.
If the embed loads from youtube-nocookie.com, the tag still recognises it as long as it is a YouTube iframe with the API enabled. Test it anyway, because consent settings can change when the tag runs.
Turning the option on
Video engagement is one of the enhanced measurement toggles. To check it:
- Open Admin and select Data streams.
- Select your web data stream.
- Under Enhanced measurement, confirm the switch is on, then select the gear icon.
- Confirm that Video engagement is selected. Save the settings if you change anything.
The video toggle has no sub-settings. You cannot choose which thresholds are sent or which videos are tracked. It is on for every qualifying embed or off for all of them.
Testing with DebugView
Test on a page you control, with debug mode on. The following snippet is a standard Google tag with debug_mode enabled. Replace G-XXXXXXXXXX with your measurement ID.
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXXXXX', { debug_mode: true });
</script>Place it inside the <head> of an HTML page, not in a standalone .js file. Remove debug_mode when you finish testing, or leave it off in production. Debug traffic is separated into DebugView, but it clutters the setup if you forget it.
Then follow these steps.
- In GA4, open Admin > DebugView.
- Load your page in a browser with no ad blocker running. Blockers often stop the Google tag.
- Press play on the video and let it run for a while.
- Watch the stream in DebugView. You should see
video_startshortly after you press play. - Skip ahead, or let the video run, to cross the progress thresholds. You should see
video_progressevents withvideo_percentvalues of 10, 25, 50 and 75. - Let the video end to see
video_complete. - Click an event in the stream to open its parameters and check
video_title,video_urlandvideo_duration.
If you use Google Tag Manager, you can use Tag Assistant preview instead. Connect it to your page, play the video, and look for the video events in the summary on the left. Both tools show the same events from the browser, so use whichever fits your setup.
A common mistake is to scrub straight to the end of the video. Skipping ahead may not trigger the intermediate video_progress events. Let the video play through each threshold, or check a short video, when you want to see all of them.
Using the events in reports
The video events appear in Reports > Engagement > Events as soon as processing completes. The parameters are different. A parameter is available for reporting only after you register it as a custom dimension or custom metric.
For video analysis, the useful ones are:
| Parameter | Register as | Scope | Use |
|---|---|---|---|
| `video_title` | Custom dimension | Event | Compare videos by name. |
| `video_percent` | Custom dimension | Event | Break `video_progress` down by threshold. |
| `video_provider` | Custom dimension | Event | Rarely needed, since the value is always the same here. |
| `video_duration` | Custom metric | Event, unit: seconds | Average video length. |
To register one, open Admin > Custom definitions > Create custom dimension. Enter a name, choose scope Event, and type the parameter name exactly as written, such as video_title. New definitions apply from the time you create them. They do not fill in older data.
Once registered, use Explore to build a free-form table with video_title as a row and event count for video_start and video_complete as values. The ratio of the two gives a rough completion rate.
You can also mark an event as a key event. If watching a product video to the end matters to your business, mark video_complete as a key event under Admin > Events. Think about this before you do it. Key events feed conversion reporting and can change how you evaluate campaigns. Mark only the events that signal a real business outcome.
Limits and pitfalls
- YouTube only. Other players produce no events. Use custom events for them.
- Requires
enablejsapi=1. This is the most common reason for missing events. - Fixed thresholds. You get 10%, 25%, 50% and 75%. You cannot change them.
- Late-loaded players. Videos added after the page loads, or in iframes created by scripts, may not be picked up.
- Cross-domain iframes. The tag has to run on the page that contains the iframe. It cannot run inside the YouTube player.
- Duplicate events. If you add your own tag that sends
video_start,video_progressorvideo_complete, you will count the same plays twice. Either turn off the enhanced option or give your custom events different names. - Autoplay and muted playback. A muted autoplay background video still triggers
video_start. Visitors who never chose to watch the video inflate your numbers. Thevisibleparameter helps you spot cases where the player was off screen, but it does not remove them. - Looped playback. A looping video can send
video_completemany times for one visit. - Consent. If your consent banner blocks the Google tag until the user agrees, plays before consent are not recorded.
- Ad blockers. Browsers that block the tag will send nothing.
Custom event alternative
When you need other players, other thresholds, or a clean event for a single important video, turn off the enhanced option and send your own events. The following sketch uses the YouTube IFrame Player API to send a custom event at the halfway point.
<script src="https://www.youtube.com/iframe_api"></script>
<script>
let player;
let halfSent = false;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
events: { onStateChange: onStateChange }
});
}
function onStateChange(e) {
if (e.data === YT.PlayerState.PLAYING && !halfSent) {
setTimeout(function check() {
const t = player.getCurrentTime();
const d = player.getDuration();
if (d > 0 && t / d >= 0.5) {
halfSent = true;
gtag('event', 'video_halfway', {
video_title: player.getVideoData().title
});
} else if (player.getPlayerState() === YT.PlayerState.PLAYING) {
setTimeout(check, 1000);
}
}, 1000);
}
}
</script>The matching iframe needs id="player" and enablejsapi=1 in its URL. This sketch shows the idea. A production version would also handle pauses, replays and several videos on one page. The event is named video_halfway, so it cannot collide with the built-in names.
Quick checklist
- Video engagement is on in the data stream settings.
- Each YouTube iframe has
enablejsapi=1in itssrc. - The Google tag loads on the page that contains the iframe.
- DebugView shows
video_start,video_progressandvideo_completefor a test play. - The parameters you need are registered as custom dimensions or metrics.
- No custom tag sends events with the same names.
Exercise
Your team embedded a YouTube video using the code from YouTube's Share > Embed dialog. Video engagement is switched on in the data stream, but DebugView shows no video_start events when you play the video. Page views and scroll events do appear. What is the most likely cause, and how do you fix it?
Show answer
The iframe URL most likely lacks enablejsapi=1, so the Google tag cannot listen to the player. Add ?enablejsapi=1 to the embed URL (or &enablejsapi=1 if the URL already has a query string), reload the page, and play the video again. Page views and scroll events work because they do not depend on the player API. If events still do not appear, check that the video is not injected after page load and that the Google tag loads on that page.
Exercise
You want to report which videos viewers finish. Which event do you use, which parameter do you register as a custom dimension, and why do you have to register it?
Show answer
Use videocomplete, and register videotitle as an event-scoped custom dimension. GA4 stores event parameters, but it makes them available in Explore and standard reports only after you register them as custom dimensions or metrics. Without registration, video_title appears in DebugView but not as a reporting field.