Table of Contents
The constructor signature is:
constructor(adContainer)
adContainer: HTMLElement
- (required) HTML element of the ad container
import AdsManager from 'ads-manager';
const adContainer = document.getElementById('ad-container');
// Define ads manager
const adsManager = new AdsManager(adContainer);
Get the version of AdsManager
.
String
- The current version ofAdsManager
.
Register a listener to a particular event.
eventName: String
- Event namecallback: Function
- Callback
Remove a listener for a particular event.
eventName: String
- Event name
Request ads from a server.
vastUrl: String
- The url of the VAST tag, or VAST XMLoptions: Object
- An optional Object to configure the ad requestmuted: Boolean
- A boolean, whether the ad will be played while muted.vastLoadTimeout: Number
- VAST document load timeout (default23000 ms
)loadVideoTimeout: Number
- VAST media file (assets) load timeout (default8000 ms
)withCredentials: Boolean
- A boolean to enable the withCredentials options for the XHR URLHandler (defaultfalse
)wrapperLimit: Number
- A number of Wrapper responses that can be received with no InLine response (default10
)
import AdsManager from 'ads-manager';
const adContainer = document.getElementById('ad-container');
const adsManager = new AdsManager(adContainer);
// ...
let vastUrl = 'https://v.adserve.tv/pg/vast.xml';
// Request ads without options
adsManager.requestAds(vastUrl);
// ...
// Request ads with options
adsManager.requestAds(vastUrl, {
loadVideoTimeout: 18000,
wrapperLimit: 7
});
Call init to initialize the ad experience on the ads manager.
width: Number
- The desired width of the ad.height: Number
- The desired height of the ad.viewMode: String
- The desired view mode. Value must not be null. Possible values ("normal"
or"fullscreen"
). Width and height are not required when viewMode is fullscreen.
Start playing the ads.
Pauses the current ad that is playing.
Resumes the current ad that is loaded and paused.
Stop playing the ads. Calling this will get publisher back to the content.
Skips the current ad, after the skip is completed the AdsManager
fires an AdSkipped
event.
Resizes the current ad. After the resize is completed the AdsManager
fires an AdSizeChange
event.
width: Number
- New ad slot width.height: Number
- New ad slot height.viewMode: String
- The new view mode. Value must not be null. Possible values ("normal"
or"fullscreen"
). Width and height are not required when viewMode is fullscreen.
Get the duration of the current ad.
Number
- The duration of the current ad.
Get the remaining time of the current ad that is playing. If the ad is not loaded yet or has finished playing, the API would return -1
.
Number
- Returns the time remaining for current ad. If the remaining time isundefined
for the current ad (for example custom ads), the value returns-1
.
Get the volume for the current ad.
Number
- The volume of the current ad, from0
(muted) to1
(loudest).
Set the volume for the current ad.
volume: Number
- The volume to set, from0
(muted) to1
(loudest).
Removes ad assets loaded at runtime that need to be properly removed at the time of ad completion and stops the ad and all tracking.
Cleans up the internal state, abort anything that is currently doing on with the AdsManager
and reset to a default state.
Returns true
if destroyed.
Boolean
Event | Description |
---|---|
AdsManagerLoaded |
Fired when the ads have been loaded and an AdsManager is available. |
AdError |
Fires when an error occurs. |
AdLoaded |
Fired when ad data is available. |
AdStarted |
Fired when the ad starts playing. |
AdDurationChange |
Fired when the ad's duration changes. |
AdSizeChange |
Fired when the ad size has changed. |
AdImpression |
Fired when the impression URL has been pinged. |
AdVideoStart |
Fired when the ad is started. |
AdVideoFirstQuartile |
Fired when the ad playhead crosses first quartile. |
AdVideoMidpoint |
Fired when the ad playhead crosses midpoint. |
AdVideoThirdQuartile |
Fired when the ad playhead crosses third quartile. |
AdVideoComplete |
Fired when the ad completes playing. |
AdPaused |
Fired when the ad is paused. |
AdPlaying |
Fired when the ad is resumed. |
AdStopped |
Fired when the ad is stopped. |
AdSkipped |
Fired when the ad is skipped by the user. |
AdClickThru |
Fired when the ad is clicked. |
AdVolumeChange |
Fired when the ad volume has changed. |
AllAdsCompleted |
Fired when the ads manager is done playing all the valid ads in the ads response, or when the response doesn't return any valid ads. |