Custom Player Integration SDK

Manually integrate your video player with our custom player SDK.

If your video player is not listed among our Supported OVPs, you may use our Video SDK to create a custom integration. The primary task is to define a JavaScript Class - referred to as a strategy - which interfaces with your native video API to return values measured by the Chartbeat Publishing Video platform. These include values such as video state (playing, stopped, completed, etc.), video duration, video thumbnail, playhead position, and so on.

Included files in the SDK

  • simplified_strategy.js is a template for creating a strategy class with no external dependencies. The comments in the code explains what each of the methods in the strategy class need to do.

  • strategy_interface.js is a Google Closure implementation of the strategy interface. If you’re using Google Closure, it defines all the required methods for you. Using Google Closure is not a requirement if you use the simplified_strategy.js as a basis for your object.

  • strategy_html_player.js is an example file showing how Chartbeat implemented the video strategy constructor for HTML5 video players.

Implementation Instructions

Step 1: Push your video strategy to _cbv_strategies

On each page with embedded video, you will need to push your video strategy constructor—as customized in strategy_interface.js — so that Chartbeat's pinger can use it to watch for video events. For the constructor, “CUSTOM_STRATEGY_CONSTRUCTOR”, you would push the constructor like this:

window['_cbv_strategies'] = window['_cbv_strategies'] || [];

Note: Make sure to push your video strategy constructor to _cbv_strategies synchronously, before Chartbeat's pinger (chartbeat_video.js) loads.

Step 2: Push your video object to _cbv

Whenever a new video player loads on the page, push the video object to _cbv. This should come after you’ve pushed your video strategy constructor, as in Step 1. For each individual video player, push the video object as below:

var _cbv = window._cbv || (window._cbv = []); _cbv.push(player);

Make sure to do this for each player that loads. So if a single page has two separate video players, you’ll need to push twice. However, if the same video player switches to a new video, you do not need to make this push, as the strategy interface should take care of new video loads.

Step 3: Change chartbeat.js to chartbeat_video.js

In order to use the Video Pinger, you must modify the Chartbeat code already on your site. You'll want to switch the Chartbeat code to load chartbeat_video.js instead of chartbeat.js. The chartbeat_video.js file includes both Publishing and Video tracking capabilities.

Checking your work

Your complete Chartbeat code will look something like this:

<script type='text/javascript'>
    (function() {
        window['_cbv_strategies'] = window['_cbv_strategies'] || [];
        var _cbv = window._cbv || (window._cbv = []);
        var _sf_async_config = window._sf_async_config = (window._sf_async_config || {});
        _sf_async_config.uid = YOUR_ACCOUNT_ID;
        _sf_async_config.domain = ' ';
        _sf_async_config.useCanonical = true;
        _sf_async_config.useCanonicalDomain = true;
        _sf_async_config.sections = 'section1,section2 ';
        _sf_async_config.authors = 'author1,author2 ';
        /** CONFIGURATION END **/
        function loadChartbeat() {
            var e = document.createElement('script');
            var n = document.getElementsByTagName('script')[0];
            e.type = 'text/javascript';
            e.async = true;
            e.src = '//';
            n.parentNode.insertBefore(e, n);

Next steps

Review our JavaScript configuration variables and add them to the Chartbeat code snippet for your website if they apply to your video player implementation.

Last updated