February 11th, 2015 updateNovember 15th, 2014 update- track onunload event
- minor fix to error reporting
June 20th, 2014 update- now supports multiple players on the same page
- includes optional code to add the necessary enablejsapi=1 to the video URL
- now track the video title instead of the video id
September 16th, 2015 update
During our GTM+UA webinar I was asked about tracking YouTube videos with the help of Google Tag Manager and Universal Analytics. I quickly demonstrated how we’re doing it in our WASP playground.
Here’s a step by step guide to the macros, tags and rules required to track YouTube video embeds on your website.
A note for Google Analytics users: For sake of demonstration I’m showing Universal Analytics, but you could easily replace the Universal Analytics Event by a regular Google Analytics one and everything will work fine.
Prerequisites
We will use the YouTube JavaScript API to expose user interactions with the video. In order for this to work, each of your YouTube embeds will need to include “enablejsapi=1” to the link of the video, for example:
Note: the “Is Youtube present” macro could be modified to automatically add the enablejsapi if it’s not there, but this will result in a quick flash of the Youtube frame.
Note: by default, related videos will be shown and tracked. If you want to disable this, add “&rel=0” to the Youtube embed link.
What you’ll get
Under Behavior/Events/Top Events, you will see an event category named “video”, with event actions named “pause”, “play”, 0%, 25%, 50%, 75% and 100%. The eventwill be the unique identifier of the video.
Custom Report for Video Performance
If you want to get details about how individual videos are performing, follow those steps:
- Go in yout Behavior/Events/Top Events/video report;
- Click on “Customize” in the top left of the report;
- Under Dimension Drilldown, remove the “Event Category” dimension and switch “Event Action” with “Event Label”, so it now reads Event Label/Event Action;
- Modify the filter so it now reads “Event Category equals video”, so only videos are shown in this new custom report;
- Voilà! You now have detailed performance info about each individual video embedded on your website.
Macros
Is Youtube present?
You have two options here, either use this macro to automatically detect when a video is embedded on a page, or use a rule to include the Youtube Listener tag only on pages where you know there’s a video.
If you are using Google Analytics instead of Universal Analytics, simply change the Tag Type to Google Analytics and everything will work fine.
That’s it! Now you can track Youtube video embeds on your own website thanks to Google Tag Manager and Universal Analytics.
This topic, and many more, are covered in our GTM+UA Master Class. Please visit the Cardinal Path training page for free and custom training options.