Advertising with the FreeWheel Plugin

In this topic, you will learn how to use the FreeWheel plugin to enable advertisements with video playback, and how it can be implemented

Overview

This plugin enables FreeWheel ad technology in the Brightcove Player.

Testing the ad server

The first thing you should do is verify the validity of the ad tag you are planning to use. Be sure you have copied its URL and browse to the following page: Ad Previewer (clicking this link will cause the page to open in a new window or tab).

Paste your ad tag URL into the indicated form input field. Click OPEN IN AD PREVIEWER. A popup titled Open In Ad Previewer will display, and you then click the OPEN button to test your ad. Click PLAY and, if functioning correctly, your ad will display interspersed with a video. If your ad tag is not working in this test environment, it will not work with Brightcove Player.

The default AdManager SDK is v7.2.0 This supports Consent Management Platforms (CMPs) implementing the TCF v2 framework out of the box, with no plugin configuration required. CMPs implementing TCF v1 are no longer supported. More information in Freewheel's documentation (Freewheel Hub login required)

Steps

  1. Include the link to the CMP script in the page where the player is embedded

    Example

    <script src="//your_cmp_address.net/cmp/cmp.complete.bundle.js" async></script>
  2. Make sure you are using version 7.2.0+ of the Freewheel SDK. This is the default version if the sdkUrl option is not used. If you wish to set a version with either sdkUrl or sdkVersion, ensure the version is set to 7.2.0 or newer.

Implement using Players module

Players module support will be available soon.

Implement with JSON Editor

In the Players module, navigate to the player you want to configure and click the link for the JSON Editor. Modify the "plugins" array to add the FreeWheel plugin.

      
        "plugins": [
        {
          "name": "freewheel",
          "is_packaged": true,
          "options": {
            ...
          }
        }
      ]
    
    

Configuration

The following settings are used to configure the FreeWheel plugin:

Option Type Default Description
networkId number Required Your FreeWheel network identifier
profile string Required Your FreeWheel profile name
serverUrl string Required Your FreeWheel ad server URL
debug boolean false Enable debug logging
requestAdsMode string "onload" "onload" and "onplay" will request ads when the player loads and when the video first plays respectively. "oncue" will request ads at load time and ads are inserted at each VideoCloud cue point.
timeout number 5000 General timeout for ad operations (milliseconds)
prerollTimeout number 1000 Timeout for preroll ads (milliseconds)
pauseOnAdClickthrough boolean true Pause ad when user clicks through
temporalSlots array [] Array of temporal slot configurations
useMediaCuePoints boolean false Use VideoCloud cue points (requires requestAdsMode: "oncue")
keyValues array [] Key-value pairs for ad targeting
autoPlayType string "attended" Autoplay behavior: "attended", "unattended", or "none"
sdkUrl string FreeWheel CDN Custom FreeWheel SDK URL
sdkVersion string "7.2.0" FreeWheel SDK version. Ignored if sdkUrl is provided.
fwLogLevel string "quiet" SDK log level: "quiet", "info", or "debug"
adContainer boolean auto-detected Force container mode (true) or containerless mode (false)
capabilities array auto-detected Player capability list
compatibleDimensions array auto-detected Acceptable video dimensions
subsessionToken number - Subsession management token

Ad Slot Configuration

Temporal Slots

Temporal slots define when and where ads should play during video playback. Configure them using the temporalSlots array:


      {
          "temporalSlots": [
              {
                  "customId": "preroll",
                  "adUnit": "preroll",
                  "timeposition": 0
              }
          ]
      }

Temporal Slot Properties

Property Type Required Description
customId string Yes Unique identifier for the slot
adUnit string Yes FreeWheel ad unit name
timeposition number Yes When to play the ad (seconds from start)
maxDuration number No Maximum duration for the ad slot
acceptedDuration array No Array of acceptable ad durations

Ad macros

