Web Player

Complete external config implementation

This page is an example of using Prebid Video with a TargetVideo player.

This page contains:

  • Setting up a TargetVideo player to play ads dynamically.

  • Using a cloud-hosted player.

  • Dynamically insert a preroll ad into the player.

Example

Add the following script tags in the head area of your web page. Load your own production build of Prebid.js, made on Prebid’s Customize and Download Prebid.js page with the AppNexus bid adapter and the GAM video module — not Prebid’s “not-for-prod” test build. The example uses Prebid’s default ad server targeting.

<!-- Prebid.js: your own production build from https://docs.prebid.org/download.html, with the AppNexus bid adapter and the GAM video module -->
  <script src="https://your-domain.com/prebid.js" async></script>

<!-- TargetVideo Player -->
<script type="text/javascript" src="https://player.target-video.com/player/build/targetvideo.min.js"></script>

<script>
    var pbjs = pbjs || {};
    pbjs.que = pbjs.que || [];

    // define invokeVideoPlayer in advance in case we get the bids back from prebid before the entire page loads
    var tempTag = false;
    var invokeVideoPlayer = function(url){
      tempTag = url;
    }

    /*
    Prebid Video adUnit
    */

    var videoAdUnit = {
      code: 'video1',
            mediaTypes: {
        video: {
          context: "instream",
          playerSize: [640, 480]
        }
      },
      bids: [
        {
          bidder: 'appnexus',
          params: {
            placementId: '9333431', // Add your own placement id here
            video: {
              skippable: true,
              playback_method: ['auto_play_sound_off']
            }
          }
        }
      ]
    };

    pbjs.que.push(function(){
      pbjs.addAdUnits(videoAdUnit); // add your ad units to the bid request

      pbjs.setConfig({ 
        cache: {
            url: 'https://prebid.adnxs.com/pbc/v1/cache'
        }
      });

      pbjs.requestBids({
          bidsBackHandler: function(bids) {
              // Prebid.js 10 and later. In Prebid.js 9 and earlier, use pbjs.adServers.dfp.buildVideoUrl
              var videoUrl = pbjs.adServers.gam.buildVideoUrl({
                  adUnit: videoAdUnit,
                  params: {
                      iu: '/19968336/prebid_cache_video_adunit', // Replace with your own GAM ad unit path
                      cust_params: {
                        section: "blog",
                        anotherKey: "anotherValue"
                      },
                      output: "vast"
                  }
              });
              invokeVideoPlayer(videoUrl);
          }
      });
    });
  </script>

Add the following code where you want the player to appear. It loads the player with the ad tag URL that Prebid built — including when the bids came back before this code ran.

<div id="myDiv" style="width:640px; height:360px;"> </div>
    <script type="text/javascript">
      invokeVideoPlayer = function(url) {
        $bp("myDiv", {"id":"PLAYER_ID","width":"640","height":"360","video":"VIDEO_ID",
        "Ad": [
                {
                    "mobile": [url], // Array of URLs called in succession
        			"desktop": null, // Array of URLs called in succession
                    "adType": "0", // Type 0 for pre roll
                    "adTimeType": "s",
                    "overlayStartAt": null,
                    "overlayDuration": null,
                    "cuepoints": null
                }
            ]
        });
      }

      // The bids may have come back before this code ran
      if (tempTag) {
        invokeVideoPlayer(tempTag);
        tempTag = false;
      }
    </script>
Complete external config implementation · TargetVideo Developer Docs