You can override a player's ad policy using the setAdPolicy method in the Advertising Module of the Player API. This method allows you to change the policy that governs a player's ad requests on the fly. For example, you can modify the ad server URL, the key/value pairs, or the ad insertion points, on the fly based on any property values that are available to the player. Changes to a player's ad policy made with setAdPolicy() apply only for that player load. The next time the player loads, it uses the ad policy defined in the Advertising module, unless setAdPolicy() is called again.
For example, you may have set up your Video Cloud player's ad policy in the Advertising module to serve a pre-roll ad every 3 videos. On your website, perhaps you let registered users watch your content ad-free while visitors are subjected to the pre-roll ads. You can use the setAdPolicy() method to turn off pre-roll ad requests when the player is loaded by registered users. There are many other uses for this method. Take a moment to look over the properties you can set to see how you can dynamically control the ad policy for your player, and leverage this to deliver the right type of ads for videos on your site.
The Player API includes a corresponding get method, getAdPolicy, which returns the current ad policy. More values are returned in getAdPolicy, since not all ad policy values are settable.
To use the setAdPolicy method:
var player;
var adModule;
// called when template loads, we use this to store a reference to
// the player and modules
function onTemplateLoaded(pExperience) {
player= brightcove.getExperience(pExperience);
adModule = player.getModule(APIModules.ADVERTISING);
For more examples and reference information about the setAdPolicy method, see the Player API Reference.
The setAdPolicy method takes an AdPolicy Object. This is an object that contains any of the following properties. If a property isn't defined in the AdPolicy Object, then the current ad policy value is kept.
| Property | Type | Description |
|---|---|---|
| adServerURL | string | The URL to which the player should send ad requests. |
| playerAdKeys | string | The key/value pairs to associate with this player. For example, adPolicy.playerAdKeys ="key=somevalue,key1=somevalue2" |
| onLoadAdKeys | string | The key/value pairs to use with an ad request on player load. |
| prerollAdKeys | string | The key/value pairs to use with a pre-roll ad request. |
| midrollAdKeys | string | The key/value pairs to use with a mid-roll ad request. |
| postrollAdKeys | string | The key/value pairs to use with a post-roll ad request. |
| playAdOnLoad | boolean | Make an ad request on player load. |
| prerollAds | boolean | Make an ad request before video play. |
| midrollAds | boolean | Make an ad request during video play. |
| postrollAds | boolean | Make an ad request after video play. |
| adPlayCap | number | The maximum number of ads to play in response to each ad request. |