The original article was written on May 22, 2019, and it focused on sending data to Google Analytics Universal. However, during the migration of the blog to a new CMS, I decided to update the content to reflect the current version — Google Analytics 4.
Video production is not a cheap pleasure. And if you’ve created a video, it’s important to understand how users interact with it. If you're using Google Tag Manager in your work, tracking this is not difficult.
To configure the setup, we will need:
The developers of Google Tag Manager did a great job. The YouTube Video trigger tracks most user interactions with videos. It works perfectly both with videos embedded directly on the page and with those dynamically loaded after a user action.
To create a new trigger, select the appropriate type from the User Engagement section.
We can conditionally divide the setup into 4 steps:
Налаштування можемо умовно поділити на 4 етапи:
IMPORTANT! When using this option, the video will reload, and users may notice a flicker.
3. Enable this trigger on – Here you can select when the trigger should be enabled. If you're unsure what to choose, use Window Load. You can read more about page load events in another article on this blog.
4. This trigger fires on – If you want to use additional conditions for the trigger, specify them in this block.
Each of the listed variables stores additional information that you can use:
true
or false
depending on whether the video is visible in the viewport.All these variables get their values from the data layer:
The variable solution is a kind of workaround. As you may have noticed, there are quite a few built-in variables storing video event data. So we’ll combine several values to send more information to Google Analytics 4 in a more convenient format.
We need a variable of the Lookup Table type with the following configuration:
Here's how it works:
Of course, this logic can also be implemented using JavaScript. It depends on what’s more convenient for you. As a result, we now see more detailed information about the Progress
event.
Now all we have to do is compile our data into a Google Analytics 4 event tag — and it’s coffee time. The configuration looks like this:
If needed, you can add additional parameters to your event to pass more data from built-in variables.
And don’t forget to add the trigger created in the first step.
The method described in this article, while allowing you to track many video interactions, still has some limitations. For example, the Progress
event applies to the total video length. In other words, the user doesn’t have to watch the video continuously for this event to fire — they just need to reach the threshold moment.
Another point worth emphasizing is the tracking of videos that load and embed after the initial page load. The trigger does support tracking such videos, but make sure the page loads the YouTube API library.
If the required library isn’t being loaded — you can include it using the following code snippet:
<script src="https://www.youtube.com/iframe_api"></script>
You can insert this via a Custom HTML tag:
And although this data is now collected in GA4 using enhanced measurement, this article remains relevant, as the approach can still be useful for passing video interaction data to other systems (e.g., to create audiences in Meta Ads) or in cases where enhanced measurement doesn’t work due to the missing YouTube API library (see the note in the Instead of Conclusion).
If you enjoyed this content, subscribe to my LinkedIn page.
I also run a LinkedIn newsletter with fresh analytics updates every two weeks — here’s the link to join.
Web Analyst, Marketer