• Home
  • Google Analytics
    • Customizations
    • For Ecommerce
  • Speaking
  • About
    • About Me
    • Contact Me
    • Disclaimer and Privacy Policy

Analytics Talk

Digital Analytics for Business

You are here: Home / Campaign Tracking / Tracking YouTube Videos with Google Analytics

Tracking YouTube Videos with Google Analytics

Posted: July 29, 2008 37 Comments

A while back, Google Analytics and YouTube introduced YouTube Insight, a tool to provide more information about the people viewing your videos on www.youtube.com. It’s pretty cool stuff and if you’re posting videos to YouTube it provides a lot of great information.

YouTube Insight: Information about those viewing your videos on www.youtube.com.

But what about YouTube videos that are embedded in a site? What’s the best way to measure interactions with these videos? You could use some basic metrics like Avg. Time on Page and Avg. Time on Site, but they’re averages and, well, averages suck. Fear not, there is a better way.

We can track almost every aspect of an embedded YouTube video using Event Tracking, a Google Analytics beta feature.

CHROME

There is one catch. In order to track an embedded YouTube video you must use the ‘chromeless’ YouTube player. A chromeless video player has no controls which means you must create all of the controls yourself. This results in a fair amount of coding.

Why do we have to use the chromeless player? The chromeless player let’s us add JavaScript code (i.e. GA Event tracking code) to user actions, thus giving us the ability to capture visitor actions as events. I’ll do my best to walk you through all of the code.

You can read more about the chromeless YouTube player on the YouTube developer site.

Let’s get started.

Event Data Model

Before we look at any code let’s talk about data and analysis. One of the keys to any successful event tracking implementation is a clear definition of the data we want to collect. Remember, event tracking is really a flexible data collection tool. We need to explicitly define the data we want to collect.

I want to track three primary things related to the embedded video:

1. Which video does the visitor choose to watch?
2. How do they interact with the video player (i.e how do they use the controls)?
3. How much time do they spend watching each video?

Now let’s translate these needs into the Google Analytics Event model which consists of Objects, Actions, Labels and Values.

Objects

The object is the part of the page that we want to track. Defining the object in this case is pretty simple: we want to track the YouTube video player, so we’ll create one object and call it “YouTube Video Player”. The object will literally be created in the code and I’ll explain how later.

Actions

Actions are the interactions that the visitor exerts on the object. What we want to track, and what we can track, really depend on what interactions we can capture. In this example, the actions we can capture are directly related to the chromeless YouTube player and what it ‘bubbles up’ for visitor interactions.

Based on the chromeless player, and the data needs we have defined, here are the actions that we are going to track:

  • Player Loaded: Indicates the YouTube player has loaded. No video has been loaded into the player, but the player is ready for a video.
  • Video Started: Indicates the user has chosen a video and it has started playing in the player.
  • Play: User has restart the video after it has been paused.
  • Pause: Video has been paused.
  • Mute: Video has been muted.
  • Unmute: Video has been unmuted.
  • Error: An error has occurred.
  • Ended: Selected video has ended, either intentionally or on purpose by the visitor.
  • Get Embed Code: Request HTML code to embed the video in a site.
  • Get Video URL: Request YouTube URL for the current video.

Like the object, actions are actually created in the code and we’ll see how later.

There are other things that we can track, but I’ve decided to limit it to the above list. Why? I don’t think there is a lot of insight that can be gained from some of the other information that is available to us. Plus the above actions will cover the data needs we’ve defined.

Google Analytics Event Labels.

Labels

Labels are the content of the object. In the case of most video player object, the label will be the name of the video playing. In this example you can choose three potential videos from a drop down box. The name of the video will become the label that is tracked in Google Analytics.

  • Apollo 11 Launch
  • About the YouTube API
  • Phish – Weekapaug Groove
  • Authors@Google: Avinash Kaushik

Values

This is where things can get a bit unique. The value collected by GA’s Event tracking is just a plain integer. All values associated with actions are summed and averaged. So we can’t mix different types of data, like monetary values (which may be in dollars) and time (which may be in seconds). For this example, we’re going to track time, so the values will be in seconds and will represent the total time that each video played.

I’m only going to associate a value with a single actions: Ended. When a video ends we’re going to record the total number of seconds played for that video.

The Example

Now that we’ve created the data model for tracking a YouTube player, we need to create a YouTube player to track. :) Remember we can only access visitor actions when we use the chromeless YouTube player.

Here’s a simple page that I created using the chromeless player and Google Analytics Event Tracking.

