Skip to content

Commit

Permalink
Merge pull request #830 from googleads/ads-events
Browse files Browse the repository at this point in the history
feat: adds IMA events
  • Loading branch information
Kiro705 authored Oct 4, 2019
2 parents 47cd607 + c5cb47d commit 77da05d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,27 @@ the previous snippet. A summary of all settings follows:
<br />
(5) [google.ima.ImaSdkSettings.VpaidMode](//developers.google.com/interactive-media-ads/docs/sdks/html5/v3/apis#ima.ImaSdkSettings.VpaidMode)

## IMA Plugin Ad Events
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). Other events are emited from the videojs player. Please see the below example to set up listeners for these events.

```javascript
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](https://developers.google.com/interactive-media-ads/docs/sdks/html5/v3/apis#ima.AdsManager) |
| Ads Loader | 'ads-loader' | [google.ima.AdsLoader](https://developers.google.com/interactive-media-ads/docs/sdks/html5/v3/apis#ima.AdsLoader) |
| Ads Request | 'ads-request' | [google.ima.AdsRequest](https://developers.google.com/interactive-media-ads/docs/sdks/html5/v3/apis#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
Expand Down
15 changes: 14 additions & 1 deletion src/sdk-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ SdkImpl.prototype.initAdObjects = function() {
google.ima.AdErrorEvent.Type.AD_ERROR,
this.onAdsLoaderError.bind(this),
false);

this.controller.playerWrapper.vjsPlayer.trigger({
type: 'ads-loader',
adsLoader: this.adsLoader,
});
};

/**
Expand Down Expand Up @@ -224,7 +229,10 @@ SdkImpl.prototype.requestAds = function() {
}

this.adsLoader.requestAds(adsRequest);
this.controller.triggerPlayerEvent('ads-request', adsRequest);
this.controller.playerWrapper.vjsPlayer.trigger({
type: 'ads-request',
AdsRequest: adsRequest,
});
};


Expand Down Expand Up @@ -284,6 +292,11 @@ SdkImpl.prototype.onAdsManagerLoaded = function(adsManagerLoadedEvent) {
this.onAdResumed.bind(this));
}

this.controller.playerWrapper.vjsPlayer.trigger({
type: 'ads-manager',
adsManager: this.adsManager,
});

if (!this.autoPlayAdBreaks) {
this.initAdsManager();
}
Expand Down

0 comments on commit 77da05d

Please sign in to comment.