Web Player
Player + page prebid implementation
This is the way we recommend implementing Prebid with the TargetVideo player. 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 player works with the Prebid setup already on your page.
With this implementation, you run Prebid on your page and give the player 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 player 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 player 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 player which Prebid ad unit (in this case "video-1") you are using on your page. The player 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:
<script async src="https://securepubads.g.doubleclick.net/tag/js/gpt.js"></script>
<!-- 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"></script>
<!-- TargetVideo Player -->
<script type="text/javascript" src="https://player.target-video.com/player/build/targetvideo.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: 'instream'
}
},
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;
var bids = pbjs.getBidResponses();
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' && bids['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 to adUnits, TargetVideo player will grab it 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" style="width:480px;height:270px;" > </div>
<script type="text/javascript">
$bp("DIV_ID", {"id":"PLAYER_ID","width":"480","height":"270","video":"VIDEO_ID"});
</script>You can also see a complete working example of this implementation in the Prebid demo. The demo shows the player working with both video and display banner header bidding.
💡 Tip
When the player runs the Prebid auction itself, you can override the player 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.
Example:
var prebidPlayerSizeBrid = [640, 480];When the player 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
};