2.3.0 • Published 4 months ago

videojs-ima v2.3.0

Weekly downloads
7,791
License
Apache-2.0
Repository
github
Last release
4 months ago

IMA SDK Plugin for Video.js

Build Status

Introduction

You can use the IMA SDK Plugin for Video.js to integrate with the Video.js player.

If you're using the plugin for a DAI implementation, see the DAI readme for documentation.

To see the plugin in action, check out our samples.

Features

  • Integrate the Google IMA SDK into Video.js to enable advertising on your video content.

Requirements

  • Your favorite text editor
  • A JavaScript enabled browser

Get started

ES6 Imports

The easiest way to get started is to use npm.

npm install videojs-ima

Your index.html should contain the video.js stylesheet (not included in the npm module), a video player to be used for playback, and script tags for the IMA SDK and your own javascript file.

<html>
  <head>
    <!-- Load dependent stylesheets. -->
    <link href="path/to/video-js.css" rel="stylesheet">
    <link href="path/to/videojs.ima.css" rel="stylesheet"/>
  </head>

  <body>
    <video id='content_video' class="video-js">
        <p class='vjs-no-js'>
            To view this video, please enable JavaScript and consider upgrading to a web browser that
            <a href='https://videojs.com/html5-video-support/' target='_blank'>supports HTML5 video</a>
        </p>
    </video>
    <!-- Load dependent scripts -->
    <script src="//imasdk.googleapis.com/js/sdkloader/ima3.js"></script>
    <script src="player.js"></script>
  </body>
</html>

Three imports are required to use the videojs-ima module, as seen in the player.js example below.

import videojs from 'video.js';
import 'videojs-contrib-ads';
import 'videojs-ima';

var videoOptions = {
  controls: true,
  sources: [{
      src: 'PATH_TO_YOUR_CONTENT_VIDEO',
      type: 'YOUR_CONTENT_VIDEO_TYPE',
  }]
};

var player = videojs('content_video', videoOptions);

var imaOptions = {
  adTagUrl: 'YOUR_AD_TAG'
};

player.ima(imaOptions);
// On mobile devices, you must call initializeAdDisplayContainer as the result
// of a user action (e.g. button click). If you do not make this call, the SDK
// will make it for you, but not as the result of a user action. For more info
// see our examples, all of which are set up to work on mobile devices.
// player.ima.initializeAdDisplayContainer();

Alternative Setup

If you don't use npm, you can download the source from the dist/ folder and include it directly in your project. You'll also need to download the source for the videojs-contrib-ads plugin.

In your index.html file, create a new video.js player and load a (currently empty) javascript file:

<html>
  <head>
    <!-- Load dependent stylesheets. -->
    <link href="path/to/video-js.css" rel="stylesheet">
    <link rel="stylesheet" href="path/to/videojs-contrib-ads.css" />
    <link rel="stylesheet" href="path/to/videojs.ima.css" />
  </head>

  <body>
    <video id="content_video" class="video-js vjs-default-skin"
        controls preload="auto" width="YOUR_VIDEO_WIDTH" height="YOUR_VIDEO_HEIGHT">
      <source src="PATH_TO_YOUR_CONTENT_VIDEO" type="YOUR_CONTENT_VIDEO_TYPE" />
    </video>
    <!-- Load dependent scripts -->
    <script src="/path/to/video.js"></script>
    <script src="//imasdk.googleapis.com/js/sdkloader/ima3.js"></script>
    <script src="/path/to/videojs-contrib-ads.js"></script>
    <script src="/path/to/videojs.ima.js"></script>
    <script src="player.js"></script>
  </body>
</html>

In player.js, load the ads library and set up the IMA plugin:

var player = videojs('content_video');

var options = {
  adTagUrl: 'YOUR_AD_TAG'
};

player.ima(options);
// On mobile devices, you must call initializeAdDisplayContainer as the result
// of a user action (e.g. button click). If you do not make this call, the SDK
// will make it for you, but not as the result of a user action. For more info
// see our examples, all of which are set up to work on mobile devices.
// player.ima.initializeAdDisplayContainer();

Playground

Check out the snippet above in-action on CodePen.

Additional settings

The plugin accepts additional settings beyond the two required settings shown in the previous snippet. A summary of all settings follows:

