Tracking YouTube Videos in Google Analytics
Last time we talked about tracking Flash videos in Google Analytics, using either the Flash tracking libraries for Google Analytics and building the tracking by hand, or using a Flash player that already has Google Analytics tracking baked in like FlowPlayer.
I want to discuss one other specific scenario with Flash movies, and that’s YouTube. Now, there are two things we might be interested in:
- Our own videos, posted on YouTube.
- Videos from YouTube (either our own, or other people’s), embedded on our own site
Our own videos, posted on YouTube
There are two things we can do here, depending on what level of fanciness you have on YouTube.
First, everyone can use YouTube Insight to get some information about your channel. You get information such as:
- Total views and how the video was found (from YouTube or YouTube search, from external links, from Google search)
- Geographic areas
- Some demographics (gender, age ranges)
- Some engagement data (comments, ratings, favorites)
Second, if you have (read: pay for) a YouTube brand channel, you can install Google Analytics on your YouTube pages. You get all the power of Google Analytics, but what you don’t get is any ability to customize the tracking code, so it’s a mixed blessing.
Videos from YouTube embedded on our own site
YouTube lets us embed videos on our own site (our own videos, or anyone else’s as long as they have enabled embedding). Like this (shameless self-plug):
YouTube uses a Flash player to display these videos on your site, and you have basically no access to get inside that Flash Player and recompile it with Google Analytics Flash tracking like we talked about in the last post.
So, it used to be that your only option was basically to build your own player. You used what’s called the “chromeless player” which didn’t have any Play or Pause buttons or anything, and you supplied your own. At the same time, you tracked whether people clicked on these.
Fortunately, the YouTube player’s API has improved since then, and you can now take advantage of the regular embedded player (with its Play and Pause controls and whatnot), but easily add Google Analytics Event Tracking using only JavaScript.
Basically, the YouTube player broadcasts an event when it changes state (when it starts playing, or ends, for example). Then we can use JavaScript to add an event listener to monitor for when that state changes and send a _trackEvent call to Google Analytics.
Fortunately, others have already been down this path as well, so you don’t even have to write your own code. There’s a project on Google Code with a library that packages all this up for you. Just like with FlowPlayer, it’s not all exactly the way you might like things labeled for your own site, but again, you have something to build from. Check it out.


Thanks. This is what I was looking for and was having a hard time finding anyone talking about recent changes.
Thanks, can we set this up for use in a Native IOS app aswell? Cause one of my clients wants to track all of the youtube controls in a Native app.
Thank you for some other wonderful post. The place else may just anyone get that kind of info in such an ideal approach of writing? I have a presentation next week, and I’m on the look for such information.
what about youtube new 3d videos like on my channel in this link http://www.youtube.com/user/joneblaze82?feature=mhee ? can you use analytics for these vids?