YouTube Video Tracking with Google Tag Manager

In September 2017, Google released native YouTube video tracking in Google Tag Manager (GTM), which makes setting up Google Analytics event tracking for YouTube super easy. This blog post shows the steps to add YouTube video tracking to GTM, or you can skip to the end and download and import the pre-configured setup into your own GTM container.

OVERVIEW

YouTube video tracking lets you track interactions with any YouTube videos on your site. This includes play, pause, watch 10%, watch 25%, watch to end, etc.

STEP 1: SET A YOUTUBE VIDEO TRIGGER 

Click New Trigger and choose Trigger Type = YouTube Video

youtube-tracking-img1

 STEP 2: CHOOSE TRIGGER OPTIONS

The native YouTube trigger comes with several options to choose from. By default "Start" and "Complete" are selected, but you can also choose to track actions like Pause and Progress if you like. I recommend enabling all the tracking options.

If you select "Progress" you can choose between percentages (percent of video watched) and time thresholds (how long someone watched). Here we'll choose percentages, marking 25%, 50%, and 75% (100% will be tracked automatically using the "Complete" option).

We are also going to select Add JavaScript API support to all YouTube videos as in some cases the trigger won't work without it.

youtube-tracking-img2

STEP 3: SET UP YOUTUBE VARIABLES

Click Variables > Built In Variables > Configure, and choose the options you need. For this example we will choose Video Status, Video Title, and Video Percent.

youtube-tracking-img3

You can choose other Variables if you prefer. These are examples of the output you will see from each Video Variable:

VariableVariable TypeReturn TypeExample Values
Video Current TimeData Layer Variablenumber17
Video DurationData Layer Variablenumber212
Video PercentData Layer Variablenumber8
Video ProviderData Layer Variablestringyoutube
Video StatusData Layer Variablestringstart, seek, pause, progress, complete
Video TitleData Layer VariablestringBag Raiders - Shooting Stars
Video URLData Layer Variablestringhttps://www.youtube.com/watch?v=feA64wXhbjo
Video VisibleData Layer Variablebooleantrue, false

STEP 4: SET UP GA EVENT TAG

Click Tags > New > Universal Analytics > Event and fill in Category, Action, and Label. In this example, our naming logic is:

Category = Videos
Action = {{Video Title}}
Label = {{Video Status}} - {{Video Percent}}%

Add the YouTube Interactions trigger from step 2 and save.

youtube-tracking-img4

STEP 5: TEST THE TAG

Click Preview mode and interact with your video to ensure the tags are firing as expected.

Here I'll include an embedded video to test the output of the tag configuration above. Interact with the video and underneath you'll see exactly what gets passed to GA.

Event Category =
Event Action =
Event Label =

CONCLUSION

In summary, we added a native YouTube trigger provided by GTM, and configured it along with with variables to track the video name, percent played, etc. We then used this trigger and variables to configure a Universal Analytics event tag that sends this information to GA.

YOUTUBE VIDEO TRACKING CONTAINER IMPORT

If you want to import this exact setup so you can begin tracking YouTube videos with nearly zero configuration (just add in your own UA tracking ID), you can download this container.

Following that, click Admin > Import Container > Choose Container File, and set as follows:

Choose Workspace = New
Choose an Import Option = Merge > Rename conflicting tags, triggers, and variables

youtube-tracking-img5

Setting as above will not change or interfere with any of your existing tags.

The only configuration option required is to edit your GA tracking ID in the UA - YouTube Video tag. Confirm and test in preview mode, then Publish so it merges into your main workspace.

1 thought on “YouTube Video Tracking with Google Tag Manager”

Comments are closed.