How to track your embedded YouTube videos with Google Tag Manager

Tracking YouTube videos embedded on your website doesn't need to be complicated. Here are the steps you'll need to follow to track people watching your videos in Google Analytics (and you can also watch my video tutorial below).

Step 1

Enable the built-in video variable inside Google Tag Manager. To do this navigate to 'Variables' and click 'Configure'. Then you just need to select the video variables at the bottom of the panel.

Tracking YouTube

Step 2

Next you'll need to create a custom variable by clicking 'New' and selecting 'Custom JavaScript'. Name the variable 'Video Action' and enter the following code for the new variable and then click 'Save'.

function() {
  var status = {{Video Status}};
  switch (status) {
    case 'start':
      return 'Play';
    case 'pause':
      return 'Pause';
    case 'seek':
      return 'Seeking';
    case 'progress':
      return + {{Video Percent}} + '% Watched';
    case 'complete':
      return '100% Watched';

Your new variable should look like this:

Tracking YouTube

Step 3

Navigate to 'Tags' and click 'New' to create a new tag. Select 'Universal Analytics' as the tag type and select 'Event' as the track type. Then you'll need to enter 'YouTube' as the 'Category' and select your new variable for the 'Action' (this will be 'Video Action' from the previous step). Then select 'Video Title' as the variable for 'Label' and select your Google Analytics tracking ID for the tag. Your tag should look like this:

Tracking YouTube

Now you need to create a new trigger for the tag.

Tracking YouTube

Select 'YouTube Video' as the trigger type and enable all of the 'Capture' options. For 'Percentages' enter 25,50,75 and enable the option to 'Add JavaScript API support'. Your trigger should look like this:

Tracking YouTube

Step 4

Save the trigger and tag, then publish your changes to your website. Now you'll be tracking all of your embedded YouTube videos into Google Analytics. You'll be able to report on people playing, pausing, watching 25%, 50%, 75% and 100% of your videos.

Video Tutorial

You can also walk-through these steps in my video tutorial: