Outstream Units
Multiple outstream units on page
Display only one ad unit if multiple Outstream ad units are located on a single page
This snippet will first call a TargetVideo in-slide ad unit and if it doesn't get a valid ad served, will call an in-content ad unit to try to display an ad. In the example, DIV_ID_1 has no div on the page, so the in-slide unit is created as a floating unit; the in-content unit renders in the div DIV_ID_2. Use two different ad unit IDs, and load the outstream script (targetvideo.outstream.min.js), which provides $bos.
<!-- DIV in which the in-content outstream unit should render. Note the ID of the DIV. -->
<div id="DIV_ID_2"> </div>
<!-- Reference to the outstream JS file-->
<script type="text/javascript" src="https://player.target-video.com/player/build/targetvideo.outstream.min.js"></script>
<!-- Code used for rendering the in-slide ad unit. -->
<script type="text/javascript">
// There is no element with the ID "DIV_ID_1" on the page, so this unit is created as a floating
// in-slide unit. Don't add a div for it.
// customOnReady is called once the unit is ready for API usage.
$bos("DIV_ID_1", {"id":"IN_SLIDE_UNIT_ID","width":"480","height":"270"}, customOnReady);
// This function checks if an ad is available for display in the in-slide unit. If no ad is found it calls the in-content unit initialization.
function customOnReady() {
this.add('adError', function() {
// Call in-content unit initialization. Note the ID that is used from the DIV above.
$bos("DIV_ID_2", {"id":"IN_CONTENT_UNIT_ID","width":"480","height":"270"});
});
}
</script>