There are ad macros available to make your job easier when configuring FreeWheel. The ad macros are replaced with corresponding values anywhere in your configuration.

The following is the complete list of variable for which substituted values will be used:

Macro Description
{player.id} Player ID
{mediainfo.id} Video ID
{mediainfo.name} Video title
{mediainfo.description} Short description (250 chars max)
{mediainfo.tags} Tags (metadata) associated with the video
{mediainfo.reference_id} Reference ID
{mediainfo.duration} Duration of the video as reported by Video Cloud
{mediainfo.ad_keys} Free form text string that can be added and edited in the Media module of Studio; you should use the query parameter in the form
cust_params={mediainfo.ad_keys}
{player.duration} Duration of video as measured by player (possibly slightly different from mediainfo.duration and probably more accurate)
{document.referrer} Referring page URL
{window.location.href} Current page URL
{player.url} URL of the player
{timestamp} Current local time in milliseconds since 1/1/70
{random} A random number 0-1 trillion

Example configuration

"plugins": [{
  "name": "freewheel",
  "is_packaged": true,
  "options": {
      "keyValues": [{
        "feature": "simpleAds",
        "module": "DemoPlayer"
      }, {
        "feature": "trackingURLs"
      }],
      "networkId": 99999,
      "profile": "global-js",
      "serverUrl": "https://cue.v.fwmrm.net/ad/h/5",
      "siteSectionCustomId": "your value here",
      "temporalSlots": [{
        "adUnit": "preroll",
        "customId": "Preroll_1",
        "timePosition": 0
      }, {
        "adUnit": "postroll",
        "customId": "Postroll_1",
        "timePosition": 60
      }, {
        "adUnit": "overlay",
        "customIdd": "Overlay_1",
        "timePosition": 5
      }],
      "videoAssetCustomId": "your value here",
      "videoAssetDuration": 500
    },
    "debug": true,
    "prerollTimeout": 1000,
    "timeout": 5000
}]

Events

The plugin emits some custom event types during loading, initialization, and playback. You can listen for the ad framework events just like you would any other event:

player.on('ads-ad-started', function(event) {
  console.log('event', event);
});
Event Dispatched when:
ads-request Upon request ad data.
ads-load When ad data is available following an ad request.
ads-ad-started An ad has started playing.
ads-ad-ended An ad has finished playing.
ads-pause An ad is paused.
ads-play An ad is resumed from a pause.
ads-first-quartile The ad has played 25% of its total duration.
ads-midpoint The ad has played 50% of its total duration.
ads-third-quartile The ad has played 75% of its total duration.
ads-click A viewer clicked on the playing ad.
ads-skipped A viewer skipped the playing ad with the skip button.
ads-volumechange The volume of the playing ad has been changed.
ads-pod-started The first ad in a linear ad pod (a sequenced group of ads) has started.
ads-pod-ended The last ad in a linear ad pod (a sequenced group of ads) has finished.
ads-allpods-completed All linear ads have finished playing.
fw-before-ad-request This event is exposed on the player object and is triggered before submitting an ad request. Usually it is used in the context of playlists, to make updates to the FreeWheel Configuration settings via: setOptions()

Dynamic server URL assignment

You can use the fw-before-ad-request event to dynamically assign the server URL. You will use the on() method to listen for the ad request, then assign the desired server URL. Of course, you will need to supply your desired server URLs for the placeholders in the code:

player.on('fw-before-ad-request', function () {
  player.setOptions({
    serverUrl: '[your server url]'
  })
})

If you have configured the server URLs previously, the code shown will override the previous configuration.

Player Ad Libraries

The videojs/videojs-contrib-ads GitHub repository contains a plugin which provides common functionality needed by video advertisement libraries working with Brightcove Player. The plugin provides common functionality needed by video ad integrations and takes care of a number of concerns for ad integrators, reducing the code you have to write for your ad integration.

Properties

videojs-contrib-ads provides some properties that can be helpful. They are:

