Skip to content

Commit 229b771

Browse files
committed
feat: adds IMA events
1 parent 317cdaa commit 229b771

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

README.md

+23
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,29 @@ the previous snippet. A summary of all settings follows:
176176
<br />
177177
(5) [google.ima.ImaSdkSettings.VpaidMode](//developers.google.com/interactive-media-ads/docs/sdks/html5/v3/apis#ima.ImaSdkSettings.VpaidMode)
178178

179+
## IMA Plugin Ad Events
180+
The IMA Plugin will fire events that can be listened for. Ad lifecycle events can be listened for by following our [Advanced Example](https://github.com/googleads/videojs-ima/blob/master/examples/advanced/ads.js)
181+
182+
Other events are emited from the videojs player. Please see the below example to set up listeners for these events.
183+
184+
```javascript
185+
this.player = videojs('content_video');
186+
187+
this.player.on('ads-manager', function(response){
188+
var adsManager = response.adsManager;
189+
// Your code in response to the `ads-manager` event.
190+
})
191+
```
192+
193+
Below are the events added by the videojs-ima plugin to the videojs player.
194+
195+
| Event | Event String | Payload |
196+
|-------|--------------|---------|
197+
| Ad Started | 'ads-ad-started' | none |
198+
| Ads Manager | 'ads-manager' | [google.ima.AdsManager](https://developers.google.com/interactive-media-ads/docs/sdks/html5/v3/apis#ima.AdsManager) |
199+
| Ads Loader | 'ads-loader' | [google.ima.AdsLoader](https://developers.google.com/interactive-media-ads/docs/sdks/html5/v3/apis#ima.AdsLoader) |
200+
| Ads Request | 'ads-request' | [google.ima.AdsRequest](https://developers.google.com/interactive-media-ads/docs/sdks/html5/v3/apis#ima.AdsRequest) |
201+
179202
## Disable automatic ad break playback
180203
In some circumstances you may want to prevent the SDK from playing ad breaks
181204
until you're ready for them. In this scenario, you can disable automatic

src/sdk-impl.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,11 @@ SdkImpl.prototype.initAdObjects = function() {
183183
google.ima.AdErrorEvent.Type.AD_ERROR,
184184
this.onAdsLoaderError.bind(this),
185185
false);
186+
187+
this.controller.playerWrapper.vjsPlayer.trigger({
188+
type: 'ads-loader',
189+
adsLoader: this.adsLoader,
190+
});
186191
};
187192

188193
/**
@@ -224,7 +229,7 @@ SdkImpl.prototype.requestAds = function() {
224229
}
225230

226231
this.adsLoader.requestAds(adsRequest);
227-
this.controller.triggerPlayerEvent('ads-request', adsRequest);
232+
this.controller.playerWrapper.vjsPlayer.trigger({ type: 'ads-request', AdsRequest: adsRequest });
228233
};
229234

230235

@@ -284,6 +289,11 @@ SdkImpl.prototype.onAdsManagerLoaded = function(adsManagerLoadedEvent) {
284289
this.onAdResumed.bind(this));
285290
}
286291

292+
this.controller.playerWrapper.vjsPlayer.trigger({
293+
type: 'ads-manager',
294+
adsManager: this.adsManager,
295+
});
296+
287297
if (!this.autoPlayAdBreaks) {
288298
this.initAdsManager();
289299
}

0 commit comments

Comments
 (0)