Track Everything Part 1: Video Analytics

programming Posted on Nov 09, 2015

It’s not a secret that Google's Universal Analytics is a great way to track page views. For small websites it’s usually enough to just copy the Google Analytics code into a website header or footer. Then Google takes care of all of the basics and sends reports regarding traffic, page views, and all the basics.

But for larger, consumer facing websites that’s not the only information we want anymore. We want details about user behavior and how they are interacting with the content. Luckily, Google Analytics’ Event Tracking and Timers can track just that.

Let’s start with video analytics. When tracking a video in analytics we need to be able to answer the following questions:

  • How many times was the video played?
  • How many times was the video completed?
  • At what point did most viewers drop off?
  • Did they skip around when watching the video?
  • Did viewers watch in full screen or regular size?

Most video players, like Flash, HTML5, and Silverlight transmit standard video events (e.g. start, stop, play, pause, completion, duration) while playing. We just need to capture these events and track them in Google Analytics. This may sound like a lot of work but it’s actually pretty simple.

To start, you should check out video.js. It’s a great framework to add videos to your website, and the best features are below:

  • Automatically handles of fallback scenarios, fallback to flash if html5 is not supported
  • Works with all browsers and devices
  • Features a plugin (videojs-ga) that can automatically capture all the video events and track them in Universal Analytics.
  • Features easy customization match with your website design

Check out the code below:

Now, Google Analytics is tracking all events by default. With the above code you can answer all of the questions we asked, except a visitor’s drop off point. To capture that we’ll need to create checkpoints during the playback and track those manually. Let’s add a few more lines:

This will now allow for 10 second check points during the playback. Each checkpoint is tracked as a separate event. Then, you can easily see drop-offs when viewing analytics, like below: