(713) 568-2763

Web Analytics Recipe Book: How to Track Embedded YouTube Videos with Google Tag Manager

Web Analytics Recipe Book: How to Track Embedded YouTube Videos with Google Tag Manager

One of my favorite hobbies is cooking. For me it’s a fun, relaxing, creative, and (sometimes) healthy activity that can be enjoyed every day. The best part? You have a tasty meal to share when you’re finished.

While cooking from a recipe is not going to win any Food Network awards, everybody’s gotta start somewhere. If you’re more of a creative type, today’s post on YouTube video tracking in Google Tag Manager may feel a bit like following a recipe. But bear with me and I promise you’ll have a feast of data when we’re finished.

Like every good recipe, we’ll entice you with a picture of what you’ll have when all the work is done. Below is a screenshot of what your new Google Analytics Top Events report will look like after following along:

How to Track YouTube Videos 1

Is your mouth-watering yet? Great. But before we can really get cookin’, we’ll need to gather our ingredients and do a bit of prep work.


First, you will need a Google Tag Manager account. For this tutorial, we will assume that you already have an active Google Tag Manager account and a basic understanding of the tool. If are you new to Google Tag Manager, we recommend an appetizer course at https://www.google.com/tagmanager/ before coming back to visit.

Secondly, each YouTube video that you intend to track will need to be tagged. Add ?enablejsapi=1 to the link in the embed code like so:

Master Ingredient:

We don’t want you to do all the heavy lifting, so if you’re just looking for a .json file that you can directly import into your Tag Manager container, we’ve got you covered. Just click here.

Feel free to follow along with the nitty gritty below, but there’s no shame in taking the easy way out.


With the prep work out of the way, it’s time to get started. For this recipe, we are referencing the work of Himanshu Sharma shared on Optimize Smart. In our evaluation, Sharma’s setup offers a great degree of detail and analysis potential. At Forthea, since we are always looking to increase speed-to-insight, we have aimed to provide the set up steps as concisely as possible below. For a more in-depth read, please see Sharma’s original post here.

Step 1: Create the YouTube is Present Macro

Macro Name: YouTube is Present
Macro Type: Custom Javascript
Custom Javascript:

This is what it will look like in Google Tag Manager:

How to Track YouTube Videos 2

Step 2: Create Macros for Event Action, Event Category, and Event Label

A: Event Action Macro (Click title to see screenshot)

Macro Name: Event Action
Macro Type: Data Layer Variable
Data Layer Variable Name: eventAction
Data Layer Version: Version 2
Default Value: (blank)

B: Event Category Macro

Macro Name: Event Category
Macro Type: Data Layer Variable
Data Layer Variable Name: eventCategory
Data Layer Version: Version 2
Default Value: (blank)

C: Event Label Macro

Macro Name: Event Label
Macro Type: Data Layer Variable
Data Layer Variable Name: eventLabel
Data Layer Version: Version 2
Default Value: (blank)

Step 3: Create YouTube Listener Tag & Check for YouTube Present Firing Rule

Next, you’ll need to create some custom firing rules in your GTM.

A: Tag Information (Click for screenshot of implementation)

Tag Name: YouTube Listener
Tag Type: Custom HTML Tag
HTML: See Below.

B: Firing Rules

Rule Name: Check for YouTube Present
{{event}} equals gtm.dom
{{YouTube is Present}} equals true

Step 4: Create UA YouTube Video Tracking – Video Page Tag & Check for YouTube Event Rule

A: Tag Information (Click for screenshot of implementation)

Tag Name: UA YouTube Video Tracking – Video Page
Tag Type: Universal Analytics
Tracking ID: (your Google Analytics ID)
Track Type: Event
Event Tracking Parameters:
            Category: {{Event Category}}
            Action: {{Event Action}}
            Label: {{Event Label}}

B. Firing Rules

Rule Name: Check for YouTube Event
{{event}} equals youtube

Step 5: Preview and Debug Google Tag Manager setup on your website

After entering Preview and Debug Mode in Google Tag Manager, open a new tab and navigate to a page of your website that contains an embedded YouTube video. When the page loads, the YouTube Listener tag should fire. Now click to begin playing the video. With your click, the UA YouTube Video Tracking – Video Page tag should also fire (Note: Since the UA YouTube Video Tracking – Video Page tag fires for every video action (play, pause, 0% played, 25% played, 50% played, 75% played, 100% played), you will see multiple fires in preview and debug mode).

How to Track YouTube Videos 10

Step 6: Create and Publish Google Tag Manager Container

If the YouTube tags are firing correctly, it’s time to take it live. Within GTM, click Publish > Create Version and Publish to place these tags on your site.

Step 7: Check Your Google Analytics Real-Time Report

Now navigate to Real-Time > Events within your Google Analytics account. You should see a new event category, Youtube Videos. Click on this new category, and there you’ll find the meat of your data. You will see 3 columns: Event Action, Event Label, and Events. With this configuration, the data in each column is as follows:

Event Action: Page Title of embedded YouTube video
Event Label: Video action – Title of YouTube video
Events: # of occurrences of each action per video

How to Track YouTube 11

Step 8: Sample your YouTube data feast (and don’t forget to share)

Below is a quick chart created with data gathered after setting up YouTube tracking for a client, comparing engagement of two different video versions. We see that for the first version of the video, nearly 70% video plays were paused or abandoned before the 25% play mark. Ouch. But after the video was updated, 67.1% video plays lasted at least through the first quarter. With this data we are also able to see that the percentage of 100% completed plays nearly tripled, from 10.8% to 31.6%. Now wasn’t that worth all your effort?

How to Track YouTube 12

And it gets better. Since your new video data lives in Google Analytics as events, this opens up all the segmentation level data available to you in Analytics. This means you can create advanced segments, dimensions, and goals around video plays.

So as the holidays are closing in, make sure you have your analytical house in order. It takes some heavy lifting now, but you’ll have a treasure trove of data to pour through when the New Year rolls around.

Davis Baker
Davis is the PPC Team Lead at Forthea and a digital advertising veteran of six years. Outside of the office, you can find Davis running, riding his dirt bike, or searching for the perfect cup of coffee (freshly ground and brewed with a French press. Anything less just won't cut it).


  1. Joergen 4 years ago

    Nice work. Tried to import the .json file though but it did not work. Neither did a manual setup. What to do?

  2. Madhusudan Sura 4 years ago

    Hi Matthew,

    i followed step by step method as suggested in the blog for youtube video tracking. but None of Tags are firing whenever youtube video page get loads. like you have shown

    my page is :http://digitalanalyticswork.blogspot.in/p/y.html

    Please help me to understand the where is problem

    Looking forward for your reply


  3. Adam 4 years ago

    JSON file is now outdated. Needs an update for GTM v2.

  4. Nicolas Colombres 4 years ago

    Indeed Adam. An update would be awesome and usefull 😀


  5. Nicolas Colombres 4 years ago

    Adam Im with you. It would be awesome if you can updated this article for GTM 2.0 🙂

    Thanks in advance!

Leave a reply

Your email address will not be published. Required fields are marked *