Prebid Video | Instream Example with Ooyala player

An example of an instream pre-roll ad using Prebid.js and Ooyala player .

Important: This example uses a test version of Prebid.js hosted on our CDN that is not recommended for production use. It includes all available adapters. Production implementations should build from source or customize the build using the Download page to make sure only the necessary bidder adapters are included.

Warning: Do not forget to exchange the placementId in the code examples with your own placementId!

Place this code in the page header.

<script async src="//"></script>

 Load the Ooyala player scripts you plan to use.

 You must load the core player script, the scripts for
 whatever video formats you want to support, and the scripts
 for the ad manager you want to use.

 The scripts themselves and a guide for choosing which ones
 you need can be found here:

<script src="//"></script>

<script src="//"></script>
<script src="//"></script>
<script src="//"></script>

<!-- HTML5 SKIN -->
<script src="//"></script>

<!-- SKIN ASSET -->
<link rel="stylesheet" href="//" />

<!-- IMA PLUGIN -->
<script src="//"></script>
    var pbjs = pbjs || {};
    pbjs.que = pbjs.que || [];
    iosDevice = !!navigator.platform.match(/iPhone|iPod|iPad/);
    console.log("|||| Start of prebid: " +;

    /* PRE-DEFINE `invokeVideoPlayer`

       Because we have no way of knowing when all the bids will be
       returned from prebid we can't be sure that the browser will
       reach the point where `invokeVideoPlayer` is defined before
       bidsBackHandler fires and tries to call it.

       To prevent a `invokeVideoPlayer not defined` error, we
       pre-define it before we make the call to prebid, and redefine
       it later on with the code to create the player and play the
       ad. In this first version it simply stores the winning VAST to
       use later.  */

    var tempTag = false;
    var invokeVideoPlayer = function(url) {
        tempTag = url;

    var videoAdUnit = {
        code: 'video1',
        mediaTypes: {
            video: {
                playerSize: [640, 480],
                context: 'instream'
        bids: [{
            bidder: 'appnexus',
            params: {
                placementId: iosDevice ? 13239390 : 13232361, // Add your own placement id here. Note, skippable video is not supported on iOS
video: { skippable: true, playback_method: ['auto_play_sound_off'] } } }] }; pbjs.que.push(function() { pbjs.addAdUnits(videoAdUnit); // add your ad units to the bid request
/* Use the Prebid Cache - required for video ads */ pbjs.setConfig({ debug: true, cache: { url: '' } }); pbjs.requestBids({ bidsBackHandler: function(bids) { /* Build the DFP video URL */ var videoUrl = pbjs.adServers.dfp.buildVideoUrl({ adUnit: videoAdUnit, params: { iu: '/19968336/prebid_cache_video_adunit', cust_params: { section: 'blog', anotherKey: 'anotherValue' }, output: 'vast' } }); invokeVideoPlayer(videoUrl); } }); }); </script>

Place this code in the page body.

    var invokeVideoPlayer = function(url) {
        console.log("invoking video player with url " + url);


           Define the settings you want for your player in a JSON
           object. These lines will be part of the embed code you
           copy-paste from Ooyala Backlot, we just need to add the ad
           parameters.  */

        var playerParam = {
            'pcode': 'lsbWkyOjtI6LOjmlqk2o5I-TsWRA',
            'playerBrandingId': '45b8294c6ad14265b2b47586c911cb07',
            'debug': true,
            'autoplay': true,
            'initialVolume': 0.0,
            'skin': {
                'config': '//',
                'inline': {
                    'adScreen': {
                        'showAdMarquee': true,
                        'showAdCountDown': true,
                        'showControlBar': true,
                        'useGoogleAdUI': true


               Create a new JSON object in the player parameters. The key
               should be the ad manager you're using (in our case we're
               using the Google IMA ads manager, so the key is
               `"google-ima-ads-manager"`). The IMA ads manager requires
               an ad set (which we've named `"all_ads"`).

               For more information see the Ooyala docs:


               Make sure the ad parameters are properly formatted JSON.
            "google-ima-ads-manager": {
                "all_ads": [{
                    "position": "0",
                    "position_type": "t",
                    "tag_url": url
                'showAdControls': true


           Use the `OO.ready()` event to make sure that all the
           necessary Ooyala plugins have loaded before attempting to
           create the player. Once it has, call `create()` and pass

           - the div you're creating the player in

           - the ID of the content video

           - the player settings we created above */

        OO.ready(function() {
            console.log("OO is ready, invoking");
            window.pp = OO.Player.create('container', 'ltcG54NzE6Bxk08Mqs1_KMcQZDN7lH8N', playerParam);


       If Prebid returned bids before the browser reached the end of
       the page, the first version of `invokeVideoPlayer` will have
       been called from `bidsBackHandler`, so the winning VAST tag will
       be stored in `tempTag`.

       If that's the case, we want to call the "real" version of
       `invokeVideoPlayer` with the stored URL to create the player and
       play the ad.

       If `tempTag` is not defined, that means the browser reached the
       end of the page before the bids came back from Prebid, meaning
       the "real" version of `invokeVideoPlayer` was already called.

    if (tempTag) {
        tempTag = false;