# Custom Player Integration SDK

If your video player is not listed among our [**Supported OVPs**](https://docs.chartbeat.com/cbp/feature-integrations/video-engagement/supported-ovp-integrations), 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.

{% file src="<https://225322705-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYD2YiVXfNNRnSgJXb4%2F-LnO-FBpO2fSXmbAFvXN%2F-LnO-Mamj-BN4nwNTZkp%2Fchartbeat_js_video_sdk.zip?alt=media&token=141cae93-9ae9-4dd4-9769-5b7a12a50b6a>" %}
Download the Chartbeat Video SDK (JavaScript)
{% endfile %}

## 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**](https://developers.google.com/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:

```javascript
window['_cbv_strategies'] = window['_cbv_strategies'] || [];
window['_cbv_strategies'].push(CUSTOM_STRATEGY_CONSTRUCTOR_NAME);
```

{% hint style="info" %}
**Note**: Make sure to push your video strategy constructor to `_cbv_strategies` synchronously, before Chartbeat's pinger (`chartbeat_video.js`) loads.
{% endhint %}

### **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:

```javascript
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:

```markup
<script type='text/javascript'>
    (function() {
        window['_cbv_strategies'] = window['_cbv_strategies'] || [];
        window['_cbv_strategies'].push(MyStrategy);
        var _cbv = window._cbv || (window._cbv = []);
        _cbv.push(MyPlayer);
        var _sf_async_config = window._sf_async_config = (window._sf_async_config || {});
        /** CONFIGURATION START **/
        _sf_async_config.uid = YOUR_ACCOUNT_ID;
        _sf_async_config.domain = 'yoursite.com ';
        _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 = '//static.chartbeat.com/js/chartbeat_video.js';
            n.parentNode.insertBefore(e, n);
        }
        loadChartbeat();
    })();
</script>
```

## 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.