If the above iFrame is not visible, you can view the entire code here.

For those interested, this test page is actually a modification of the YouTube API example.

To start the tracking, select a video from the drop down and it will start playing. Then experiment with some of the controls. All actions that we defined in our event model will be tracked.

If you want to change videos just choose a new video from the drop down box.

I don’t want to go over too much of the code, but here’s the JavaScript behind the tracking.

If the above iFrame is not visible, you can view the entire code here.

A majority of the code is not Google Analytics code, but rather YouTube player code. What I’ve done is added the Event Tracking code in the appropriate places to capture the visitor interactions. Setting up the event tracking code is really pretty simple.

The first thing I did was create the Object, which is called ‘YouTube Video Player’. I created the object in the main GA page tag.




After creating the object I added the _trackEvent() method wherever I want to capture a visitor action, like Play or Pause. Here’s how I capture the Play action:


function play() {
  if (ytplayer) {
    ytplayer.playVideo();
    ytpEventTracker._trackEvent("Play",eventLabel);
  }
}

Most of the Play code is actually YouTube code. The only GA specific code is ytpEventTracker._trackEvent("Play",eventLabel);.

We pass three values to _trackEvent(). The first is the name of the action and this value will appear in the GA Actions report. The second value is the lable value which will appear in the Labels report. I should note that eventLabel is the name of the video (per the data model) that is currently playing when the visitor clicks on Play.

The final value, which is not shown above, is the value value. In this example, the value is the total number of seconds played. This is only recorded for the Ended action.

If you look at the example code, all I really did was add ytpEventTracker._trackEvent() to all the actions that I wanted to track.

The Results

Enough with all the techno-mumbo-jumbo. Let’s look at some of the data starting at the top of our hierarchy: the Object report.

Google Analytics Object report.

Noting too exciting here. We’re only tracking a single object here, hence the one line of data. The data can be a little confusing. The total number of events is really the total number of actions that occurred. The number of unique events is the number of visits that included an event.

But let’s dig a bit deeper. Let’s see which video was most popular by viewing the labels associated with the YouTube Video Player object. All I need to do is click on the Object name to view the associate labels and actions, and then choose ‘Labels’ using the Detail Level link above the table tabs.

Google Analytics Label report.

Here we can see that ‘Phish-Weekapaug Groove’ was the most popular video, when based on time. It had a higher total value than the other videos. Sorry Avinash. :)

One thing to notice is that measuring the popularity of each video based on Events is not correct. Just because a label has the most actions does not mean that it is the most popular.

Remember, an action can occur ever time a visitor interacts with the player. In this example it would be more accurate to judge popularity based on time.

Now let’s see how people interacted with the most popular video. What actions did visitors perform when ‘Phish-Weekapaug Groove’ was playing?

All I need to do is click on the label name to see the actions associated with the label.

Google Analytis Action report.

Cool, here we can see that the video was started 32 times, but only completed 12 times. It was viewed a total of 1775 seconds but only an average of 143 seconds.

What does it all mean? I know that the Phish video is 179 seconds long. So, on average, visitors viewed 80% of it. I can also tell, by the number of unique events, that the Phish video was viewed multiple times in the same visit. It must be pretty popular.

I also want to point out that we can view the data in other ways. We can navigate directly to the Actions report to see a list of all the actions, regardless of the object or label they are associated with. This is a great way to get a feel for the most commonly used features of our YouTube player.

Google Analytics Actions report.

Conclusion

So was this really worth it? Sure, I think so. I wanted to create a real life example that demonstrates some of the ways to use Event Tracking. I also wanted to use YouTube as an example because so may people use it as a platform to distribute video.

While it may seem like a lot of work to track video and other web 2.0 technologies it is vital. If you’re spending money producing videos, or if you’re selling video ad space, you need to know how people interact with your player and content. It’s the perfect use for Event Tracking.

Filed Under: Campaign Tracking, Event Tracking, Tracking Tagged With: Event Tracking, google-analytics, video-tracking, Web Analytics, web-2.0

