We are closing.

Dm banner

SublimeVideoDocumentation

Google Analytics integration

Make sure to check out our Google Analytics add-on for an automated integration and to track more events without having to code anything.

Integrating Google Analytics Event Tracking with SublimeVideo is very simple. Using our current JavaScript API you can track “video started” and “video ended” events. Here are the two steps you’ll need to implement this integration.

Step 1: Embed the Google Analytics tracking code

If you’re already using Google Analytics Web Tracking in your site, you can skip this step since you already have embedded the tracking code in your website. Otherwise, please consult the Tracking Code Quickstart for instructions on how to setup the Google Analytics tracking code.

Step 2: Setup the events to track

Put the following code in a <script> element.

/*
Note: This is only a simple example, Google Analytics event tracking lets you
customize the way you track events
Be sure to check out the Google Analytics integration guides for any more info:
 - http://code.google.com/apis/analytics/docs/tracking/eventTrackerGuide.html
 - http://code.google.com/apis/analytics/docs/gaJS/gaJSApiEventTracking.html
 - http://code.google.com/apis/analytics/docs/gaJS/gaJSApi.html
*/
sublime.ready(function() {
  sublime.player('my_video').on({
    start: trackVideoStart,
    end:   trackVideoEnd
  });
});

function trackVideoStart(player) {
  _gaq.push(["_trackEvent", "Videos", "Started", videoName(player)]);
}

function trackVideoEnd(player) {
  _gaq.push(["_trackEvent", "Videos", "Ended", videoName(player)]);
}

function videoName(player) {
  return player.videoElement().getAttribute('title');
}

Note: Make sure to replace my_video with the actual ID of your <video>.

Demo

You can see this feature in action on this page.