Adverts with Google IMA

The Player SDK for Browsers can be easily extended to support ad insertion. The open-source videojs-ima plugin enables Google Interactive Media Ads (IMA). This supports linear advertisements in conjunction with content played by the player. It also supports companion ads. This page explains the steps you need to follow to implement ad integration, together with code examples. It should be used alongside the supplied sample code.

You can find more information about the plugin on its Github page.

Example code

Use npm to install videojs-ima and its dependencies.

  • Add the following links to the CSS and JavaScript files to your HTML file:

        <link rel="stylesheet" href="lib/videojs-contrib-ads/videojs-contrib-ads.css" />
        <link rel="stylesheet" href="lib/videojs-ima/videojs.ima.css" />
        <script src="//"></script>
        <script src="lib/videojs-contrib-ads/videojs-contrib-ads.js"></script>
        <script src="lib/videojs-ima/videojs.ima.js"></script>
  • Once the player has been created (e.g., in the loaded callback), initialise the videojs-ima plugin with the ID of the video element:

    let playerInstance = otvplayer(
        // options
        // loaded callback
        function loadedCallback() {
                id: "videoPlayer"
  • Before setting the player source, set the ad tag URL. This specifies the ads to play:

        adTagUrl = "";
        playerInstance.src {
            src: "",
            type: "application/dash+xml"

For a full list of ad tags, see

When it plays the stream, the player should insert the specified ads as appropriate.

Companion ads

The videojs-ima plugin also supports companion ads. See the Companion Ads IMA example in the SDK for an example of how these can be added.