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.
These are built-in variables with which GTM can track the video details from any embedded YouTube videos on your page.
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.”
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.
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.
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.
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.
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.
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.
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.
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.
Once done, save the trigger and refresh the Preview Mode.
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.
There are some situations in which this tracking setup could fail.
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.
Web analytics applications such as Mouseflow do this kind of tracking by default.
Lenin VJ Nair
Lenin Nair has years of experience in marketing for software and technology domains. He is a certified specialist in marketing and enjoys exploring new ways to market products and services for small and medium businesses. He enjoys reading, writing, traveling, and ideating. He holds an MBA in marketing and a bachelor's degree in IT.