Skip to content

Commit

Permalink
Improve Digital adapter: add support for outstream video (#5129)
Browse files Browse the repository at this point in the history
* Improve Digital: CCPA support

* Outstream video support

* Lint fixes
  • Loading branch information
jbartek25 authored Apr 21, 2020
1 parent b9cb920 commit f85862d
Show file tree
Hide file tree
Showing 2 changed files with 243 additions and 78 deletions.
69 changes: 60 additions & 9 deletions modules/improvedigitalBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import * as utils from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { config } from '../src/config.js';
import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js';
import {Renderer} from '../src/Renderer.js';

const BIDDER_CODE = 'improvedigital';
const RENDERER_URL = 'https://acdn.adnxs.com/video/outstream/ANOutstreamVideo.js';

export const spec = {
version: '6.1.0',
version: '7.0.0',
code: BIDDER_CODE,
gvlid: 253,
aliases: ['id'],
supportedMediaTypes: [BANNER, NATIVE, VIDEO],

Expand Down Expand Up @@ -61,7 +64,7 @@ export const spec = {
if (requestObj.errors && requestObj.errors.length > 0) {
utils.logError('ID WARNING 0x01');
}

requestObj.requests.forEach(request => request.bidderRequest = bidderRequest);
return requestObj.requests;
},

Expand All @@ -71,15 +74,15 @@ export const spec = {
* @param {*} serverResponse A successful response from the server.
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: function (serverResponse, bidRequest) {
interpretResponse: function (serverResponse, {bidderRequest}) {
const bids = [];
utils._each(serverResponse.body.bid, function (bidObject) {
if (!bidObject.price || bidObject.price === null ||
bidObject.hasOwnProperty('errorCode') ||
(!bidObject.adm && !bidObject.native)) {
return;
}

const bidRequest = utils.getBidRequest(bidObject.id, [bidderRequest]);
const bid = {};

if (bidObject.native) {
Expand All @@ -94,6 +97,14 @@ export const spec = {
} else if (bidObject.ad_type && bidObject.ad_type === 'video') {
bid.vastXml = bidObject.adm;
bid.mediaType = VIDEO;
if (isOutstreamVideo(bidRequest)) {
bid.adResponse = {
content: bid.vastXml,
height: bidObject.h,
width: bidObject.w
};
bid.renderer = createRenderer(bidRequest);
}
} else {
// Banner
let nurl = '';
Expand Down Expand Up @@ -136,10 +147,6 @@ export const spec = {
if (!bid.width || !bid.height) {
bid.width = 1;
bid.height = 1;
if (bidRequest.sizes) {
bid.width = bidRequest.sizes[0][0];
bid.height = bidRequest.sizes[0][1];
}
}

bids.push(bid);
Expand Down Expand Up @@ -180,6 +187,50 @@ function isInstreamVideo(bid) {
return bid.mediaType === 'video' || (videoMediaType && context !== 'outstream');
}

function isOutstreamVideo(bid) {
const videoMediaType = utils.deepAccess(bid, 'mediaTypes.video');
const context = utils.deepAccess(bid, 'mediaTypes.video.context');
return videoMediaType && context === 'outstream';
}

function outstreamRender(bid) {
bid.renderer.push(() => {
window.ANOutstreamVideo.renderAd({
sizes: [bid.width, bid.height],
width: bid.width,
height: bid.height,
targetId: bid.adUnitCode,
adResponse: bid.adResponse,
rendererOptions: {
showBigPlayButton: false,
showProgressBar: 'bar',
showVolume: false,
allowFullscreen: true,
skippable: false,
}
});
});
}

function createRenderer(bidRequest) {
const renderer = Renderer.install({
id: bidRequest.adUnitCode,
url: RENDERER_URL,
loaded: false,
config: {
player_width: bidRequest.mediaTypes.video.playerSize[0][0],
player_height: bidRequest.mediaTypes.video.playerSize[0][1]
},
adUnitCode: bidRequest.adUnitCode
});
try {
renderer.setRender(outstreamRender);
} catch (err) {
utils.logWarn('Prebid Error calling setRender on renderer', err);
}
return renderer;
}

function getNormalizedBidRequest(bid) {
let adUnitId = utils.getBidIdParameter('adUnitCode', bid) || null;
let placementId = utils.getBidIdParameter('placementId', bid.params) || null;
Expand Down Expand Up @@ -217,7 +268,7 @@ function getNormalizedBidRequest(bid) {
normalizedBidRequest.keyValues = keyValues;
}

if (config.getConfig('improvedigital.usePrebidSizes') === true && !isInstreamVideo(bid) && bid.sizes && bid.sizes.length > 0) {
if (config.getConfig('improvedigital.usePrebidSizes') === true && !isInstreamVideo(bid) && !isOutstreamVideo(bid) && bid.sizes && bid.sizes.length > 0) {
normalizedBidRequest.format = bid.sizes;
} else if (singleSizeFilter && singleSizeFilter.w && singleSizeFilter.h) {
normalizedBidRequest.size = {};
Expand Down
Loading

0 comments on commit f85862d

Please sign in to comment.