• Stars
    star
    449
  • Rank 97,328 (Top 2 %)
  • Language
    JavaScript
  • License
    Apache License 2.0
  • Created over 10 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

IMA SDK Plugin for Video.js

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:

Settings Type Description
adLabel string Replaces the "Advertisement" text in the ad label. Added for multilingual UI support.
adLabelNofN string Replaces the "of" text in the ad label (e.g. ... (1 of 2) ...). Added for multilingual UI support.
adTagUrl string A URL which returns a VAST, VMAP or ad rules response. This will override adsResponse.
adsRenderingSettings object JSON object with ads rendering settings as defined in the IMA SDK Docs(1).
adsResponse string The VAST, VMAP, or ad rules response to use in lieu of fetching one an ad tag. This is overridden if adTagUrl is set.
adsRequest object JSON 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.
autoPlayAdBreaks boolean Whether or not to automatically play VMAP or ad rules ad breaks. Defaults to true.
deprecated adWillPlayMuted boolean Notifies the SDK whether the player intends to start ad while muted. Changing this setting will have no impact on ad playback. Defaults to false.
contribAdsSettings object Additional settings to be passed to the contrib-ads plugin(3) used by this IMA plugin.
debug boolean True to load the debug version of the plugin, false to load the non-debug version. Defaults to false.
disableAdControls boolean True to hide the ad controls(play/pause, volume, and fullscreen buttons) during ad playback. Defaults to false.
disableCustomPlaybackForIOS10Plus boolean Sets whether to disable custom playback on iOS 10+ browsers. If true, ads will play inline if the content video is inline. Defaults to false.
disableFlashAds boolean True to disable Flash ads - Flash ads will be considered an unsupported ad type. Defaults to false.
featureFlags object Sets IMA SDK feature flags.
forceNonLinearFullSlot boolean True 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.
id string DEPRECATED as of v.1.5.0, no longer used or required.
locale string Locale for ad localization. The supported locale codes can be found in Localizing for Language and Locale
nonLinearHeight number Desired height for non-linear ads. Defaults to 1/3 player height.
nonLinearWidth number Desired width of non-linear ads. Defaults to player width.
numRedirects number Maximum 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.
omidVendorAccess object Sets 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.
ppid string Sets the publisher provided ID
preventLateAdStart boolean Prevent ads from starting after the content has started if an adtimeout occurred (preroll, midroll, postroll). The default value is false
sessionId string Sets the session ID
showControlsForJSAds boolean Whether or not to show the control bar for VPAID JavaScript ads. Defaults to true.
showCountdown boolean Whether or not to show the ad countdown timer. Defaults to true.
vastLoadTimeout number Override for default VAST load timeout in milliseconds for a single wrapper. The default timeout is 5000ms.
vpaidAllowed boolean DEPRECATED, please use vpaidMode.
vpaidMode VpaidMode(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.

Event Event String Payload
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.

More Repositories

1

googleads-mobile-android-examples

googleads-mobile-android
Java
1,693
star
2

googleads-mobile-unity

Official Unity Plugin for the Google Mobile Ads SDK
C#
1,355
star
3

googleads-mobile-ios-examples

googleads-mobile-ios
Objective-C
953
star
4

googleads-python-lib

The Python client library for Google's Ads APIs
Python
678
star
5

googleads-php-lib

Google Ad Manager SOAP API Client Library for PHP
PHP
657
star
6

google-ads-python

Google Ads API Client Library for Python
Python
498
star
7

googleads-mobile-flutter

A Flutter plugin for the Google Mobile Ads SDK
Java
341
star
8

google-api-ads-ruby

Ad Manager SOAP API Client Libraries for Ruby
Ruby
297
star
9

google-ads-php

Google Ads API Client Library for PHP
PHP
295
star
10

googleads-ima-html5

Samples for the HTML5 IMA SDK.
JavaScript
260
star
11

googleads-mobile-android-mediation

Sample Android project showcasing how to build a mediation adapter or custom event for the Google Mobile Ads SDK.
Java
240
star
12

googleads-java-lib

Google Ad Manager SOAP API Client Library for Java
Java
226
star
13

googleads-shopping-samples

Samples for the Content API for Shopping and the Manufacturer Center API
Java
192
star
14

google-ads-java

Google Ads API Client Library for Java
Java
167
star
15

google-media-framework-android

[DEPRECATED] The Google Media Framework (GMF) is a lightweight media player designed to make video playback and integration with the Google IMA SDK on Android easier.
Java
155
star
16

googleads-adsense-examples

Samples for the AdSense Management API
Java
142
star
17

swift-package-manager-google-mobile-ads

Swift
133
star
18

googleads-mobile-ios-mediation

Objective-C
118
star
19

googleads-mobile-android-native-templates

Java
116
star
20

googleads-ima-android

Samples for the IMA Android SDK.
Java
114
star
21

googleads-dotnet-lib

Google Ad Manager SOAP API .NET client library
C#
108
star
22

googleads-dfa-reporting-samples

Samples for the DoubleClick for Advertisers Reporting and Trafficking API
C#
106
star
23

googleads-consent-sdk-android

Consent SDK
Java
101
star
24

publisher-ads-lighthouse-plugin

Publisher Ads Audits for Lighthouse is a tool to improve ad speed and overall quality through a series of automated audits. This tool will aid in resolving discovered problems, providing a tool to be used to evaluate effectiveness of iterative changes while suggesting actionable feedback.
JavaScript
98
star
25

google-media-framework-ios

The Google Media Framework (GMF) is a lightweight media player designed to make video playback and integration with the Google IMA SDK on iOS easier.
Objective-C
74
star
26

admob-ads-in-flutter

Dart
73
star
27

google-ads-dotnet

This project hosts the .NET client library for the Google Ads API.
C#
72
star
28

google-ads-ruby

Google Ads API Ruby Client Library
Ruby
70
star
29

googleads-ima-ios

Samples for the iOS IMA SDK.
Objective-C
57
star
30

googleads-bidmanager-examples

PHP
42
star
31

googleads-admob-api-samples

googleads-admob-api-samples
Java
40
star
32

admob-inline-ads-in-flutter

Dart
40
star
33

google-publisher-tag-samples

Google Publisher Tag (GPT) code samples.
TypeScript
36
star
34

googleads-adxbuyer-examples

Samples for the DoubleClick Ad Exchange Buyer REST API
C#
34
star
35

googleads-ima-html5-dai

JavaScript
33
star
36

google-ads-doctor

Go
31
star
37

googleads-consent-sdk-ios

Consent SDK
Objective-C
31
star
38

googleads-adxseller-examples

Samples for the DoubleClick Ad Exchange Seller REST API
Java
20
star
39

googleads-ima-roku-dai

Brightscript
15
star
40

google-ads-perl

Google Ads API Client Library for Perl
Perl
15
star
41

googleads-mobile-ios-native-templates

Objective-C
14
star
42

dfp-playground

JavaScript
14
star
43

googleads-ima-tvos-dai

Objective-C
11
star
44

adwords-scripts-linkchecker

App Engine-based link checker for AdWords Scripts and Apps Script
Java
11
star
45

googleads-ima-cast

Samples for the Chromecast IMA SDK
JavaScript
10
star
46

googleads-displayvideo-examples

Display & Video 360 (DV360) API code samples.
Java
10
star
47

angular-dfp

Semantic DoubleClick integration with AngularJS
JavaScript
10
star
48

authorized-buyers-rtb-api-samples

C#
9
star
49

googleads-dynamic-ad-insertion

JavaScript
9
star
50

googleads-dfp-java-dfp-playground

DFP API Playground
Java
9
star
51

googleads-viewability-insights-extension

A DevTools extension for inspecting the viewability of Ad Manager Ads.
JavaScript
9
star
52

app-conversion-solutions

App Conversion Solutions with Google Ads API
Java
8
star
53

google-publisher-tag-types

Automatically generated TypeScript type definitions for the Google Publisher Tag JavaScript API
TypeScript
8
star
54

mobilevsi-android

Java
7
star
55

googleads-ima-android-dai

Java
7
star
56

googleads-dfa-samples

Samples for the DoubleClick for Advertisers API
PHP
7
star
57

googleads-ima-cast-dai

JavaScript
6
star
58

admob-firebase-codelabs-android

Kotlin
6
star
59

googleads-ima-tvos-client-side

Objective-C
6
star
60

googleads-perl-lib

AdWords API Perl Client Library
Perl
5
star
61

googleads-ima-ios-dai

Objective-C
5
star
62

html5-to-dfp

Python
5
star
63

admob-firebase-codelabs-unity

C#
5
star
64

swift-package-manager-google-user-messaging-platform

Swift
5
star
65

googleads-pal-webapp

An app demonstrating PAL SDK
TypeScript
4
star
66

googleads-ima-tizen-dai

JavaScript
4
star
67

gpt-ad

A Polymer element for defining GPT Ads in Polymer apps.
HTML
4
star
68

swift-package-manager-google-programmatic-access-library-ios

Swift
4
star
69

admob-appopen-unity

C#
3
star
70

swift-package-manager-google-interactive-media-ads-tvos

Swift
3
star
71

gpt-light-ad

HTML
3
star
72

swift-package-manager-google-programmatic-access-library-tvos

Swift
2
star
73

authorized-buyers-marketplace-api-samples

C#
2
star
74

swift-package-manager-google-interactive-media-ads-ios

Swift
2
star
75

conf-data-processing-architecture-reference-sample

2
star
76

hbbtv-lshape-demo

JavaScript
2
star
77

googleads-pal

Java
2
star
78

search-campaign-setup-booster

Python
2
star
79

google-publisher-tag-playground

An interactive code playground for Google Publisher Tag (GPT) samples.
TypeScript
2
star
80

comparison-shopping-service-api-samples

Code samples for the Comparison Shopping Service API (CSS API)
Java
1
star
81

.allstar

1
star
82

.github

1
star