Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yieldmo bid adapter: set outstream renderer #6566

Merged
merged 1 commit into from
Apr 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 49 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.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 @@ -202,8 +206,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 @@ -219,6 +224,35 @@ function createNewVideoBid(response, bidRequest) {
mediaType: VIDEO,
},
};

if (imp.placement && 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 @@ -305,10 +339,14 @@ 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 (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
}
}
}]
}];
```