Skip to content

Commit

Permalink
This PR adds an outstream video support for Yieldmo adapter.
Browse files Browse the repository at this point in the history
- adapter maintainer email: opensource@yieldmo.com
  • Loading branch information
ym-abaranov committed Apr 9, 2021
1 parent 19b4885 commit 487efbb
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 11 deletions.
64 changes: 53 additions & 11 deletions modules/yieldmoBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import * as utils from '../src/utils.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { Renderer } from '../src/Renderer.js';
import includes from 'core-js-pure/features/array/includes';
import find from 'core-js-pure/features/array/find.js';

const BIDDER_CODE = 'yieldmo';
const CURRENCY = 'USD';
const TIME_TO_LIVE = 300;
const NET_REVENUE = true;
const BANNER_SERVER_ENDPOINT = 'https://ads.yieldmo.com/exchange/prebid';
const VIDEO_SERVER_ENDPOINT = 'https://ads.yieldmo.com/exchange/prebidvideo';
const OUTSTREAM_VIDEO_PLAYER_URL = 'https://prebid-outstream-qa.yieldmo.com/bundle.js';
const OPENRTB_VIDEO_BIDPARAMS = ['placement', 'startdelay', 'skipafter',
'protocols', 'api', 'playbackmethod', 'maxduration', 'minduration', 'pos'];
const OPENRTB_VIDEO_SITEPARAMS = ['name', 'domain', 'cat', 'keywords'];
const localWindow = utils.getWindowTop();
const LOCAL_WINDOW = utils.getWindowTop();
const DEFAULT_PLAYBACK_METHOD = 2;
const DEFAULT_START_DELAY = 0;
const VAST_TIMEOUT = 15000;

export const spec = {
code: BIDDER_CODE,
Expand Down Expand Up @@ -48,12 +52,12 @@ export const spec = {
page_url: bidderRequest.refererInfo.referer,
bust: new Date().getTime().toString(),
pr: bidderRequest.refererInfo.referer,
scrd: localWindow.devicePixelRatio || 0,
scrd: LOCAL_WINDOW.devicePixelRatio || 0,
dnt: getDNT(),
description: getPageDescription(),
title: localWindow.document.title || '',
w: localWindow.innerWidth,
h: localWindow.innerHeight,
title: LOCAL_WINDOW.document.title || '',
w: LOCAL_WINDOW.innerWidth,
h: LOCAL_WINDOW.innerHeight,
userConsent: JSON.stringify({
// case of undefined, stringify will remove param
gdprApplies: utils.deepAccess(bidderRequest, 'gdprConsent.gdprApplies') || '',
Expand Down Expand Up @@ -198,8 +202,9 @@ function createNewBannerBid(response) {
* @param bidRequest server request
*/
function createNewVideoBid(response, bidRequest) {
const imp = find((utils.deepAccess(bidRequest, 'data.imp') || []), imp => imp.id === response.impid);
return {
const imp = (utils.deepAccess(bidRequest, 'data.imp') || []).find(imp => imp.id === response.impid);

let result = {
requestId: imp.id,
cpm: response.price,
width: imp.video.w,
Expand All @@ -211,6 +216,36 @@ function createNewVideoBid(response, bidRequest) {
ttl: TIME_TO_LIVE,
vastXml: response.adm
};

if (imp.placement !== 1) {

const renderer = Renderer.install({
url: OUTSTREAM_VIDEO_PLAYER_URL,
config: {
width: result.width,
height: result.height,
vastTimeout: VAST_TIMEOUT,
maxAllowedVastTagRedirects: 5,
allowVpaid: true,
autoPlay: true,
preload: true,
mute: true
},
id: imp.tagid,
loaded: false,
});

renderer.setRender(function (bid) {
bid.renderer.push(() => {
const { id, config } = bid.renderer;
window.YMoutstreamPlayer(bid, id, config);
});
});

result.renderer = renderer;
}

return result;
}

/**
Expand Down Expand Up @@ -297,10 +332,17 @@ function openRtbImpression(bidRequest) {
.filter(param => includes(OPENRTB_VIDEO_BIDPARAMS, param))
.forEach(param => imp.video[param] = videoParams[param]);

if (videoParams.skippable) {
imp.video.skip = 1;
}
if (videoParams.skippable) imp.video.skip = 1;

// if placement is not in-stream - it's always pre-roll (startdelay: 0) and playbackmethod = 2 in order to openRTB specs (Initiates on Page Load with Sound Off by Default)

if (videoParams.placement !== 1) {
imp.video = {
...imp.video,
startdelay: DEFAULT_START_DELAY,
playbackmethod: [ DEFAULT_PLAYBACK_METHOD ]
}
}
return imp;
}

Expand Down
27 changes: 27 additions & 0 deletions modules/yieldmoBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,30 @@ var adUnits = [{ // Video adUnit
}]
}];
```

Sample out-stream video ad unit config:
```javascript
var videoAdUnit = [{
code: 'div-video-ad-1234567890',
mediaTypes: {
video: {
playerSize: [640, 480], // required
context: 'outstream',
mimes: ['video/mp4'] // required, array of strings
}
},
bids: [{
bidder: 'yieldmo',
params: {
placementId: '1524592390382976659', // required
video: {
placement: 3, // required, integer ( 3,4,5 )
maxduration: 30, // required, integer
protocols: [2, 3], // required, array of integers
api: [2, 3], // required, array of integers
playbackmethod: [1,2] // required, array of integers
}
}
}]
}];
```

0 comments on commit 487efbb

Please sign in to comment.