From d717392b054fcf340cc2cae960ea38350d033858 Mon Sep 17 00:00:00 2001 From: Chris Huie Date: Tue, 27 Sep 2022 08:36:40 -0600 Subject: [PATCH 1/6] add video --- modules/eplanningBidAdapter.js | 50 ++- test/spec/modules/eplanningBidAdapter_spec.js | 286 +++++++++++++++++- 2 files changed, 334 insertions(+), 2 deletions(-) diff --git a/modules/eplanningBidAdapter.js b/modules/eplanningBidAdapter.js index 0d37b72f4ad..f631fa2f036 100644 --- a/modules/eplanningBidAdapter.js +++ b/modules/eplanningBidAdapter.js @@ -2,6 +2,7 @@ import {getWindowSelf, isEmpty, parseSizesInput, isGptPubadsDefined, isSlotMatch import {getGlobal} from '../src/prebidGlobal.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {getStorageManager} from '../src/storageManager.js'; +import {BANNER, VIDEO} from '../src/mediaTypes.js'; const BIDDER_CODE = 'eplanning'; export const storage = getStorageManager({bidderCode: BIDDER_CODE}); @@ -19,9 +20,14 @@ const STORAGE_VIEW_PREFIX = 'pbvi_'; const mobileUserAgent = isMobileUserAgent(); const PRIORITY_ORDER_FOR_MOBILE_SIZES_ASC = ['1x1', '300x50', '320x50', '300x250']; const PRIORITY_ORDER_FOR_DESKTOP_SIZES_ASC = ['1x1', '970x90', '970x250', '160x600', '300x600', '728x90', '300x250']; +const VAST_INSTREAM = 1; +const VAST_OUTSTREAM = 2; +const VAST_VERSION_DEFAULT = 3; +const DEFAULT_SIZE_VAST = '640x480'; export const spec = { code: BIDDER_CODE, + supportedMediaTypes: [BANNER, VIDEO], isBidRequestValid: function(bid) { return Boolean(bid.params.ci) || Boolean(bid.params.t); @@ -88,6 +94,11 @@ export const spec = { } } + if (spaces.impType) { + params.vctx = spaces.impType & VAST_INSTREAM ? VAST_INSTREAM : VAST_OUTSTREAM; + params.vv = VAST_VERSION_DEFAULT; + } + return { method: method, url: url, @@ -119,6 +130,13 @@ export const spec = { advertiserDomains: ad.adom }; } + if (isVastResponse(ad)) { + bidResponse.vastXml = ad.adm; + bidResponse.mediaTypes = VIDEO; + } else { + bidResponse.ad = ad.adm; + } + bidResponses.push(bidResponse); }); } @@ -236,17 +254,42 @@ function getSpacesStruct(bids) { return e; } +function getFirstSizeVast(sizes) { + if (sizes == undefined || !Array.isArray(sizes)) { + return undefined; + } + + let size = Array.isArray(sizes[0]) ? sizes[0] : sizes; + + return (Array.isArray(size) && size.length == 2) ? size : undefined; +} + function cleanName(name) { return name.replace(/_|\.|-|\//g, '').replace(/\)\(|\(|\)|:/g, '_').replace(/^_+|_+$/g, ''); } function getSpaces(bidRequests, ml) { + let impType = bidRequests.reduce((previousBits, bid) => (bid.mediaTypes && bid.mediaTypes[VIDEO]) ? (bid.mediaTypes[VIDEO].context == 'outstream' ? (previousBits | 2) : (previousBits | 1)) : previousBits, 0); + // Only one type of auction is supported at a time + if (impType) { + bidRequests = bidRequests.filter((bid) => bid.mediaTypes && bid.mediaTypes[VIDEO] && (impType & VAST_INSTREAM ? (!bid.mediaTypes[VIDEO].context || bid.mediaTypes[VIDEO].context == 'instream') : (bid.mediaTypes[VIDEO].context == 'outstream'))); + } + let spacesStruct = getSpacesStruct(bidRequests); - let es = {str: '', vs: '', map: {}}; + let es = {str: '', vs: '', map: {}, impType: impType}; es.str = Object.keys(spacesStruct).map(size => spacesStruct[size].map((bid, i) => { es.vs += getVs(bid); let name; + + if (impType) { + let firstSize = getFirstSizeVast(bid.mediaTypes[VIDEO].playerSize); + let sizeVast = firstSize ? firstSize.join('x') : DEFAULT_SIZE_VAST; + name = 'video_' + sizeVast + '_' + i; + es.map[name] = bid.bidId; + return name + ':' + sizeVast + ';1'; + } + if (ml) { name = cleanName(bid.adUnitCode); } else { @@ -462,4 +505,9 @@ function registerAuction(storageID) { return true; } + +function isVastResponse(bid) { + return bid.adm.match(/^( Date: Tue, 27 Sep 2022 07:51:00 -0700 Subject: [PATCH 2/6] move up imptypes logic --- modules/eplanningBidAdapter.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/modules/eplanningBidAdapter.js b/modules/eplanningBidAdapter.js index f631fa2f036..6f8d0ef1e10 100644 --- a/modules/eplanningBidAdapter.js +++ b/modules/eplanningBidAdapter.js @@ -92,11 +92,10 @@ export const spec = { params['e_' + id] = (typeof userIds[id] === 'object') ? encodeURIComponent(JSON.stringify(userIds[id])) : encodeURIComponent(userIds[id]); } } - } - - if (spaces.impType) { + if (spaces.impType) { params.vctx = spaces.impType & VAST_INSTREAM ? VAST_INSTREAM : VAST_OUTSTREAM; params.vv = VAST_VERSION_DEFAULT; + } } return { From 426e6d877397f91c17d7d091056e14d1ce1db0f3 Mon Sep 17 00:00:00 2001 From: Chris Huie Date: Tue, 27 Sep 2022 07:54:35 -0700 Subject: [PATCH 3/6] fix linting --- modules/eplanningBidAdapter.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/eplanningBidAdapter.js b/modules/eplanningBidAdapter.js index 6f8d0ef1e10..6a359cdcb2e 100644 --- a/modules/eplanningBidAdapter.js +++ b/modules/eplanningBidAdapter.js @@ -93,8 +93,8 @@ export const spec = { } } if (spaces.impType) { - params.vctx = spaces.impType & VAST_INSTREAM ? VAST_INSTREAM : VAST_OUTSTREAM; - params.vv = VAST_VERSION_DEFAULT; + params.vctx = spaces.impType & VAST_INSTREAM ? VAST_INSTREAM : VAST_OUTSTREAM; + params.vv = VAST_VERSION_DEFAULT; } } From d7974d4c1971f2178253596591823cc48486fe3f Mon Sep 17 00:00:00 2001 From: Chris Huie Date: Tue, 27 Sep 2022 08:37:23 -0700 Subject: [PATCH 4/6] update curly braces --- test/spec/modules/eplanningBidAdapter_spec.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/spec/modules/eplanningBidAdapter_spec.js b/test/spec/modules/eplanningBidAdapter_spec.js index 05d141fdfc0..244c84daba2 100644 --- a/test/spec/modules/eplanningBidAdapter_spec.js +++ b/test/spec/modules/eplanningBidAdapter_spec.js @@ -838,9 +838,8 @@ describe('E-Planning Adapter', function () { }; expect(bidResponse).to.deep.equal(expectedResponse); }); - }); - - it('should correctly map the parameters in the response vast', function () { + + it('should correctly map the parameters in the response vast', function () { const bidResponse = spec.interpretResponse(responseVast, { adUnitToBidId: { [CLEAN_ADUNIT_CODE_VAST]: BID_ID } })[0]; const expectedResponse = { requestId: BID_ID, @@ -872,6 +871,7 @@ describe('E-Planning Adapter', function () { mediaTypes: VIDEO }; expect(bidResponse).to.deep.equal(expectedResponse); + }); }); describe('getUserSyncs', function () { From cd933700485a747ae9d0e0c8b53b67c29b900f73 Mon Sep 17 00:00:00 2001 From: Chris Huie Date: Tue, 27 Sep 2022 08:44:26 -0700 Subject: [PATCH 5/6] fix spaces linting --- test/spec/modules/eplanningBidAdapter_spec.js | 62 +++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/test/spec/modules/eplanningBidAdapter_spec.js b/test/spec/modules/eplanningBidAdapter_spec.js index 244c84daba2..a356c9cee95 100644 --- a/test/spec/modules/eplanningBidAdapter_spec.js +++ b/test/spec/modules/eplanningBidAdapter_spec.js @@ -838,39 +838,39 @@ describe('E-Planning Adapter', function () { }; expect(bidResponse).to.deep.equal(expectedResponse); }); - + it('should correctly map the parameters in the response vast', function () { - const bidResponse = spec.interpretResponse(responseVast, { adUnitToBidId: { [CLEAN_ADUNIT_CODE_VAST]: BID_ID } })[0]; - const expectedResponse = { - requestId: BID_ID, - cpm: CPM, - width: W, - height: H, - ttl: 120, - creativeId: CRID, - netRevenue: true, - currency: 'USD', - vastXml: ADM_VAST, - mediaTypes: VIDEO - }; - expect(bidResponse).to.deep.equal(expectedResponse); - }); + const bidResponse = spec.interpretResponse(responseVast, { adUnitToBidId: { [CLEAN_ADUNIT_CODE_VAST]: BID_ID } })[0]; + const expectedResponse = { + requestId: BID_ID, + cpm: CPM, + width: W, + height: H, + ttl: 120, + creativeId: CRID, + netRevenue: true, + currency: 'USD', + vastXml: ADM_VAST, + mediaTypes: VIDEO + }; + expect(bidResponse).to.deep.equal(expectedResponse); + }); - it('should correctly map the parameters in the response vast vv 1', function () { - const bidResponse = spec.interpretResponse(responseVastVV1, { adUnitToBidId: { [CLEAN_ADUNIT_CODE_VAST]: BID_ID } })[0]; - const expectedResponse = { - requestId: BID_ID, - cpm: CPM, - width: W, - height: H, - ttl: 120, - creativeId: CRID, - netRevenue: true, - currency: 'USD', - vastXml: ADM_VAST_VV_1, - mediaTypes: VIDEO - }; - expect(bidResponse).to.deep.equal(expectedResponse); + it('should correctly map the parameters in the response vast vv 1', function () { + const bidResponse = spec.interpretResponse(responseVastVV1, { adUnitToBidId: { [CLEAN_ADUNIT_CODE_VAST]: BID_ID } })[0]; + const expectedResponse = { + requestId: BID_ID, + cpm: CPM, + width: W, + height: H, + ttl: 120, + creativeId: CRID, + netRevenue: true, + currency: 'USD', + vastXml: ADM_VAST_VV_1, + mediaTypes: VIDEO + }; + expect(bidResponse).to.deep.equal(expectedResponse); }); }); From 3602048981820ea95a63ed1e1b34a7e746481a7d Mon Sep 17 00:00:00 2001 From: Chris Huie Date: Tue, 27 Sep 2022 10:52:52 -0700 Subject: [PATCH 6/6] fix line --- modules/eplanningBidAdapter.js | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/eplanningBidAdapter.js b/modules/eplanningBidAdapter.js index 6a359cdcb2e..b60c3571d47 100644 --- a/modules/eplanningBidAdapter.js +++ b/modules/eplanningBidAdapter.js @@ -118,7 +118,6 @@ export const spec = { cpm: ad.pr, width: ad.w, height: ad.h, - ad: ad.adm, ttl: TTL, creativeId: ad.crid, netRevenue: NET_REVENUE,