SettingsTypeDescription
adLabelstringReplaces the "Advertisement" text in the ad label. Added for multilingual UI support.
adLabelNofNstringReplaces the "of" text in the ad label (e.g. ... (1 of 2) ...). Added for multilingual UI support.
adTagUrlstringA URL which returns a VAST, VMAP or ad rules response. This will override adsResponse.
adsRenderingSettingsobjectJSON object with ads rendering settings as defined in the IMA SDK Docs(1).
adsResponsestringThe VAST, VMAP, or ad rules response to use in lieu of fetching one an ad tag. This is overridden if adTagUrl is set.
adsRequestobjectJSON object with ads request properties defined in the IMA SDK Docs(2). Properties set here that can also be provided elsewhere (e.g. adTagUrl) will override those other settings.
autoPlayAdBreaksbooleanWhether or not to automatically play VMAP or ad rules ad breaks. Defaults to true.
deprecated adWillPlayMutedbooleanNotifies the SDK whether the player intends to start ad while muted. Changing this setting will have no impact on ad playback. Defaults to false.
contribAdsSettingsobjectAdditional settings to be passed to the contrib-ads plugin(3) used by this IMA plugin.
debugbooleanTrue to load the debug version of the plugin, false to load the non-debug version. Defaults to false.
disableAdControlsbooleanTrue to hide the ad controls(play/pause, volume, and fullscreen buttons) during ad playback. Defaults to false.
disableCustomPlaybackForIOS10PlusbooleanSets whether to disable custom playback on iOS 10+ browsers. If true, ads will play inline if the content video is inline. Defaults to false.
disableFlashAdsbooleanTrue to disable Flash ads - Flash ads will be considered an unsupported ad type. Defaults to false.
featureFlagsobjectSets IMA SDK feature flags.
forceNonLinearFullSlotbooleanTrue to force non-linear AdSense ads to render as linear fullslot. If set, the content video will be paused and the non-linear text or image ad will be rendered as fullslot. The content video will resume once the ad has been skipped or closed.
idstringDEPRECATED as of v.1.5.0, no longer used or required.
localestringLocale for ad localization. The supported locale codes can be found in Localizing for Language and Locale
nonLinearHeightnumberDesired height for non-linear ads. Defaults to 1/3 player height.
nonLinearWidthnumberDesired width of non-linear ads. Defaults to player width.
numRedirectsnumberMaximum number of VAST redirects before the subsequent redirects will be denied and the ad load aborted. The number of redirects directly affects latency and thus user experience. This applies to all VAST wrapper ads.
omidVendorAccessobjectSets and enables the Open Measurement SDK(4). Accepts an object with keys corresponding to OMID verification vendors(5). The value pair for each key should be the OMID access mode(6) associated with that vendor.
ppidstringSets the publisher provided ID
preventLateAdStartbooleanPrevent ads from starting after the content has started if an adtimeout occurred (preroll, midroll, postroll). The default value is false
sessionIdstringSets the session ID
showControlsForJSAdsbooleanWhether or not to show the control bar for VPAID JavaScript ads. Defaults to true.
showCountdownbooleanWhether or not to show the ad countdown timer. Defaults to true.
vastLoadTimeoutnumberOverride for default VAST load timeout in milliseconds for a single wrapper. The default timeout is 5000ms.
vpaidAllowedbooleanDEPRECATED, please use vpaidMode.
vpaidModeVpaidMode(5)VPAID Mode. Defaults to ENABLED. This setting,overrides vpaidAllowed.

(1) AdsRenderingSettings (2) AdsRequest (3) contrib-ads plugin (4) Open Measurement SDK guide (5) OmidVerificationVendor (6) OmidAccessMode (7) ImaSdkSettings.setVpaidMode

IMA Plugin Ad Events

The IMA Plugin fires events that can be listened for. Ad lifecycle events can be listened for by following our Advanced Example. Other events are emited from the videojs player. Please see the below example to set up listeners for these events.

this.player = videojs('content_video');

this.player.on('ads-manager', function(response){
  var adsManager = response.adsManager;
  // Your code in response to the `ads-manager` event.
})

Below are the events added by the videojs-ima plugin to the videojs player.

EventEvent StringPayload
Ad Started'ads-ad-started'none
Ads Manager'ads-manager'google.ima.AdsManager
Ads Loader'ads-loader'google.ima.AdsLoader
Ads Request'ads-request'google.ima.AdsRequest

Disable automatic ad break playback

In some circumstances you may want to prevent the SDK from playing ad breaks until you're ready for them. In this scenario, you can disable automatic playback of ad breaks in favor of letting the SDK know when you're ready for an ad break to play. To do so:

  1. Set autoPlayAdBreaks to false in the initial options.
  2. Provide an ad break ready listener via setAdBreakReadyListener.
  3. Call player.ima.playAdBreak() in your ad break ready listener when you're ready to play the ads.

Where do I report issues?

Please report issues on the issues page.

Terms of Service

The IMA SDK plugin for Video.js uses the IMA SDK, and as such is subject to the IMA SDK Terms of Service.

How do I contribute?

See CONTRIBUTING.md for details.

