Tracking YouTube Videos in Google Analytics
Interested in easily tracking YouTube Videos? We have some updated code. Check out our post here about Easily 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):
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.
About Jonathan Weber
Jonathan Weber is the Data Evangelist at LunaMetrics. He spreads the principles of analytics through our training seminars all over the East coast. Before he caught the analytics bug, he worked in information architecture. He holds a Master’s degree from the University of Pittsburgh School of Information Sciences. Jonathan’s breadth of knowledge – from statistics to analysis to library science – is somewhat overwhelming.





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?
Is there an updated blog post about this? All of my down-the-rabbit-hole searching for an easy-to-follow answer led me to this page: https://github.com/CardinalPath/gas
But it would be great if Lunametrics could do an updated post. There has to be some changes since 2010. Thanks.
For some updated script that makes tracking embedded YouTube videos as easy as copy/paste check out this blog. http://www.lunametrics.com/blog/2012/10/22/automatically-track-youtube-videos-events-google-analytics/
Hello, Neat post. There’s a problem together with your website in web explorer, would test this? IE still is the market leader and a good section of other folks will omit your fantastic writing due to this problem.
thanks, this is awesome.
I seriously love your website.. Pleasant colors &
theme. Did you build this amazing site yourself? Please reply back as I’m looking to create my very own website and would like to find out where you got this from or what the theme is called. Many thanks!
I have been exploring for a little bit for any high-quality articles or weblog posts in this kind of area . Exploring in Yahoo I ultimately stumbled upon this site. Reading this information So i am glad to express that I’ve an incredibly excellent uncanny feeling I discovered exactly what I needed. I most no doubt will make sure to don?t forget this site and provides it a glance regularly.
Excellent goods from you, man. I have understand your stuff previous
to and you are just extremely fantastic. I actually like what you have acquired here, certainly
like what you are saying and the way in which you say it.
You make it entertaining and you still take
care of to keep it sensible. I can’t wait to read far more from you. This is actually a terrific site.