Tracking YouTube Videos with Google Analytics

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.

<script type='text/javascript'>
var pageTracker = _gat._getTracker("UA-XXXXXXX-X");
pageTracker._initData();
pageTracker._trackPageview();

// Create the event tracking object
var ytpEventTracker =
pageTracker._createEventTracker("YouTube Video Player");
var eventLabel;
</script>

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.

Google Analytics: Thoughts on the Future

I am continuously amazed at how fast our industry changes. In the two years since Google Analytics was launched we’ve seen Web Analytics grow in popularity and web analysts become highly prized in the marketplace. Many people attribute the change to Google Analytics which got me thinking about GA and how it may evolve in the future.

I’d like to mention that this post is purely opinion and speculation. I have no idea what Google’s master plan is for Google Analytics, but I do think that my ideas are possible.

picture-6.png

Let’s start by looking at where Google is going as a business. Google’s long term strategy is to become the dominant advertising network on the planet. It’s something that CEO Eric Schmidt has talked about in the past and it make total sense. The more advertising options that Google can offer it’s current customers the bigger the opportunity for growth.

Google’s success relies on the adoption of said advertising tools. Look at AdWords and the insane revenue it generates. Now image if Google could create 3 or 4 more advertising products that are as successful as AdWords. We’ll be looking at Berkshire Hathaway stock prices in no time.

The expansion of Google’s advertising platform began with audio ads and print ads and I’m sure they’re not going to stop there. These new products are simple, thus making them accessible to businesses that may not normally branch out into a new advertising medium. I’ll talk about specific Google advertising products and my thoughts on each in a moment, but what does all this mean to Google Analytics?

No matter what advertising tools Google creates, there needs to be a centralized reporting and analysis component. GA is that piece of the puzzle. It’s no secret that Google wants to create the Google Marketing Dashboard, why not base it on Google Analytics? It makes complete sense, right? GA is a data analysis tool so why not use it to analyze all marketing data? At the very least GA should be the analysis piece of the puzzle.


That’s the long term vision, but what type of integration opportunities exist right now?

The most basic integration is the inclusion of advertising cost data into Google Analytics. Audio cost data, print cost data… it’s natural to think that these will be pulled into GA soon.

The next integration step should be the automatic identification of online traffic that originated with an offline ad. Image if you could automatically create vanity URLs for your audio or print campaigns and have GA automatically track them. We’re already doing this manually, but it could, and should, be automated by Google. This type of integration will further remove IT from the configuration of GA making it easier for all types of organizations to track offline marketing efforts.

Let’s get even more specific.

Google AdWords

picture-1.pngNo need to talk much about this one. Google is the 800 pound gorilla in the paid search world. AdWords campaigns are automatically tracking in Google Analytics and cost data is automatically imported to compute ROI. Pretty slick. It would be nice if Google could pull in cost data from other paid search vendors, but there are probably too many political hurdles for this to happen.

Google Audio Ads

picture-2.png
I mentioned this one above and wrote a post about tracking audio ads with Google Analytics it in the past. I think audio integration is pretty logical. Beyond the cost data, I would like to see some type of map overlay report correlating geographic web traffic and the distribution of audio ads. The addition of automatically created vanity URLs for audio ads would provide a slick way to connect online conversions to the originating audio ad.

Google Print Ads

picture-3.png
Print is very similar to audio and I think it’s something we could see soon. Many of the same integration points exist for print ads including cost data, a map overlay of ad distribution and web visits and an automatically created vanity URL for print ads.

Graphic (Banner) Ads

This is another one that could be very close. Once the purchase of DoubleClick is finalized I bet we’re gong to see DoubleClick’s pre-click data rolled into GA quickly. Maybe they’ll add a DoubleClick item to the Traffic Sources menu below the AdWords menu item.

I think we’ll also see an auto-tagging feature for ads displayed on DoubleClick’s network. No more tagging destination URLs. Woo hoo!

Mobile

picture-7.png
Everyone loves to talk about mobile tracking. But the fact is that mobile tracking right now is miserable. The inconsistent implementation of JavaScript on mobile devices makes it very hard to track visitors on mobile devices.

Google has taken a big step to improve mobile tracking with the announcement of Android. This isn’t just a mobile browser, it’s a complete platform for mobile devices. It’s also a way that Google can insure that they’re very involved in the future of the mobile web. I’m sure that Google will include some type of mechanism in Android to track visitors.

Video (Google Video & YouTube) Ads

picture-8.png
Google is poised to provide some amazing data about how people interact with video. The new Google Analytics Event tracking feature is a logical, structured way to measure visitor engagement with video and video ads. I really hope that event tracking is added to all YouTube videos so we can all measure the performance of video content. Once we know how visitors are engaging video we can choose optimal placement of video ads.

I also expect Google to facilitate the creation of video ads in the same manner they did with audio ads and print ads. Maybe they’ll create a video ad marketplace.

Email Marketing

Google does not have an email marketing solution, but why couldn’t they leverage Gmail and create one? Just add a basic interface where users can upload a recipient list and some type of interface where they can style the email and you have a very effective email marketing tool.

