Outstream Units
Outstream + page prebid implementation
This is the way we recommend implementing Prebid with a TargetVideo outstream unit. It combines Prebid on your page with a small setting in the CMS.
The main advantage is that you don’t have to change any existing TargetVideo embed codes, and the outstream unit works with the Prebid setup already on your page.
With this implementation, you run Prebid on your page and give the outstream unit a single reference: the Prebid ad unit code.
In the CMS, add a Prebid ad source with Prebid Implementation Type set to External via player embed, and add it to the ad schedule your outstream unit uses. In its field labelled GAM Ad Unit ID, enter the Prebid ad unit code from your page — in this example video-1 — not a Google Ad Manager path: the unit matches this value against the code of your page’s ad unit. Setting up the ad source itself is described in Prebid.js Integration in the Help Center.
The main difference here is that you need to tell the outstream unit which Prebid ad unit (in this case "video-1") you are using on your page. The unit looks for that ad unit in a global adUnits variable on your page (videoUnit, videoUnits and adUnit also work) and plays the vastUrl you set on it.
This is best explained with an example:
<!-- 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 PREBID_TIMEOUT = 2000;
var FAILSAFE_TIMEOUT = 3000;
var adUnits = [
{
code: 'video-1', // use this code in the CMS
mediaTypes: {
video: {
playerSize: [640, 480],
context: 'outstream'
}
},
bids: [{
bidder: 'appnexus',
params: {
placementId: 13232361,
video: {
skippable: true,
playback_method: ['auto_play_sound_off']
}
}
}]
}
];
var pbjs = pbjs || {};
pbjs.que = pbjs.que || [];
pbjs.que.push(function() {
pbjs.addAdUnits(adUnits);
pbjs.setConfig({
cache: {
url: 'https://prebid.adnxs.com/pbc/v1/cache'
}
});
pbjs.requestBids({
bidsBackHandler: initAdserver,
timeout: PREBID_TIMEOUT
});
});
function initAdserver() {
if (pbjs.initAdserverSet) return;
pbjs.initAdserverSet = true;
console.log('Prebid bids are back', pbjs.getBidResponses()); // bids are back, now we're requesting VAST URL for video unit
for (var i in adUnits) { // going through adUnits array
if (adUnits[i].code == 'video-1') { // searching for video unit. THIS IS THE CODE TO ENTER IN YOUR PREBID AD SOURCE IN THE CMS.
var vastUrl = pbjs.adServers.gam.buildVideoUrl({ // generating VAST URL (Prebid.js 10+; in 9 and earlier: pbjs.adServers.dfp)
adUnit: adUnits[i],
params: {
iu: '/19968336/prebid_cache_video_adunit', // Replace with your own GAM ad unit path
cust_params: {
section: 'blog',
anotherKey: 'anotherValue'
},
output: 'vast'
}
});
adUnits[i].vastUrl = vastUrl; // setting it on adUnits; the outstream unit picks it up from there
console.log('Prebid setting vastUrl on page', vastUrl);
}
}
googletag.cmd.push(function() {
pbjs.que.push(function() {
pbjs.setTargetingForGPTAsync();
googletag.pubads().refresh();
});
});
}
// in case PBJS doesn't load
setTimeout(function() {
initAdserver();
}, FAILSAFE_TIMEOUT);
</script>
<div id="DIV_ID"></div>
<script type="text/javascript"> $bos("DIV_ID", {"id":"UNIT_ID","width":"480","height":"270"}); </script>
💡 Tip
When the unit runs the Prebid auction itself, you can override the size it sends to Prebid by setting the following JavaScript variable on your page. Keep the name exactly as shown, with its old “Brid” suffix: the player reads this name.
var prebidPlayerSizeBrid = [640, 480];When the unit runs the Prebid auction itself, you can also give it your own Prebid configuration in prebidConfigBrid. It replaces the player’s default configuration and any Prebid settings from the CMS, so include the cache URL and price granularity as well. For example, to keep Prebid from reusing cached bids (useBidCache):
var prebidConfigBrid = {
cache: {url: 'https://cache.target-ad.com/cache'},
priceGranularity: 'auto',
useBidCache: false
};