Web Player

Advertisement

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 player. freqCap is a whole number of hours: after an ad starts, the viewer gets no more ads from this player 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 player ID; if local storage is unavailable, the cap isn’t applied.

Example:

$bp("myDiv", {
	"id":"PLAYER_ID",
	"width":"640",
	"height":"480",
	"video":"VIDEO_ID", 
	"freqCap":5
});

Get consent data from a hostile iframe

If you add the "use_tcfapi_locator": true parameter to the embed code, the player will try to grab consent data from a hostile iframe and then use it for advertising purposes.

Example:

$bp("myDiv", {"id":"PLAYER_ID","width":"480","height":"270","video":"VIDEO_ID", "use_tcfapi_locator":true});

Display banner ads when the player is served through DFP

If the player is served through DFP, there may be occasional issues with displaying banner ads correctly. To resolve this, simply add the "use_iframe_for_banners" parameter to the embed code.

Example:

$bp("myDiv", {"id":"PLAYER_ID","width":"480","height":"270","video":"VIDEO_ID", "use_iframe_for_banners":true});

Display the number of configured ad pods

Include the "showAdsCounter" parameter in the embed code if you wish to display the number of configured ad pods. It's important to note a system limitation when dealing with VMAP ads. The player won't count the number of ads due to inability to predict the number of ads a VMAP tag might return. Instead, it reserves one slot for these ads, skipping the display of a specific number for VMAP tags.

While the player effectively counts one ad pod as a single ad, it won't display any specific message during the playback of a VMAP ad. For example, if there are three pods — initially a VMAP ad followed by two VAST tags — during the playback of the VMAP ad, no message will be displayed. However, for the subsequent two VAST tags, the message will indicate "Showing 2 of 3" during the second one and "Showing 3 of 3" during the third.

The ad counter will accurately track ads for each position in the player. Preroll ads, midrolls, and postrolls will show the number of ads when it's time for playback in these slots. However, if only one pod is configured for preroll, midroll, or postroll, no message will be displayed.

If there is no valid ad response, one slot will be reserved for a specific ad pod, even though the ad won’t be displayed. To translate the label, set showing and of in translate, for example translate: {"showing": "…", "of": "…"}.

Example:

$bp("myDiv", {"id":"PLAYER_ID","width":"480","height":"270","video":"VIDEO_ID", "showAdsCounter":true});

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 player 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 player 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 player 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 player 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.

Remove the player if no ad is found or after an ad ends

The following example uses the destroy() method to remove the player from the page once the ad has finished playing, or if an adError happens.

Example:

function do_on_error() {
    // Remove player and all dependencies
    $bp().destroy();
    console.log('error fired removing player');
    // Add custom code here
}

function do_on_adend() {
    // Remove player and all dependencies
    $bp().destroy();
    console.log('ad end fired removing player');
    // Add custom code here
}

$bp("myDiv", configObj, 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);
});
$bp("myDiv", configObj);

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

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

Set a custom ad with the API

Use the code snippet below to instruct the player 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 into the video. 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 player already has a mid-roll, setAd replaces its ad tags but keeps its cue points. It has no effect on videos with monetization turned off.

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() {
    $bp("myDiv").setAd(Ad);
}
$bp("myDiv", {"id":"PLAYER_ID","width":"480","height":"270","video":"VIDEO_ID",
	"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, 1 Midroll, 2 Postroll
			"adType": "0", 
        }
    ]
});
$bp("myDiv", {"id":"PLAYER_ID","width":"640","height":"360","video":"VIDEO_ID",
	"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,1 Midroll, 2 Postroll
        }
    ]
});

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

Set sticky behavior for ad display only

Use the following code snippet to force the player to sticky only if a valid ad is received by the player.

❗ Important

Make sure that the player you are using has its sticky option enabled and that your player is set to autoplay.

Example:

$bp("myDiv", {
	"id":"PLAYER_ID",
	"width":"640",
	"height":"360",
	"video":"VIDEO_ID",
	"autoplayStickyAdOnly":true
});

Reset ad frequency counter on page refresh

Set resetFreqCounter to true to make the player restart its count of videos played on every page load. The player uses this count for the Ad Frequency and Ad Offset settings of your player in the CMS (for example, an ad every third video). It does not reset freqCap.

Example:

$bp("myDiv", {
	"id":"PLAYER_ID",
	"width":"640",
	"height":"360",
	"video":"VIDEO_ID",
	"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:

$bp("myDiv", {
	"id":"PLAYER_ID",
	"width":"640",
	"height":"360",
	"video":"VIDEO_ID",
	"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:

$bp("myDiv", {
	"id":"PLAYER_ID",
	"width":"640",
	"height":"360",
	"video":"VIDEO_ID",
	"a9_timeout": 2500	// 2.5 seconds
});

Show snapshot while loading an advertisement

By default, the player shows a black screen and a small loading ad pre-loader when trying to fetch an ad from an ad server. You can force the player to display a starting snapshot instead of a black screen by using the below parameter. This applies to pre-roll ads only.

Example:

$bp("myDiv", {
	"id":"PLAYER_ID",
	"width":"640",
	"height":"360",
	"video":"VIDEO_ID",
	"showSnapshotOnLoadingAd":true
});
Advertisement · TargetVideo Developer Docs