How to Track Videos in Google Analytics using Google Tag Manager

how to track videos in google analytics using google tag manager

Jump To:

Videos take a lot of time and effort to create so it’s especially important that you can track video engagement once you’ve added those videos to your website. Luckily, it’s pretty easy to track videos in Google Analytics using Google Tag Manager (GTM). 

In this guide, we are going to show you how to easily track video plays, pauses, completions, and progress in Universal Analytics and Google Analytics 4 using GTM. While there are several other video hosts, such as Vimeo, we are going to focus on tracking embedded YouTube videos, Vimeo videos, and HTML5 videos. HTML5 videos are most likely self-hosted videos that were uploaded directly to your website platform, such as WordPress.

Jump To

Identifying Your Video Host

In order to track your video engagement, we must first determine your video host. It may already be pretty obvious if your video is hosted on YouTube or one of the other bigger players, but if it’s not, right-click on the video and click inspect or press F12. This will bring up the HTML code in your browser’s DevTools panel. 

Don’t worry! Even if you’re not a developer, you don’t need to be scared by the Dev Tools panel. We’ll show you exactly how to use it.

Navigate to the Elements tab to look for your video. If you can’t find your video right away, you may need to expand some other elements to show the elements nested inside.  Mousing over different parts of the HTML code in your DevTools will highlight the corresponding element on your website which should help you narrow down to find your video. You can also use the Inspect tool as seen in the picture below.

DevTools inspect feature
Use Right Click + Inspect or press F12 to pull up Dev Tools in Chrome. From there, you can use the Inspect tool to mouse over elements on the website and find its node on the Elements tab of DevTools.

Your video will probably be in an <iframe> or a <video> node and it may even say the name of the video host. 

If you don’t see an <iframe> and your domain is listed after the “src=” attribute of your video, the video is self-hosted. This means it was probably just uploaded to your website CMS’s media library instead of another video host like YouTube. If this is the case, skip down to the next section to track self-hosted html5 videos in Google Analytics.

src attribute for self-hosted video in DevTools
This MP4 video file is a self-hosted HTML5 video player because the src attribute shows the domain. For example, if we are on example.com, then we would see “src=https://example.com/videoname.mp4”

If you see “youtube.com/embed” in the src attribute, like in the screenshot example below, then you’re in luck because Google Tag Manager makes it easy to track videos hosted on YouTube.

youtube video embedded in iframe in DevTools
In this example, this video is hosted on YouTube, which can be seen in two places: once in the src attribute and once in the class of the parent <div> above the iframe.

If you see “player.vimeo.com/video/” in the src attribute, like in the screenshot example below, then skip down to the last section to track Vimeo videos in Google Analytics.

Here you can see that this is an embedded Vimeo video because it says Vimeo in the title and src attributes of the iframe. Since it’s in an iframe, we’ll need a special listener.

YouTube Video Tracking In GTM

To save you even more time, we created a GTM recipe to automatically create Google Analytics events for YouTube videos, instead of setting everything up from scratch. This recipe is meant for Universal Analytics because Enhanced Measurement automatically tracks YouTube videos in Google Analytics 4 (GA4).

GTM youtube events trigger
Our GTM Recipe for tracking YouTube videos on your website creates events for Plays, Completions, and each 25% of progress

To make it easier for you to set up, we’ve created a GTM recipe that you can import into your GTM container. A GTM Recipe is just a small JSON file that can be more easily shared and added to other GTM containers. We use them a lot when setting up tracking and tagging for our clients because a lot of this stuff is reusable.

GTM Recipe: YouTube Video Tracking

To import this recipe into your GTM container, download our YouTube Video tracking GTM Recipe using the button below and follow the import instructions in the HTML4 video tracking section or check out our more detailed guide to importing a GTM container.

import YouTube event recipe in GTM
This is what your YouTube recipe import should look like in GTM.

Tracking Self-Hosted HTML5 Videos in Universal Analytics & Google Analytics 4 Using GTM

Besides uploading a video on YouTube or Vimeo, another common method of adding a video to your website is by uploading it into your website’s Content Management System (CMS) and hosting it on your domain. 

Unfortunately, the built-in GTM variable used in the above method only works for tracking YouTube videos. In order to track HTML5 video engagement in Google Analytics, we need to create a custom HTML tag in Google Tag Manager with an auto-event listener in it. If that sounds too complicated, feel free to just jump down to our (free) HTML5 Video GTM recipe below for easy setup and start tracking your HTML5 videos in Google Analytics

