From d847489b22754976f945616449dabf2b1887d394 Mon Sep 17 00:00:00 2001 From: Anton Baranov Date: Tue, 9 Feb 2021 10:08:59 -0800 Subject: [PATCH] This PR adds an outstream video support for Yieldmo adapter. - adapter maintainer email: opensource@yieldmo.com --- modules/yieldmoBidAdapter.js | 60 +++++++++++++++++++++++++++++------- modules/yieldmoBidAdapter.md | 27 ++++++++++++++++ 2 files changed, 76 insertions(+), 11 deletions(-) diff --git a/modules/yieldmoBidAdapter.js b/modules/yieldmoBidAdapter.js index a4bd58140b9..fcace04ffdd 100644 --- a/modules/yieldmoBidAdapter.js +++ b/modules/yieldmoBidAdapter.js @@ -1,8 +1,8 @@ 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'; @@ -10,10 +10,14 @@ 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, @@ -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') || '', @@ -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, @@ -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; } /** @@ -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; } diff --git a/modules/yieldmoBidAdapter.md b/modules/yieldmoBidAdapter.md index 1b8b7b1b741..54be295a1a1 100644 --- a/modules/yieldmoBidAdapter.md +++ b/modules/yieldmoBidAdapter.md @@ -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 + } + } + }] +}]; +```