Have you ever wondered how you can track whether a visitor clicks on an embedded YouTube video on your website? It’s one of the coolest features of Google Analytics event tracking. In this tutorial, learn how to implement YouTube video event tracking using Google Analytics and Google Tag Manager.

Tracking events on your web pages is one of the key features of Google Analytics. However, you need to do some customizations to be able to track them. By default, only the page views are counted by GA. In another article, I had shown you how to track clicks on buttons and links using a Google Analytics and Tag Manager setup. In this article, shall we discuss how to you can track video views using GA? GA allows easy tracking of YouTube videos—YouTube being a Google property.

The key prerequisite is that you should be using GTM to implement GA and track page views on your site.

Sign into your Google Tag Manager account and head over to your Container Workspace. Here, click “Variables” and then “Configure.” Scroll down until you find the video-related variables and enable them all.

Image 3.1: Video Variables in GTM

Image 3.1: Video Variables in GTM

These are built-in variables with which GTM can track the video details from any embedded YouTube videos on your page.

Step 2: Create your video trigger

As the next step, you need to create a video trigger that can fire a tag for any specific video-related event. As the first step, we will create a general video trigger that will fire for all video plays. In a later step, we’ll modify the trigger to target the specific video you want to track.

In your Workspace, click “Triggers” and then “New.” Name your trigger and then click “Trigger Configuration” to create the trigger. In the Trigger Configuration window, select the trigger type as “YouTube Video.”

Image 3.2: Selecting YouTube Video Trigger

Image 3.2: Selecting YouTube Video Trigger

Step 3: Configure the general video trigger

In order to track various attributes related to the video, you can capture the start, complete, pause, seek, percentage viewed, etc. Select all the elements you want to track. Also, ensure you check “Add JavaScript API support to all YouTube videos.” Then select the “All Videos” radio button.

Image 3.3: YouTube Video Trigger Configuration

Image 3.3: YouTube Video Trigger Configuration

Now save the trigger and your general video trigger is ready. This will identify any video-related action on your web page. The trigger will automatically capture any video-related variable on your web page.

Step 4: Set up the GA video event tracking tag

Once you have the trigger ready, we can go ahead and create the regular event tracking tag of GA. Click “Tags” and then “New.” Name your tag and click “Tag Configuration.” Here, select “Universal Analytics” if you are using the latest GA tracking tag (otherwise, use the Classic option). In the “Track Type” option, select “Event” and provide the necessary parameters. Category and Action are the required parameters,s and the others are optional.

In general, you can put “Video” as the Category and select Action from a variable within by clicking the “+” button. “Video Status” is a good Action variable as it tracks the current status of the video player, such as “Start,” “Paused,” etc. For Label, you can select the video title by clicking the “+” button again and selecting the “Video Title” variable. For all these variables, you can also put any custom alphanumeric text you want as the input. For the Value parameter, you can specify a value if a video play has any revenue influence. Otherwise, you can leave it empty. Also select the correct Google Analytics settings variable as well.

Image 3.4: Google Analytics Video Tag

Image 3.4: Google Analytics Video Tag

Once you update all parameters, click “Save” to save the tag. It will ask you to add a trigger. Here, select the already created video trigger to fire the tag. Then save the tag.

Step 5: Test the trigger & the tag

Once you have set up the tag and associate the trigger to it, you need to test and ensure that the tag is actually firing properly for the trigger. Let’s see how this is done. First of all, you need to put GTM in Preview Mode by clicking the “Preview” button at the top right. You should now open the web page where YouTube videos are embedded to test if the tag is getting fired properly. Make sure the web page is opened in the same browser in a different tab. You should see the GA Preview & Debug pane at the bottom.

On the web page, click any video to start playing it and you should see a new “gtm.video” event being triggered. Click “gtm.video” and you should see that the new video-tracking tag has fired.

Image 2.5: Testing the General Video Tag

Image 2.5: Testing the General Video Tag

Clicking the tag name will show you all the variables and values associated with them. In my case, the video label and action are the two parameters set through variables (video title and video status respectively) and they are captured properly as shown below.

Image 2.6: Variables Captured by the Video Tag

Image 2.6: Variables Captured by the Video Tag

Based on all actions you do on the video, such as seek, pause, or complete, gtm.video events are triggered and your custom GA tag is fired. It sends all these event data to GA, tracking your actions on the YouTube video.

Step 6: Modify the trigger to fire only for a certain video

Now, you can modify the trigger if you want to fire the tag for only a specific video, and not all the videos. Reload the page and play the video that you actually want to track. Click the gtm.video event that was triggered and then click the “Variables” tab.

Image 2.7: Video Variables in GTM Preview Pane

Image 2.7: Video Variables in GTM Preview Pane

Scroll down to all the video-related variables. Here, among the variables, find a unique variable that can identify that video among others. Video Title or Video URL can be good candidates for this. I’ll use the Video Title variable in my case. The title of this particular video is “Eminem – Love The Way You Lie ft.Rihanna” as you can see. Copy this text exactly, without including any whitespace or line break in between.

Now, within GTM, open up the video trigger you created and under Trigger Configuration, instead of “All Videos,” select “Some Videos.” Then select the variable as “Video Title” and put the title of the video there as shown.

Image 2.8: Narrowing Down the Video Trigger

Image 2.8: Narrowing Down the Video Trigger

Once done, save the trigger and refresh the Preview Mode.

Step 7: Test the trigger and tag once again

Now, after you have saved the Preview Mode, get back to your web page and try playing a different video. Check and see if the gtm.video event is firing the video tag. Only when our targeted video is played, the tag is fired. For the other actions on the video, such as pause, stop, etc., also the video tag should be fired properly. If this is happening, your tag is working properly.

Make sure you exit the Preview Mode in GTM and publish the Container now. Only after publishing the Container, the tag will be actually implemented on the site.

Common Pitfalls

There are some situations in which this tracking setup could fail. While working on this, I encountered several issues that I would like to point to you now. For instance, if you don’t select the advanced option “Add JavaScript API support to all YouTube videos,” your video trigger may not work for all videos. It will be triggered only for videos that have JS API support. With this checkbox checked, the JS API support is provided to any embedded YouTube video. Only downside is, once the event is triggered, the video may reload.

In our company’s home page, we have a YouTube video which never triggered the tag. I believe it’s because of the complex coding on the home page and presence of too many elements.


Go right ahead & share your thoughts!