Outstream Units

Complete external config implementation

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

This page contains:

  • Setting up a TargetVideo outstream unit to play ads dynamically.

  • Using a cloud-hosted player.

  • Dynamically insert a preroll ad into the outstream unit.

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 outstream unit -->
<script type="text/javascript" src="https://player.target-video.com/player/build/targetvideo.outstream.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: "outstream",
                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 outstream unit to appear. It loads the unit with the ad tag URL that Prebid built — including when the bids came back before this code ran.

<div id="DIV_ID" style="width:640px; height:360px;"> </div>
<script type="text/javascript">
    invokeVideoPlayer = function(url) {
        $bos("DIV_ID", {"id":"UNIT_ID","width":"640","height":"360",
            "Ad": [
                {
                    "mobile": [url], // Array of URLs called in succession on mobile
                    "desktop": null, // Array of URLs called in succession on desktop
                    "adType": "0", // Type 0 for pre roll
                }
            ]
        });
    }

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