But what about all of those people that don’t use Google advertising tools? What if someone just wants to use GA to measure website traffic? What cool features can they expect from Google?

I think Google’s commitment to GA goes well beyond the integration of advertising data. Google has a vested interest in providing tools that help EVERYONE make the web a better place. Part of Google’s philosophy is to, “Focus on the user and all else will follow.”

Analytics is one of the tools (and the most mature, I might ad) that Google provides so we can all make the web better (Website Optimizer and Google Trends are two others). The more analysis features that Google can pack into GA the more effective we’ll all be at making our sites better.

picture-5.pngCase in point, GA version 2. It was a major improvement in analytics UI design that facilitates analysis. Is it perfect? No, of course not. But it really makes analysis easier for everyone. I expect that Google will continue to refine the reporting interface by giving us more data visualization tools and more context for our data.

So what does this mean to other analytics vendors?

I don’t think that any other analytics vendor will be able to track Google based advertising (AdWords, Audio ads, etc.) as well as Google. I know that seems obvious, but it is a big deal, especially when Google becomes the major advertising network on the planet. Google can provide a view of offline ad activity and the resulting online behavior because they will have all the data. Could other providers create similar reporting? Maybe, but it won’t be as easy.

I also believe that we’ll continue to see consolidation. Google has, in my opinion, made web analytics tools (and testing tools) a commodity. Is there still a need for $250,000 web analytics application? Maybe, but I guarantee you people are taking a closer look at GA and evaluating the features that they really need before dropping hundreds of thousands of dollars.

Think I’m nuts? Think OmniSciences will take over the world? Leave a comment and let me know.

Event Tracking Pt. 1: Overview & Data Model

One of the major new features announced by Google at the EMetrics summit is event tracking. There has been a lot of discussion in our industry about tracking events and only a few vendors offer this feature. I believe that Google is the third. Anyway, this post gives an overview of the new feature. Part 2 covers the actual implementation and part 3 covers the reporting.

What Are Events

an engaged visitorEvents are actions that visitors take on a web page that don’t generate new pageviews. Interacting with a video player, a widget or an audio player are all common events. Tracking these interactions provides a lot of insight into what visitors are doing on a page.

In the old GA we could track this data as a pageview. But this was really ineffective. First, it created lots of pageviews that polluted our true pageview numbers. Second, the reporting wasn’t built to handle events so it never provided any real insight. That’s why we now have event tracking.

Event tracking adds another layer of data to the visitor data hierarchy:

Visitors
Visits
Pageviews
Events

Now we can really get a good idea of how visitors are engaging our interactive content. This will be vital as web technologies, like Ajax and Flash, continue to evolve.

Every time an event occurs GA will increase the event counter. So if we’re tracking the click button event, GA will show us an agregate count of the clicks. I’ll cover the reporting in Part 3.

Start With Business Questions

Before I get into the structure of event data, I want to talk about analysis. All analysis starts with a business question. What is the most popular organic keyword that visitors searched for? How many sales did I have last week? What was the revenue for a specific campaign? Normally, when you’re using GA, you don’t need to do any special configuration to answer these questions. GA does most of it for you.

But with events, you need to create ALL of the data that will end up in GA. You literally need to define what data you want GA to collect both in name and in value. If you don’t know what business questions you want to answer, you won’t be able to create the correct data.

As I continue this post, I’m going to use an example, Google Maps. If I was an analyst for Maps I would want to answer a lot of questions:

How many people use the zoom and do they zoom in or out?
Which map view is most popular: map, satellite, hybrid, etc.
How many people drag a map waypoint to a new location?

To make things easy, let’s focus on one question: which map view its the most popular. So now that we know the question we want to answer, let’s talk about the data we need to answer it.

Understanding the Data Model

There are 4 parts to the events data model:

Objects
Actions
Labels
Values

Objects

Objects are parts of pages that we want visitors to interact with. This may be a video player or a cool Ajax widget. To continue our example, the object would be ‘Map’. Remember, the business question we want to answer concerns a feature in the map.

Actions

20071015-actions.pngThe second part of the data model is Actions. Actions are attached to an object and represent the actions that visitors perform on our object. Actions tell us what the visitor did.

There can be lots of actions associated with an object. Just think about our map. There are so many things that a visitor could do. But we want to define actions that relate directly to the business questions. Here are a few actions that our Map object might have:

Zoom
Change view type
Drag waypoint

Because we’re focused on one business question, we’re going to focus on one action: ‘Change view type’.

Labels

Labels quantify the action that occurred. If the actions tell us what the visitor did, the value tells us the result. So, for the ‘Change view type’ action that I created above, I might have the following labels:

Satellite
Map
Hybrid
Street view

Labels are really important to understanding actions. If an actions only has one value it does not provide any insight into what the visitor did.

Values

The final part of the data model is Values. Values are optional but can provide a lot of insight into certain events. Values can be any type of numeric data that indicates the value of the action and label. While there are not may good values for our example, let’s assign a monetary value to each label. Who knows, maybe someone viewing a hybrid map is worth more than someone viewing a regular map:

