Upcoming LunaMetrics Seminars
Washington DC, Dec 1-5 Los Angeles - Anaheim, Dec 8-12 Pittsburgh, Jan 12-16 Boston, Jan 12-16

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:

  1. Our own videos, posted on YouTube.
  2. 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.

social analyticsFirst, 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.

Jonathan Weber

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. The next seminar he'll be leading will be a Google Analytics training in Boston. 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.

http://www.lunametrics.com/blog/2010/11/18/tracking-youtube-videos-google-analytics/

9 Responses to “Tracking YouTube Videos in Google Analytics”

Thanks. This is what I was looking for and was having a hard time finding anyone talking about recent changes.

nsdnayz says:

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.

J says:

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?

E says:

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.

Sayf Sharif Sayf Sharif says:

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/

Enrique says:

thanks, this is awesome.

James says:

Ah, another worthless article that tells you you can do something but offers no help in the “how”.

James, maybe you’d be interested in this later article that tells you exactly how and gives you the code to do it: http://www.lunametrics.com/blog/2012/10/22/automatically-track-youtube-videos-events-google-analytics/

Avanindra says:

can we add google analytic tracking to youtube.