Dec. 15. 2017.

Tutorial: Google Analytics YouTube Video Tracking Made Easy

Memba' the days when you had to try and use your "I kinda know programming but not really" skills to try and implement YouTube video tracking in Google Tag Manager? Well my friend, I am happy to announce that those days are long gone. Back in September, Google Tag Manager added a YouTube video trigger which makes tracking YouTube engagement in Google Analytics soooo much easier. Huzzah! And I am here to show you how to do it!* 

*Please note that this is not a great tutorial for absolute GTM beginners. I do not include how to preview, publish, or test your event in Google Analytics. The below is assuming you already know the basics. 

Step 1: Enable The YouTube Built-In Variables

To do this, get on over to the "Variables" area of Google Tag Manager and click on that big ol' "Configure" button. Make sure the YouTube video triggers are enabled/configured so you can easily refer to them when creating your event. To learn more about what each of these variables translate to, check out the Google's documentation on GTM video variables


GTM Video Tracking

Step 2: Add A Custom JavaScript Variable For a Cleaner Format 

I got this tip from Simo Ahava who is basically the most helpful GTM guy that ever was. This doesn't make as much sense at this exact moment but it will when you're creating your tag in Step 3. 

While you're still in the variables area after Step 1 above, go down to "User-Defined Variables" and click on that big red "New" button that you've already come to love. 

Call this guy "JS - Get video action", click under "Variable Configuration", and select "Custom JavaScript". Once there, paste this ol' chunk of code into there and save:

function() {
  var status = {{Video Status}};
  switch (status) {
    case 'start':
      return 'Start playing';
    case 'pause':
      return 'Pause';
    case 'buffering':
      return 'Buffering';
    case 'progress':
      return 'Reached ' + {{Video Percent}} + '%';
    case 'complete':
      return 'Reached the end';
  }
}

Step 3: Get That Tag All Ready To Go

In the "Tags" area, go on and click on that big red "New" button. Select "Tag Configuration > Universal Analytics". 

From there, take a looksie at the screenshot below on what to put in the "Category", "Action", and "Label" fields. You can really put whatever you like here, this is just my personal preference:

GTM YouTube Tracking

Step 4: Get Trigger Happy And Config' that Trig'!

Under your freshly created tag, click under "Triggering" and configure it like so:

GTM YouTube Trigger

Step 5: Grab Yourself a Glass O' Wine And Have a Good Cry

Those are tears of happiness folks, because you just showed GTM who's boss! If you follow all of the steps above, this will work for most YouTube video situations.

Enjoy that wine!