Outstream Units

Customize certain advertising aspects

Fine-tune advertisement behavior, loading and timeouts

Set frequency cap for ads

Use the following code snippet to set a per-viewer ad frequency cap in a TargetVideo outstream unit. freqCap is a whole number of hours: after an ad starts, the viewer gets no more ads from this unit for that many hours. In the example below, the value is 5, so a viewer gets an ad at most once every 5 hours. The cap is kept in the browser’s local storage, per unit ID; if local storage is unavailable, the cap isn’t applied.

Example:

$bos("DIV_ID", {
    "id":"UNIT_ID",
    "width":"640",
    "height":"480",
    "freqCap": 5
});

Custom ad tag parameters

By adding custom parameters to your ad tag URL, you can fine-tune advertising behavior.

Force specific ad parser

You can choose which ad parser the outstream unit uses for an ad tag by adding one of these parameters to the ad tag URL: brid_parser=ima for the Google IMA SDK, or brid_parser=brid for the player’s own parser.

Example:

// Append to the ad tag URL
&brid_parser=ima
// Append to the ad tag URL
&brid_parser=brid

Force insecure mode for VPAID ads

Certain VPAID ads need to run in an insecure (friendly) iframe to display properly when served through the Google IMA SDK. The outstream unit uses insecure mode by default, unless the embed code sets "ima_secure_mode": true. To force insecure mode for an ad tag even then, add the following string to its URL. Also add it to any ad tag that carries brid_adtimeout (see “Custom ad timeout” below): that parameter otherwise switches the tag to secure mode.

⚠️ Warning

Available only when using Google IMA SDK.

Example:

// Append to the ad tag URL
&brid_vpaidmode=insecure

Custom Ad timeout

You can change the default timeout the outstream unit has for ad tags by adding the following param to the end of your ad tag URL. The value is in seconds; tv_adtimeout works the same way.

📘 Note

By default this timeout is set to 15 seconds.

Example:

// Append to the ad tag URL
&brid_adtimeout=20

By adding the above to your ad tag, you will tell the outstream unit to wait for 20 seconds before it considers a timeout for this ad tag. On a tag with this parameter, VPAID ads run in secure mode unless you also add &brid_vpaidmode=insecure.

Load custom code once the outstream ad has completed playback

The following code examples show how to hook onto the outstream unit’s adEnd and adError events and run custom code, for example to remove the unit with destroy().

Example:

function do_on_error(){
    console.log('error fired do custom code');
    // Add custom code here
}

function do_on_adend(){
    console.log('ad end fired do custom code');
    // Add custom code here
}

$bos("DIV_ID", config, function(){
    // adEnd fires each time an ad ends (even if it errors out or doesn't exist)
    this.on('adEnd', do_on_adend);
    // adError fires only if an ad errors out, this includes empty VAST responses
    this.on('adError', do_on_error);
});
$bos("DIV_ID", config);

$bos("DIV_ID").on("adEnd", function(){
    // Remove the unit and all dependencies
    $bos("DIV_ID").destroy();
    console.log('ad end fired, removing unit');
    // Add custom code here
});

$bos("DIV_ID").on("adError", function(){
    // Remove the unit and all dependencies
    $bos("DIV_ID").destroy();
    console.log('error fired, removing unit');
    // Add custom code here
});

Set a custom ad with the API

Use the code snippet below to instruct the outstream unit to use a custom ad. The example sets two ad tag URLs, each returning a valid VAST response, as a mid-roll at 20 and 30 seconds. For setAd, the ad object takes adTagUrl — one URL or an array of URLs; the mobile and desktop arrays are only for the embed code’s Ad setting, shown in the next examples. If the unit already has a mid-roll, setAd replaces its ad tags but keeps its cue points.

Example:

var Ad = {
    // One ad tag URL, or an array of ad tag URLs called in succession
    "adTagUrl": ["AD_TAG_URL_1", "AD_TAG_URL_2"],
    // Type 0 for pre roll, 1 Midroll, 2 Postroll
    "adType": "1",
    // Used for midrolls, can be s=seconds, i=interval, %=percentage of the video
    "adTimeType": "s",
    // Cuepoints where you want the midroll to occur, if multiple, comma separated.
    "cuepoints": "20, 30"
};

function foo() {
    $bos("DIV_ID").setAd(Ad);
}
$bos("DIV_ID", {"id":"UNIT_ID","width":"480","height":"270",
    "Ad": [
        {
            /**
             * Mobile will be called on both mobile and desktop if desktop is left empty or omitted 
             * If desktop property is populated, 
             * the ad tags under mobile will get called on mobile only
             * and desktop on desktop only.
             */
            "mobile": ["AD_TAG_URL_1", "AD_TAG_URL_2", "AD_TAG_URL_3"], 
            // Will get called in succession on desktop
            "desktop": ["AD_TAG_URL_1", "AD_TAG_URL_2", "AD_TAG_URL_3"],
            // Type 0 for pre roll
            "adType": "0", 
        }
    ]
});
$bos("DIV_ID", {"id":"UNIT_ID","width":"640","height":"360",
    "Ad": [
        {
            // Will get called in succession on both mobile and desktop if the desktop array is left empty or omitted.
            "mobile": ["MOBILE_AD_TAG_URL_1", "MOBILE_AD_TAG_URL_2"],
            // Will get called in succession on desktop only
            "desktop": ["DESKTOP_AD_TAG_URL_1", "DESKTOP_AD_TAG_URL_2"],
            "adType": "0", // Type 0 for pre roll
        }
    ]
});

For the prepend and level arguments of setAd, see $bp().setAd(ad, prepend, level) in the JavaScript API reference.

Reset ad frequency counter on page refresh

Set resetFreqCounter to true to make the outstream unit restart its ad frequency counter on every page load. It does not reset freqCap.

Example:

$bos("DIV_ID", {
    "id":"UNIT_ID",
    "width":"640",
    "height":"360",
    "resetFreqCounter": true
});

Customize header bidding timeouts

Timeout for prebid

The example below sets how long Prebid waits for bids, in milliseconds.

📘 Note

The default is 3000 ms (3 s), unless your Prebid settings in the CMS set a different timeout. prebid_timeout in the embed code overrides both.

Example:

$bos("DIV_ID", {
    "id":"UNIT_ID",
    "width":"640",
    "height":"360",
    "prebid_timeout": 2500 // 2.5 seconds
});

Amazon header bidding

The example below sets how long Amazon header bidding (A9) waits for bids, in milliseconds.

📘 Note

The default is 3000 ms (3 s).

Example:

$bos("DIV_ID", {
    "id":"UNIT_ID",
    "width":"640",
    "height":"360",
    "a9_timeout": 2500
});
Customize certain advertising aspects · TargetVideo Developer Docs