Satellite 5
Map 10
Hybrid 15
Street view 20

Values can also be monetary making it easy to identify what actions have real value.

Pulling it All Together

So let’s look at our business question and the data model we’re going to use to answer it.

Questtion:
Which view type do people use more?

Object:
Map

Action:
Change view type

Labels & Values:
Map 5
Satellite 10
Hybrid 15
Street Level 20

The next step is to implement the data model using event tracking code. That’s covered in Part 2. Oh, if the Google Maps team is reading, call me. I’m more than happy to lend a hand. :)

Event Tracking Pt. 2: Implementations

In this post I’m going to discuss how to implement event tracking in Google Analytics. If you have not read part 1, I strongly recommend you do so because I reference Part one extensively. When we implement event tracking we add code that creates the data model we defined in Part 1. We’re going to continue our example of tracking an event in Google Maps. We want to find out how which map view people use most.

The Data Model

If you remember part 1, I created a data model for our event data. This will help us answer our business question and it will help use create the code.

Tag Your Pages

I know this seems simple, but the first step is to make sure your pages are tagged with the GA tracking code. Remember, this only works with the new ga.js tracking code.

<script type='text/javascript'>;
var pageTracker = _gat._getTracker("UA-XXXXX-X");
pageTracker._initData();
pageTracker._trackPageview();
</script>

Creating The Object

The first thing we need to do is create the object that we want to analyze. To create a new object we use a method name _createEventTracker(). We pass this method a value and that value is the name of the object we defined in the data model. Our object is called ‘Map’ so let’s use ‘Map’ in the name:

var mapEventTracker  = pageTracker._createEventTracker('Map');

When we look at the reporting interface we will see ‘Map’ in the Objects report. Pretty straight forward, huh?

This code must appear after your GA page tag. The reason is that the _createEvent Tracker() method is attached to the pageTracker object. In this example, I’m going to place it in the same block as the regular tracking code:

<script type='text/javascript'>
// Here’s the standard page tag stuff
var pageTracker = _gat._getTracker("UA-XXXXX-X");
pageTracker._initData();
pageTracker._trackPageview();

// Here is the new event object
var mapEventTracker  = pageTracker._createEventTracker('Map');
</script>

Tracking the Action

Now that we have an object, how do we track an action associated with that object? We add JavaScript to our page code when the action takes place. So, with our Maps example, we would add some code when the visitor clicks on the button to change the Map view type. Here’s how that code might look:

onClick="mapEventTracker._trackEvent('Change Map View', <label>, <value>);"

<label> and <value> should be replaced with one of the labels we identified in our data mode:

Map 5
Satellite 10
Hybrid 15
Street Level 20

What happens when a visitor clicks on a map button is that the code sends the action, label and value to GA and associates it with the map action we defined above. Now you can see how our data model really drives the implementation.

Tracking Multiple Objects

Ok, so here is something that’s pretty cool. Let’s say the map team wants to add two different maps to a single page. We can track both of them using the same map object. We would then differentiate what the visitor does using different labels. The actions would remain the same for both objects, but we’d have different labels.

A Final Note

I’d like to say that every implementation for event tracking can be different. It really depends on the business questions you need to answer and the structure of your pages. I think this post does a very good job of covering the basics, but your specific implementation will probably be a bit different… Unless you’re Google Maps. :)

As we’ll see in the next post, the new Event reports provide a logical structure for analyzing event data.

Event Tracking Pt. 3: Reporting & Analysis

This is part three of a three part series about event tracking in Google Analytics. You can find more information in these other posts:

Event Tracking Pt. 1: Overview & Data Model
Event Tracking Pt. 2: Implementation

I wrote this post before having access to the new events reports. As a result, I don’t have any screen shots for you guys! Sorry I don’t have anything to show you guys, but I will try to explain as much as possible.

The new event reports section will have specific reports for objects, actions and labels. If you have not read my post on the event data model then I strongly suggest that you do so. The data model is the driving force behind the structure of the reports.

Event reports will let you see summary information at an Object level, action level and value level. Here’s an example using Google Maps. If we create a ‘Map’ object then we will get a unique count of how many times the map object has been created. We can then drill into that event and see the actions and values of those actions.

Map
|_ Click Map View
|_ Satellite
|_ Hybrid
|_ Map
|_ Traffic
|_ Street view

This drill-down functionality is very similar to the drill down that you can do with campaign tracking.

The interface will also show you the values of each label. Remember, Satellite, Hybrid, Map, Traffic and Street view, are all labels and they have an associated value. GA will total up the value and show a unique count of how many times each action happened, the total value and the average value.

This is fantastic information because we can now measure what people are doing on our media rich pages. We no longer need to rely on Average Time on Page to gauge the success of our content.

I know this is really high level, and I’m sorry I don’t have any screen shots, but I’ll try to get some soon. Hopefully you got a taste of what is possible with the event reporting.