Comments

  1. Eivind says

    July 29, 2008 at 4:17 pm

    That was a handy example.

    Just for your info, it doesn’t work in my Firefox 3.0 browser. From what I understand it isn’t much you can do about that – it’s a Firefox bug:
    https://bugzilla.mozilla.org/show_bug.cgi?id=410904

    The problem is that Firefox doesn’t properly append the referer header to requests made from swfs embedded on the page from what I’ve understood.

    Reply
  2. Justin Cutroni says

    July 29, 2008 at 4:47 pm

    Thanks for the heads up Eivind. I have resisted the FF 3.0 upgrade as it would break a lot of my extensions. Hopefully they get this fixed soon. I’m sure everyone will be rushing to track chromeless YouTube videos soon! :)

    Justin

    Reply
  3. James Dutton says

    July 29, 2008 at 4:47 pm

    Justin – this is awesome! I’m glad you’ve taken the time out to showcase the results that can come out of the integration of great technology and the clever use of site analytics tools.
    This is now bookmarked and will become a reference for next time I’m asked about what we can do with youtube videos, which works perfectly with the scripting engine we’ve already worked on for flash based video.
    Cheers, James.

    Reply
  4. Sergi says

    July 29, 2008 at 5:59 pm

    Excelent post Justin. That’s just what I’m already doing at the website where I work: tracking our trailers with event tracking (I asked for access to the event tracking beta to my adwords manager ;)

    Just two points:

    1. Instead of using the YouTube chromeless player I user the JW FLV Media Player (http://www.jeroenwijering.com/?item=JW_FLV_Media_Player). It exposes the full event model (play, stop, fullscreen….), has an API, plays YouTube videos, supports playlists and what’s better, it very easy to skin it and it’s already beautiful enough ;) It’s not free for commercial use, but it costs only 20 euros.

    2. Maybe it’s an event tracking bug or maybe it only happened to me, but when I created an event tracker in my main GA profile I received an small amount of what I call “ghost visits”, visits with zero pageviews (in my case about 1% of total pageviews). You can check it at Visitors -> Visitors Loyalty -> Depth of Visit where you may find you have visits with zero pageviews. I solved it creating another profile besides the main one and tracking there the events.

    Regards

    Sergi

    Reply
  5. Evan Mullins says

    July 30, 2008 at 10:23 am

    Very interesting! Thanks. I will definitely be using this. It’s great to see a working example.

    Reply
  6. Carlo says

    July 31, 2008 at 5:46 pm

    Would this work on videos that aren’t running or uploaded on YouTube?

    Reply
  7. Justin Cutroni says

    August 1, 2008 at 12:18 am

    Hi Carlo,

    The same concepts that I’ve outlined above can be used for almost any video player. The big difference is the implementation. The code that was created above is specific to the chromeless YouTube player. Any other implementation needs to be customized for the player you want to track.

    Thanks for reading and thanks for the comment.

    Justin

    Reply
  8. Carlo says

    August 1, 2008 at 1:30 am

    Justin, just so you know, I’m a big fan of your site and you don’t know how much you’ve helped me figure things out with GA, especially coming from WebTrends or Omniture background.

    Thanks!

    Reply
  9. Justin Cutroni says

    August 1, 2008 at 8:41 pm

    Carlo,

    I’m glad you’ve found the blog usefull. I really enjoy sharing what I know and I’m glad it helps. If you have any suggestions let me know.

    Justin

    Reply
  10. Dennis R. Mortensen says

    August 15, 2008 at 9:12 am

    Hi Justin,

    Great post, I love anything and anybody who actually gets down and illustrate the nitty-gritty parts.
    I did a study among clients and partners not that long ago about WHICH metrics to use when tracking online video and came up with 9 Essential Online Video Metrics.

    http://visualrevenue.com/blog/2008/02/online-video-analytics-kpis.html

    Which is not far from the metrics you collect, with the one difference that being TOO detailed, left some analysts in the dark on WHAT insight to gather from the events tracked (we call them actions, but hey). Therefore we grouped some events to get a more clear set of metrics and a better opportunity for understanding the impact:

    – Online video positive consumption action
    – Online video negative consumption action

    It it of course of the utmost importance that the right events are grouped

    My 2 Euro cents :-)

    Cheers
    d.

    Dennis R. Mortensen, Director of Data Insights at Yahoo!
    Blog: http://visualrevenue.com/blog
    Book: http://visualrevenue.com/blog/yahoo-analytics-book

    Reply
  11. Justin Cutroni says

    August 15, 2008 at 9:38 am

    Dennis,

    Thanks so much for the comment! I am embarrassed to say that I had not read your post until today. I’ve been out of the loop and am slowly creeping back in.

    Your post is fantastic. Your emphasis on actions and insights is right on the money and something I should have emphasized more. It’s great that many of the web 2.0 measurement tools let us define the data we want to collect. As long as we keep actionability in mind we’ll be all set.

    It’s quite flattering that my list of metrics was fairly close to yours. I’m glad we’re all thinking along the same lines especially because we have no formal web 2.0 measurement standards.

    Thanks again for the comment, I appreciate it.

    Justin

    Reply
  12. Michele Bench says

    August 15, 2008 at 1:30 pm

    Where in GA can I find the object report once we’ve started collecting data?

    Reply
  13. Justin Cutroni says

    August 15, 2008 at 2:29 pm

    Hi Michele,

    The Event reports are in the Content section of Google Analytics. However, event tracking is still in beta. You’ll only see the Event tracking menu if your GA account has been added to the event tracking beta.

    Thanks for the question,

    Justin

    Reply
  14. Eivind says

    August 16, 2008 at 11:03 am

    Hi again Justin.

    Just wanted to mention that the player works fine in Firefox 3, so I was wrong in my first comment. It was the Firefox browser on that particular pc that had problems.

    I just “had to” make my own YouTube Chromeless player because of your article, you’ll find it implemented in this article.

    Reply
  15. Justin Cutroni says

    August 18, 2008 at 9:44 am

    Hi Elvind,

    Thanks for the followup and thanks for making a chromeless player. It’s this type of innovation that really gets me excited. To see people with real talent, create tools that other people can use, is fantastic.

    Is this player available to everyone? I’d love to use it to post videos on my site. Perhaps you would consider adding some English instructions for other users?

    Thanks again,

    Justin

    Reply
  16. Eivind says

    August 18, 2008 at 1:52 pm

    Hi again.

    I will make an English article shortly about my player, and also make a download available.

    Just finished bug testing with some help today (I’m not a programmer, so I usually just bang my head against the wall until the problem is solved :-)), so the only thing left is to see if I can make the CSS for the player a little bit easier before I write the article.

    Reply
  17. Eivind says

    September 11, 2008 at 5:11 pm

    It took some more time to publish my version of the Chromeless Player. Anyway, you can download my YouTube Chromeless Player here.

    I have also implemented a possibility for playing high quality YouTube videos.

    Reply
  18. Electronic Business Cards says

    March 8, 2009 at 8:53 pm

    Thanks again for another great post. I have done a little with YouTube, but haven’t had the time for much more than a few videos showing how Electronic Business Cards impact sales and the like. This encourages me to push forward.

    Brad

    Reply
  19. Chris says

    May 14, 2009 at 12:27 pm

    Is this needed anymore?

    I noticed that Insights now CLAIMS to show embedded plays as well.

    The reason I’m thinking about using your method is because I have my doubts about the accuracy of the view counts Insights shows me.

    Reply
    • Justin Cutroni says

      May 18, 2009 at 4:09 pm

      Hi Chris,

      The Insight data does show embedded plays, and where the video is embedded. But it doesn’t contain any information about how much content was viewed or how the visitor interacted with the player. If you’re using your own video player, and you want to understand how visitors are interacting with the content and player, then event tracking is the way to go. Using Insights is a great way to understand how the community is using the content.

      Thanks for the great comment.

      Justin

      Reply
  20. Paul Featherstone says

    December 2, 2010 at 12:38 pm

    Great piece of work here!

    Has anyone tried repurposing this to use with Vimeo? I’m also pondering how one would track vids on external sites using GA, thinking I could regulate distribution of embed code via our partner network as long as it didn’t require too much technical implementation at their end.

    Any thoughts much appreciated.

    Paul

    Reply
  21. Paul Featherstone says

    December 2, 2010 at 12:40 pm

    Has anyone tried repurposing this for use with vimeo?

    Great work here!

    Paul

    Reply
  22. Anders says

    January 30, 2012 at 1:02 am

    Does anybody know if it works on iOS devices?

    Reply
    • Justin Cutroni says

      February 14, 2012 at 5:11 pm

      @ Anders – In theory this should work on iOS as long as the user does not go into full screen mode. The reason is this player is completely dependent on using the YouTube player. If that player is not run by the browser then none of this tracking will work.

      Reply
  23. Sayf Sharif says

    October 22, 2012 at 9:58 am

    I wrote up some code to dynamically track YouTube videos on the LunaMetrics blog. All someone needs to do is copy the default iframe embed onto their page, and the script (using jquery) will automatically track it with events. I’d love to get your thoughts on it. http://www.lunametrics.com/blog/2012/10/22/automatically-track-youtube-videos-events-google-analytics/

    Reply
  24. Animated Web Videos says

    February 9, 2013 at 5:29 am

    Great piece of sharing Justin . I have uploaded one of my product promotional video to YouTube a week ago and gets viewed more than 5000 times. I really want to track my visitors through Analytics but not find any helpful blog. Your posting solved my issue.

    Reply

