How to Automatically Track Embedded YouTube Videos

Estimated Reading Time: 4 minutes

Have you ever wanted to track an embedded YouTube video with Google Analytics but don’t know where to begin? Do you currently use Google Tag Manager to implement Google Analytics and other tags? Well, today is your lucky day, because I’m going to show you a solution to track embedded YouTube videos.

Sound too good to be true? Well you better read on to find out!

Why Can’t You Track Video Interactions Out-Of-The-Box?

Tracking embedded videos using event tracking isn’t as simple as adding some code to a website element like a button or a widget. This is because embedded videos are iframes. That is, they actually originate from another domain, in this case youtube.com.

To be able to track these videos with event tracking, we have to pass information from the iframe to the page the video is actually embedded on. This requires us to use YouTube’s API to listen for click events (like a click on the Play button) and then pass that information to the page the video is embedded on. Once we can pass this click information from the iframe to the page the video is embedded on, we can then send events to Google Analytics using Google Tag Manager.

Steps to Track Embedded YouTube Videos

Quick note: This method assumes you have some Google Tag Manager knowledge and know how to create new tags and publish a new container version.

1. Create a new Custom HTML tag in Google Tag Manager 

  Create a new Custom HTML tag

2. Name your new Custom HTML tag and copy/paste the following code into the “HTML” section of the tag:

Quick note: This script below works only with the Classic version of Google Analytics (ga.js). If you would like to use it with Universal Analytics (or GTM by making dataLayer.push’s), feel free to change the _gaq.push’s to the correct naming convention for those.

Download the script here

3. Add a firing rule to the custom HTML tag to fire on event equals gtm.dom”

Add a firing rule of event equals gtm.dom

4. Save the new Custom HTML script

Save the new custom HTML tag

5. Update your Google Analytics pageview tag by checking the “Tracker Name” option and Save

Without getting too technical (which means without having to make one of our dev’s explain this in detail), checking the “Tracker Name” option sets the tracker name to blank so that you can access the same _gaq object that was set as GTM.

So, basically, you can create one custom HTML tag that uses _gaq.push’s so that you don’t need to make dataLayer.push’s (and create a second event tracking tag in GTM to fire these events).

One note on this, if you have any old GA tags or events in the source of your site, these could potentially fire as well.

Check the "Tracker Name" option

6. Create a new version of your GTM container, test, and publish

Voilá, you can now automatically track any embedded YouTube videos placed on your site. Pretty cool, right?

If you’re an analyst or developer who uses Google Analytics often, you probably are using GA Debugger, a Google Chrome extension that helps you test and validate your Google Analytics tracking. If you’re a GA user that doesn’t use GA Debugger, step your game up and go download it now!

Here’s a blog post on my own website where I list some helpful Chrome extensions that will help you test your Google Analytics tracking: http://andygibson.us/2013/05/helpful-chrome-extensions-to-test-your-google-analytics-implementation/

YouTube Video Tracking Demo

Once you activate GA Debugger and then open up your Chrome developer console, feel free to test out the embedded video below to see what events are fired to Google Analytics.



Subscribe to the InfoTrust Blog


Author

  • Andy Gibson

    Andy is the Head of Vertical - News & Media at InfoTrust. He enjoys Dayton Flyers basketball, his pitbull rescue, Millie, and trying to figure out how to cook for himself. He's an expert with Google Analytics and Google Tag Manager, if you're into that kind of thing.

Facebook
Twitter
LinkedIn
Email
Originally Published: January 29, 2014

Subscribe To Our Newsletter

August 7, 2023
Originally published on January 29, 2014

Other Articles You Will Enjoy

How Data Maturity Can Cultivate a Data-Driven Culture

How Data Maturity Can Cultivate a Data-Driven Culture

Data-driven decisions are a buzz topic in Martech. It is essential for C-suite executives to understand and more importantly, use their data to move…

4-minute read
Advanced Analysis Techniques in Google Analytics 4: How to Use AI-Powered Insights and Predictive Analytics for Effective Marketing

Advanced Analysis Techniques in Google Analytics 4: How to Use AI-Powered Insights and Predictive Analytics for Effective Marketing

AI-powered insights and predictive analytics are revolutionary tools reshaping the modern marketing landscape. These advanced analytics techniques, particularly prominent in Google Analytics 4 (GA4),…

8-minute read

Get Your Assessment

Thank you! We will be in touch with your results soon.
{{ field.placeholder }}
{{ option.name }}

Talk To Us

Talk To Us

Receive Book Updates

Fill out this form to receive email announcements about Crawl, Walk, Run: Advancing Analytics Maturity with Google Marketing Platform. This includes pre-sale dates, official publishing dates, and more.

Search InfoTrust

Leave Us A Review

Leave a review and let us know how we’re doing. Only actual clients, please.