@applicaster/zapp-react-native-default-playerpops-plus-web@infinitebrahmanuniverse/nolb-vide@everything-registry/sub-chunk-3053@nimeshjohri/webplayer-sdkvideojsadxvooliom-playerwebplayer-sdkkal-demo@s3bubble/player@kmklabs/vjs-core-5.10.8-hls-3.5.2-ads-3.3.12-ima-2f3a06d@kmklabs/vjs-core-5.10.8-hls-3.6.13-ads-3.3.12-ima-2f3a06d@kmklabs/vjs-core-5.19.1-hls-5.8.3-ads-3.3.12-ima-2f3a06d@kmklabs/vjs-core-5.19.1-hls-5.8.3-ads-4.2.8-ima-2f3a06d@kmklabs/vjs-core-6.4.0-hls-5.8.3-ads-5.1.4-dash-2.9.3-ima-2f3a06d@kmklabs/vjs-core-6.4.0-hls-5.8.3-ads-5.1.4-dash-2.9.3-ima-2f3a06d-eme-3.2.0@kmklabs/vjs-core-6.4.0-hls-5.8.3-ads-5.1.4-ima-2f3a06d@kmklabs/vjs-core-6.5.0-hls-5.8.3-ads-5.1.4-dash-2.9.3-ima-2f3a06d-eme-3.2.0@kmklabs/vjs-core-6.6.0-hls-5.8.3-ads-5.1.4-dash-2.9.3-ima-2f3a06d-eme-3.2.0@kmklabs/vjs-core-6.7.0-hls-5.8.3-ads-5.1.4-dash-2.9.3-ima-2f3a06d-eme-3.2.0@kmklabs/vjs-core-6.7.4-hls-5.8.3-ads-5.1.4-dash-2.9.3-ima-2f3a06d-eme-3.2.0@kmklabs/vjs-core-6.8.0-hls-5.8.3-ads-5.1.4-dash-2.9.3-ima-2f3a06d-eme-3.2.0@kmklabs/vjs-core-6.9.0-hls-5.13.0-ads-5.1.5-ima-2f3a06d-dash-2.9.3@kmklabs/vjs-core-6.9.0-hls-5.14.1-ads-6.4.1-ima-2f3a06d-dash-2.9.3@kmklabs/vjs-core-6.9.0-hls-5.15.0-ads-6-ima-628213d-dash-2.9.3@kmklabs/vjs-core-6.9.0-hls-5.8.3-ads-5.1.4-dash-2.9.3-ima-2f3a06d@kmklabs/vjs-core-6.9.0-hls-5.8.3-ads-5.1.4-dash-2.9.3-ima-2f3a06d-eme-3.2.0@kmklabs/vjs-core-6.9.0-hls-5.8.3-ads-5.1.4-ima-2f3a06d-dash-2.9.1@kmklabs/vjs-core-6.9.0-hls-5.8.3-ads-5.1.4-ima-2f3a06d-dash-2.9.3@kmklabs/vjs-core-6.9.0-hls-5.8.3-ads-5.1.5-ima-2f3a06d-dash-2.9.3@kmklabs/vjs-core-6.9.0-hls-5.8.3-ads-5.1.5-ima-628213d-dash-2.9.3@kmklabs/vjs-core-6.9.0-hls-5.8.3-ads-6-ima-628213d-dash-2.9.3@kmklabs/vjs-core-6.9.0-hls-5.9.0-ads-6-ima-628213d-dash-2.9.3@kmklabs/vjs-core-7.0.5-hls-5.8.3-ads-5.1.4-dash-2.9.3-ima-2f3a06d-eme-3.2.0@zorraquino/eitb-ds@zorraquino/podkast-styleonlywatchcloudinary-video-playerstream-engine-player
2.3.0

4 months ago

2.2.0

9 months ago

2.1.0

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.11.0

3 years ago

1.10.1

3 years ago

1.10.0

3 years ago

1.9.1

3 years ago

1.9.0

3 years ago

1.8.3

4 years ago

1.8.2

4 years ago

1.8.1

4 years ago

1.8.0

4 years ago

1.7.5

4 years ago

1.7.4

4 years ago

1.7.3

4 years ago

1.7.2

5 years ago

1.7.1

5 years ago

1.7.0

5 years ago

1.6.3

5 years ago

1.6.2

5 years ago

1.6.1

5 years ago

1.6.0

5 years ago

1.5.2

5 years ago

1.5.1

6 years ago

1.5.0

6 years ago

1.4.0

6 years ago

1.3.0

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.8.0

6 years ago

0.7.0

7 years ago

0.6.0

7 years ago

0.5.0

8 years ago

0.4.0

8 years ago

0.1.0

10 years ago