to the tippy ↑

Google Analytics

google-analytics2

At Wistia, we love analytics. While ours are pretty sweet, there are lots of tools out there, like Google Analytics. While Wistia's analytics give you more in-depth information on video plays, putting basic 'video play' stats in Google Analytics can give you a better picture of your web visit metrics.

This guide is here to help you get started integrating Wistia video tracking with your Google Analytics account.

Google Analytics Lab

We realize that sometimes these things can get a bit complex, so to save you some time we built out the Google Analytics Lab. It actually does all of the stuff mentioned below for you! You can check it out here.

We strongly recommend this route if you're not looking for more than the video play, 25/50/75/100% watched, and turnstile conversion events.

If you are still committed to doing it yourself to code out some sweet other alerts, read on!

Note

This lab also works with Universal Analytics, so no worries about compatibility there unless you've changed to a custom analytics variable other than ga or _gaq.


Before You Get Started

Make sure you have installed the Google Analytics tracking scripts. These are necessary for any custom tracking we do below.

It's worth noting that if you have Universal Analytics, things might be a bit different for you. In that case, you'll want to see this other Google help document where they explain how to set that one up.

If you currently have the pre-Universal Analytics version of Google Analytics setup, we recommend checking out the Universal Analytics Upgrade Center to get all the info you need to know about converting to the shiny new Universal Analytics style of things.

Modify Your Wistia Embed Codes

Integrating with Google Analytics is very simple thanks to the Embed Shepherd. All you need to do is paste this little snippet of code anywhere on your website, preferably right before the </body> tag (meaning at the bottom of your page's body).

You'll need to add the following code snippet to every page that contains a video you want to track. Or better yet, if you have a layout file or a footer that's shared across pages, just put it in there and you'll be good to go!

Due to changes made when Universal Analytics was released, you'll use different code depending on which version you use. The easiest way to do this is to see if you have the _gaq or ga variable defined on your website.

Pre-Universal Analytics snippet

playlist_api.js
1
2
3
4
5
6
7
8
9
10
11
12
<script src="http://fast.wistia.net/static/embed_shepherd-v1.js"></script>
<script>
  wistiaEmbeds.onFind(function(video){
    video.bind("play", function(){
      _gaq.push(['_trackEvent', 'Video', 'Play', video.name()]);
      return this.unbind;
    }).bind("end", function(){
      _gaq.push(['_trackEvent', 'Video', 'Complete', video.name()]);
      return this.unbind;
    });
  });
</script>

Post-Universal Analytics snippet

playlist_api.js
1
2
3
4
5
6
7
8
9
10
11
12
<script src="http://fast.wistia.net/static/embed_shepherd-v1.js"></script>
<script>
  wistiaEmbeds.onFind(function(video){
    video.bind("play", function(){
      ga('send', 'event', 'Video', 'Play', video.name());
      return this.unbind;
    }).bind("end", function(){
      ga('send', 'event', 'Video', 'Complete', video.name());
      return this.unbind;
    });
  });
</script>

You'll notice that not only has the variable changed from _gaq to ga but that the format between Google Analytics and Universal Analytics is slightly different. Instead of using .push([...]) you're using ga('send', ...) to push along that data. Everything else stays the same!

What those snippets do

These snippets fire a 'Play' event to Google Analytics whenever a video on your website is played. They also fires a 'Complete' event when a viewer reaches the end of a video.

We only fire each of these events once per video per page load (that's what the return this.unbind is for). So if a viewer plays and pauses a video over and over again, we'll only send one play event to Google. Pretty cool.

You can extend what we've done here to pipe many more events to Google Analytics if you like. Take a look at the Player API to see what's possible.

Track viewing in Google Analytics Dashboard

Now that we have all the back-end coding out of the way, it's time to monitor how the videos are performing on your Analytics Dashboard.

The first step is to navigate to the Event Tracking section. Click the "Behavior" area of the left hand nav bar, and then select "Event Tracking" from the list. The Event Tracking section will show the total number of events, the average number of events per visit, and the Top Events. Select "Categories" to see just the video events.

The "Categories" events will now contain a "Video" section, which you defined in the Javascript earlier. Click "video" to drill into the specific event descriptions.

The "Video" section page will show the total number of plays and the total number of complete plays, which we defined in separate Javascript functions earlier. Click on "Play" or "Complete" to see the plays or completes for a specific video (if you have started tracking multiple videos through UA or GA).

The final drill down shows what specific video titles (defined in the javascript function above) were played.

Using Wistia and Google Analytics is a good way to get all your top-level video analytics data in the same place you already get your other website tracking information.