Hey there!
I'm Benjamin from Loves Data.
In this video I'll show you how to track YouTube videos embedded on your website into Google
Analytics using Google Tag Manager.
You'll learn how to track people playing and pausing your videos, and understand if people
are watching the full video or if they're just making it halfway through.
To do this we will use the in-built YouTube trigger in Google Tag Manager - so let's head
to Google Tag Manager and get started!
First we need to navigate to 'Variables' and we are going to click 'Configure' under 'Built-In
Variables.
Now let's scroll to the very bottom of the configuration panel...
Here we can see the built-in video variables, so let's enable these...
Now coming back to the 'Variables' panel let's select 'New' under 'User-Defined Variables'...
Let's name the variable 'Video Action'...
And select 'Custom JavaScript as the 'Type'...
Now we need to paste some code into our new variable.
This code will look at the video status as people engage with the embedded YouTube content.
When someone clicks to watch the video, pauses the video, makes it to a particular percentage
through the video or finishes watching the video this will provide a value that we'll
send to Google Analytics.
We'll add this to our tag in a moment, but now we need to save our variable.
Now we need to navigate to 'Tags' and click 'New'.
Let's name the tag 'YouTube'.
We're going to select 'Universal Analytics' as the 'Tag Type'.
Now we select 'Event' as the 'Track Type'.
This means we'll be sending an event to Google Analytics when people are watching our videos.
Let's enter 'YouTube' as the event category...
And select 'Video Action' as the 'Action'...
This will grab the values from the variable we just created as people are engaging with
our videos.
Now let's select 'Video Title' as the 'Label'...
You also have the option of selecting the 'Video URL' or you can also select both.
I just want to see the titles of each video in my report, so I'm going to stick with 'Video
Title'.
I need to select the Tracking ID for the 'Google Analytics Settings' and now it's time to configure
the trigger...
We need to select 'YouTube Video' as the trigger and then we want to configure the trigger
to send all of the different video interactions to Google Tag Manager.
Since we want to report on how far people are making it through our embedded videos
I'm going to enter 25, 50, 75 as the percentages.
This will mean we can see how many people watch at least 25% of the video, 50% and 75%.
And we'll also be able to see how many people are watching to the end of the video too.
I'm going to select 'Add JavaScript API support to all videos' - this helps ensure all of
the videos we have embedded on our website are tracked into Google Analytics.
Now I can save the trigger and the tag.
Finally, I need to publish the tag...
Here we can see a page that includes my Google Tag Manager container and an embedded YouTube
video...
Let's refresh the page...
And play the video...
Now we can head to the Real Time reports in Google Analytics...
We can now see the interaction with the video reported into Google Analytics.
We're using the in-built YouTube trigger to send this data into Google Analytics using
Google Tag Manager.
And we haven't added or modified any code on our website.
So that how you can track YouTube videos embedded on your website into Google Analytics.
Once you're collecting data you'll be able to use the 'Events' reports to understand
how people are engaging with your video content.
You can also configure Google Tag Manager to track other interactions, including scroll
depth and form submissions.
Watch my video on tracking events for a quick way to automatically track custom interactions
into Google Analytics.
Are you tracking YouTube videos in Google Analytics?
I'd love to know!
Let me know in the comments below!
If you found this video helpful, then please like it, so I know to make more videos like
this.
See you next time!