Integrating Prebid.js with video on your own

Define Prebid Ad Units

Setting up Prebid ad units is almost the same whether you’re working with instream video ads or outstream. The primary difference is specifying the type of video ad (instream or outstream), which you do in the mediaTypes.video.context field:

    var adUnit1 = {
        code: 'videoAdUnit',
        mediaTypes: {
            video: {
                context: 'instream', //or 'outstream'
                playerSize: [640, 480],
                mimes: ['video/mp4'],    // required for Prebid Server
                protocols: [1, 2, 3, 4, 5, 6, 7, 8],
                playbackmethod: [2],
                skip: 1
            }

The mediaTypes.video.playerSize field is where you define the player size that will be passed to demand partners.

Prebid Server

If you’re using Prebid Server, you must also include the mediaTypes.video.mimes field, as this is required by OpenRTB.

For full details on video ad unit parameters, see Ad Unit Reference for Video

In your ad unit you also need to define your list of bidders. For example, including AppNexus as a bidder would look something like this:

    var adUnit1 = {
        ...
        bids: [{
            bidder: 'appnexus',
            params: {
                placementId: '123456789',
            }
        }]

The parameters differ depending on which bidder you’re including. For a list of parameters for each bidder, see Bidders’ Params.

For full details on creating instream video ad units, see Show Video Ads with Google Ad Manager – Create Ad Unit.

For full details on creating outstream video ad units, see Show Outstream Video Ads – Create Ad Unit.

Configuration

After you’ve defined your ad units, you can continue with the rest of your configuration. In most cases for video, the first step will be to define where the VAST XML coming back in the bids will be stored. Some bidders have you covered here – the VAST is stored on their servers. But many bidders don’t have their own server-side cache.

Video players expect that the response from the ad server will be a URL that points to somewhere on the internet that stores the video ad creative. This URL can’t point to the browser, so Prebid.js will send bid VAST XML out to a cache so it can be displayed if it wins in the ad server.

Configuring the video cache is done with setConfig:

    pbjs.setConfig({
        cache: {
            url: 'https://prebid.adnxs.com/pbc/v1/cache'
            /* Or whatever your preferred video cache URL is */
        }
    });

And this is where setups for instream and outstream diverge. Please follow one of these links:

Be sure to note the setting for price granularity. You might need to set up a custom price granularity. (See “Custom CPM Bucket Sizing” under Price Granularity. Or, if you’re monetizing both banner and video inventory with Prebid, you might need to define format-specific price granularity settings through mediaTypePriceGranularity.

Prebid Server If you’re using Prebid Server, you also need to configure your server-to-server bidder adapters. See Getting Started with Prebid Server.

Examples

This section contains working examples of instream and outstream video ads for various players.

Using client-side adapters

Instream

Outstream

Further Reading