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:
“rules” are now renamed to “triggers”
“macros” are now renamed to “variables”
auto-event listeners are no longer needed, and firing a tag based on a click is done by creating a trigger type of “Click”
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
Your one-stop-shop for everything Google Marketing Platform, designed to help marketers stay informed and up-to-date on product news, solutions, how-to’s, and more.
You should receive a confirmation email from GoToWebinar with your unique webinar login information. If you do not receive this email or have trouble logging in to the event, please email asmaa.mourad@cardinalpath.com.
Thank you for subscribing!
You're now looped into the world's largest GMP resource hub!