Tracking YouTube Videos in Google Analytics

By /

November 18, 2010

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 is our Data Evangelist, focusing on bringing the strategic value of data analysis to our customers. He spreads the principles of analytics through our training seminars and is currently writing a book on Google Analytics & Tag Manager. Before he caught the analytics bug, he worked in information architecture. Away from the computer you can find him as a flower farmer and plant geek.

  • Jeff Zickgraf

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

  • nsdnayz

    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

    what about youtube new 3d videos like on my channel in this link ? can you use analytics for these vids?

  • E

    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:

    But it would be great if Lunametrics could do an updated post. There has to be some changes since 2010. Thanks.

  • Sayf Sharif

    For some updated script that makes tracking embedded YouTube videos as easy as copy/paste check out this blog.

  • Enrique

    thanks, this is awesome.

  • James

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

  • Jonathan Weber

    James, maybe you’d be interested in this later article that tells you exactly how and gives you the code to do it:

  • Avanindra

    can we add google analytic tracking to youtube.

Contact Us.


24 S. 18th Street, Suite 100,
Pittsburgh, PA 15203

Follow Us



We'll get back to you
in ONE business day.