Cardinal Path

YouTube Video Tracking with Google Tag Manager (V2) and Universal Analytics: A Step-by-Step Guide

In case you haven’t noticed, Google Tag Manager is getting an upgrade which will soon be automatically pushed by Google to all existing GTM V1 accounts starting June 1, 2015. Voluntary migration to this new version, V2, is also already in play. If you haven’t had a chance to familiarize yourself with the new version, then read more about it here.

Some of the changes include:

  1. “rules” are now renamed to “triggers”
  2. “macros” are now renamed to “variables”
  3. auto-event listeners are no longer needed, and firing a tag based on a click is done by creating a trigger type of “Click”
  4. built-in variables will replace the standard, built-in macros (eg. {{url}}, {{element id}}, {{event}}, etc.)

and there are many more!

This blog post is an update to our YouTube video tracking post, originally authored by Stéphane Hamel. We have highlighted the changes to Stéphane’s original GTM implementation to capture the changes needed to migrate your YouTube tracking from V1 to V2. The same prerequisites from the original V1 implementation apply to V2, and the only differences are in the configuration of the tags, triggers, and variables. We’ve also restructured the steps in Stephane’s original instructions to make it even more streamlined. So here we go!


Create Your Variables

Web Property ID

This variable holds the value of the GA web property ID to which data will be sent.

  • Variable name:
    • WebProperty ID
  • Variable type:
    • Constant
  • Variable configuration:
    • Value = UA-XXXXXX-Y (use your own web property ID)

Is YouTube Present?

This variable, when executed, checks the content of the page for any embedded YouTube. If found, “true” is returned, otherwise “false” is returned.

  • Variable name:
    • YouTube is present
  • Variable type:
    • Custom JavaScript
  • Variable configuration:
// Return "true" if there is at least one YouTube video on the page
function () {
   for (var e = document.getElementsByTagName('iframe'), x = e.length; x--;)
   if (/youtube.com\/embed/.test(e[x].src)){
      return true;
   }
   return false;
}

Data Layer Category

Define a macro that will hold the value of the event category name pushed from the data layer.

  • Variable name:
    • dataLayer category
  • Variable type:
    • Data Layer Variable
  • Variable configuration:
    • Data Layer Variable Name: eventCategory
    • Data Layer Version: Version 2

Data Layer Action

Define a macro that will hold the value of the event action name pushed from the data layer.

  • Variable name:
    • dataLayer action
  • Variable type:
    • Data Layer Variable
  • Variable configuration:
    • Data Layer Variable Name: eventAction
    • Data Layer Version: Version 2

Data Layer Label

Define a macro that will hold the value of the event label name pushed from the data layer.

  • Variable name:
    • dataLayer label
  • Variable type:
    • Data Layer Variable
  • Variable configuration:
    • Data Layer Variable Name: eventLabel
    • Data Layer Version: Version 2

Create Your Triggers

YouTube Event Trigger

Define a trigger that is executed when the dataLayer event name is “youtube”.

  • Trigger name:
    • YouTube event
  • Trigger event type:
    • Custom Event
  • Trigger fires on:
    • Event name: youtube

YouTube Present Trigger

Define a trigger that is executed when the value returned from the variable “YouTube is present” is true, and when the event is “gtm.dom”.

  • Trigger name:
    • YouTube present
  • Trigger event type:
    • Custom Event
  • Trigger fires on:
    • Event name: gtm.dom
    • “YouTube is present” equals true

Create Your Tags

YouTube Event Tag

This tag sends in the event data, that is pushed from the dataLayer, to the GA property.

  • Tag name:
    • YouTube Event
  • Tag product:
    • Google Analytics
  • Tag type:
    • Universal Analytics
  • Tag configuration:
    • Tag type: Universal Analytics
    • Tracking ID: {{WebProperty ID}}
    • Track Type: Event
    • Category: {{dataLayer category}}
    • Action: {{dataLayer action}}
    • Label: {{dataLayer label}}
    • Fields to Set: Field Name = “useBeacon”, Field Value = “true”
  • Tag firing rule:
    • Tag triggered by “YouTube event” trigger

YouTube Listener Tag

This tag detects if there are any embedded YouTube videos on the page. If there are, then it listens for various actions coming from interactions with those videos, or when the video progresses.

  • Tag name:
    • YouTube Listener
  • Tag product:
    • Custom HTML Tag
  • Tag configuration:
    • Tag type: Custom HTML
    • HTML: (click here for a copy of the YouTube listener code)
  • Tag firing rule:
    • Tag triggered by “YouTube present” trigger

 

Here is the code for you to copy/paste:

 


Don’t forget to thoroughly test your implementation in Preview mode before you go live with it.

Good luck with your YouTube video tracking! If you have any suggestions to improve this tracking, please don’t hesitate to let us know: nyuen@cardinalpath.com

Related Resources

New to Tag Management Systems (TMS)?  This article explains Why Tag Management is the Way Forward in 2016, our State of Digital Marketing Analytics in the Top 500 Online Retailers report summarizes the adoption rate of TMS in eCommerce, and our expert panel had a lively discussion about the insights uncovered by the report.

CP Marketing

Share
Published by
CP Marketing

Recent Posts

Optimizing user experiences with Digital Experience Analytics (DXA) platforms

As consumers become increasingly digitally savvy, and more and more brand touchpoints take place online,…

1 month ago

Enabling Value-Based Bidding with Google Tightlock

Marketers are on a constant journey to optimize the efficiency of paid search advertising. In…

1 month ago

Resolving “Unassigned” Traffic in GA4

Unassigned traffic in Google Analytics 4 (GA4) can be frustrating for data analysts to deal…

2 months ago

This website uses cookies.