Name Data Type Description
ads.ad.id String Unique identifier for an ad that plays
ads.ad.index Number The index of the ad that plays at a specified time; the index would identify the ordinal value of an ad in an ad pod
ads.ad.duration Number The duration of the ad in seconds
ads.ad.type String Either PREROLL, MIDROLL or POSTROLL
ads.ad.currentTime() Function A function that returns the current time of ad playback

The following code demonstrates the use of the properties:

myPlayer.on('ads-ad-started',function( evt ){
  console.log('*****ads-ad-started event passed to event handler', evt);
  console.log('myPlayer.ads.ad.id',myPlayer.ads.ad.id);
  console.log('myPlayer.ads.ad.index',myPlayer.ads.ad.index);
  console.log('myPlayer.ads.ad.duration',myPlayer.ads.ad.duration);
  console.log('myPlayer.ads.ad.type',myPlayer.ads.ad.type);
  setTimeout(function(){
    console.log('****myPlayer.ads.ad.currentTime()',myPlayer.ads.ad.currentTime());
  },500);
  setTimeout(function(){
    console.log('****myPlayer.ads.ad.currentTime()',myPlayer.ads.ad.currentTime());
  },1000);
});

The output in the console from the above code is shown here:

console of contrib-ads properties

Methods

videojs-contrib-ads provides some methods that can be helpful. They are:

Method Description
inAdBreak() This method returns true during the time between startLinearAdMode and endLinearAdMode where an integration may play ads. This is part of ad mode.
isContentResuming() Returns true if content is resuming after an ad. This is part of ad mode.
isInAdMode() Returns true if the player is in ad mode.

Plugin Public Methods

The plugin exposes several methods for programmatic control:

setOptions(options)

Update plugin configuration at runtime. Options are validated before applying.

    
      player.freewheel().setOptions({
        debug: true,
        fwLogLevel: 'debug'
      });
    
  

Parameters:

  • options (object): The options to set, see Configuration for details

setSdkLogLevel(level)

Change the FreeWheel SDK log level, independently of the plugin's debug setting.

    
      // Set to "debug"
      player.freewheel().setSdkLogLevel('debug');

      // Set to "quiet"
      player.freewheel().setSdkLogLevel('quiet');
    
  

Parameters:

  • level (string): 'quiet', 'info', or 'debug'

hasAdContainer()

Check if the plugin will display ads in a container.

    
      const isContainerMode = player.freewheel().hasAdContainer();
      if (isContainerMode) {
          console.log('Using container mode');
      } else {
          console.log('Using containerless mode');
      }
    
    

Returns:

boolean

getContext()

Access the FreeWheel context object directly for advanced usage.

      
        const fwContext = player.freewheel().getContext();
        // Use FreeWheel SDK methods directly
      
    

Returns:

FreeWheel context object or null

getCurrentAdSlot()

Get information about the currently playing ad slot.

    
      const currentSlot = player.freewheel().getCurrentAdSlot();
      if (currentSlot) {
          console.log('Current ad slot:', currentSlot.customId);
      }
    
  

Returns:

Freewheel ad slot object or null

Known issues

Dynamically re-using the same player with FreeWheel

If you are loading videos dynamically and re-using the same player, the FreeWheel configuration settings will contain the same values as they were set at the time the FreeWheel plugin was instantiated, unless setOptions() is used to update the settings.

Resizing player during ad playback

If the player is resized during ad or video playback, ad content will not resize unless the player's dimensions function is called to resize the player. Resizing the player using other methods (for example: style width and height) will not resize the ad.

When using player.dimensions(width,height) to resize the player, you will have to trigger the fw-resizeplayer event so that the plugin will know the dimensions have changed. This is because some VPAID ads retain the default dimensions of the ad and will not automatically resize when the player resizes.

Here is an example:

player.dimensions(960,540);
player.trigger('fw-resizeplayer');