Trackbacks

  1. STICKPERSON | Video analytics says:
    August 3, 2008 at 10:21 pm

    […] Over at Analytics Talk, Justin Cutroni writes about using the Google Analytics Event model to track users viewing and interactions with online video. Using the method Cutroni describes, an embedded YouTube player on a site can capture Google Analytics data not only about which videos users watch, but also their interactions with controls and how long they spend watching each video. […]

    Reply
  2. Web Analytics Bloglinks der Woche (KW 31 / 2008) | Web Analytics News says:
    August 4, 2008 at 1:36 am

    […] Tracking YoutTube Videos with Google Analytics (Analytics Talk) […]

    Reply
  3. Collective Wanderings 5 | Collective Thoughts says:
    August 15, 2008 at 7:17 pm

    […] Tracking YoutTube Videos with Google Analytics […]

    Reply
  4. links for 2008-12-23 :: User First Web says:
    December 23, 2008 at 4:05 am

    […] Analytics Talk » Blog Archive » Tracking YouTube Videos with Google Analytics (tags: javascript analytics flash google youtube omniture ipip) […]

    Reply
  5. YouTube Test Tube | DigitalMoneyMakers.com says:
    January 4, 2009 at 5:44 pm

    […] Analytics Talk » Blog Archive » Tracking YouTube Videos with … […]

    Reply
  6. SearchCap: The Day In Search, April 21, 2009 says:
    April 21, 2009 at 4:02 pm

    […] Tracking YouTube Videos with Google Analytics, Analytics Talk […]

    Reply
  7. Delicious Bookmarks for April 17th through April 21st | StraussBlog says:
    May 7, 2009 at 9:07 pm

    […] Analytics Talk » Blog Archive » Tracking YouTube Videos with Google Analytics – How to build a chromeless YouTube player with Google Analytics event tracker code. Useful if you want embedded YouTube videos but care enough about Google Analytics data to build your own custom player. […]

    Reply
  8. Tracking von YouTube Videos mit Google Analytics | webalytics blog says:
    January 19, 2010 at 1:22 am

    […] Blog-Artikel von Justin Cutroni vom 29.07.2008 inspirierte uns, die Nutzung der Videos auf unserer Website ebenfalls mit Google Analytics und dem […]

    Reply
  9. Multimedia Search Optimization (Part 2): Video SEO | The Adventures of SEO Boy says:
    September 23, 2010 at 2:55 pm

    […] before and after watching the video, and how they got to your website in the first place.  If you customize the video player on your site for an embedded video hosted elsewhere you can still gain Analytics data, but this is a bit more complicated and you’d better have a […]

    Reply
  10. Filtros e Segmentos Avançados no Google Analytics | Direct Performance says:
    July 18, 2011 at 7:53 am

    […] Exemplo de uso: analisar isoladamente o comportamento dos visitantes que assistiram até o final o vídeo sobre o produto XYZ . (Tutorial) […]

    Reply
  11. Cons of Making Your Own YouTube Videos | Rich Heart Women says:
    February 18, 2012 at 4:33 am

    […] you to fee films that you watch or even have on the net discussions with other YouTube members. Are you interested in earning your very own movies to upload to YouTube? Although a significant sel…to significantly examine your selection prior to truly building it. As nice as sharing YouTube […]

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

My Books

Google Analytics by Justin Cutroni
Learn More on Amazon.com

Performance Marketing co-authored by Justin Cutroni
Learn More on Amazon.com

Recent Posts

  • Understanding the Google Analytics Cohort Report
  • Using Offline and Online data to drive Google Analytics Remarketing
  • Understanding Cross Device Measurement and the User-ID
  • Universal Analytics: Now out of beta!
  • Advanced Content Tracking with Universal Analytics

Categories

  • About Google Analytics (25)
  • Analysis (52)
  • Analytics Strategy (3)
  • Campaign Tracking (14)
  • Ecommerce (8)
  • Event Tracking (10)
  • Remarketing (2)
  • Reporting (10)
  • Resources (7)
  • Tag Management (5)
  • Tips (25)
  • Tracking (52)
  • Uncategorized (64)
  • Universal Analytics (9)
  • Web Analytics (15)

Copyright © 2023 ·News Pro Theme · Genesis Framework by StudioPress · WordPress