Now, before going any further, we’d like to give a shout-out to Julius Fedorovicius and David Vallejo. In 2014, David published the original version of the auto-event listener tag that’s used to power the HTML5 Video Tracking GTM Recipe, and Julius modified that GTM recipe to track HTML5 videos in Google Analytics 4. Julius’s website also has individual GTM recipes for tracking HTML5 videos on each version of Google Analytics. 

However, instead of 2 separate GTM recipes, we are going to take it a step further and use one upgraded GTM recipe that creates HTML5 video events in Universal Analytics and also Google Analytics 4. This reduces the number of tags and variables so that your website is faster and your GTM container is easier to maintain. 

GTM Recipe: Our Upgraded HTML5 Video Tracking Recipe for Universal Analytics And Google Analytics 4

To import our upgraded recipe for tracking HTML5 video engagement,

  1. Download our upgraded HTML5 video recipe
  2. Log into tagmanger.google.com
  3. From the Admin section, click “Import Container”
  4. Choose the JSON file you saved to your computer
  5. Add which GTM workspace you’d like to add the recipe to (If you don’t know, choose “Existing”)
  6. Choose Merge as the import option and make sure that there are 0 modified or deleted items. If you see any modified or deleted items, select “Rename conflicting tags, triggers, and variables” instead.
  7. After clicking Confirm, test your new YouTube events using GTM’s Preview mode and Publish the container when ready. 
Combined HTML5 Videos Recipe For Google Analytics 4 and Universal Analytics by Intigress

Vimeo Video Tracking In GTM

Of these GTM recipes, Vimeo video tracking is the most complicated because its event listener doesn’t work the same as the other two. With a little bit of Intigress magic, we ensured that our Vimeo GTM recipe fires events in Universal Analytics and Google Analytics 4 (GA4) with the same names as the other recipes on this page. This gives you clean data even if you need to use more than one of the recipes on this page. We’ll spare you the dirty details on how we did this and get right to it.

This is what your Google Analytics 4 Vimeo tracking event will look like

GTM Recipe: Vimeo Video Tracking

To import this recipe into your GTM container, download our YouTube Video tracking GTM Recipe using the button below and follow the import instructions above in the HTML5 section or we also have a more in-depth guide on importing a GTM Recipe.

This is what importing our Vimeo tracking GTM recipe should look like.

One last thing. Because of the way the Vimeo event listener works, this GTM recipe will fire a video_start GA4 event and a UA event with a start Event Action every time a video is played (which could be more than once). Because of this we also set the triggers so they won’t fire any “pause” events since there are no corresponding “play” events. If you would like to track pause events, you can add “pause” to the custom event trigger’s RegEx.

Video Tracking Events In Google Analytics

Our recipes are designed to be compatible with each other so that naming conventions are the same. No matter which recipe you used for your video eventing, you should see events firing on video engagements in both Universal Analytics and Google Analytics 4.

Don’t forget to update the recipes to make sure you’re using the correct tracking ID or Measurement ID.

In Universal Analytics, your events will look like this:

Universal Analytics will display Video as the event category, and the progress as the event action.

And here’s what they look like in Google Analytics 4.

Google Analytics 4 video events
Google Analytics video events have additional parameters too.

If you have any difficulties at all or it’s not working for you, feel free to contact us for assistance tracking videos in Google Analytics using Google Tag Manager or for other tracking and tagging assistance.

Have questions or found this helpful? Let us know in the comments below! 

4 Responses

  1. Hi, but is possible to know what videos are they watching ?

    I have google analytics 4, and I want to know of all the videos completed which ones are users watching and how many times.

    1. Yes. In both Universal Analytics and Google Analytics 4, you’ll be able to see all of that information. In GA4 specifically, look for the number of video_complete events to see how many times a video was watched to the end. You can then use the parameters to determine things like the video title.

    1. Vimeo video tracking is a bit trickier, but we have updated this article with a Vimeo tracking recipe. If you need any more assistance or are interested in our tagging & tracking service, please feel free to contact us.

Leave a Reply

Your email address will not be published.

Stay Up-to-date

Find this helpful? Sign up for our newsletter to get this delivered right to your inbox. Plus, get digital marketing news, expert insights, updates, and more.