From d6bdfaecd8889374b33ad04afd5560a80f91cae2 Mon Sep 17 00:00:00 2001 From: Jurij Sinickij Date: Mon, 20 Sep 2021 17:54:32 +0300 Subject: [PATCH 1/2] Adf adapter: additional bidder parameters --- modules/adfBidAdapter.js | 17 ++++++-- test/spec/modules/adfBidAdapter_spec.js | 57 ++++++++++++++++++++++--- 2 files changed, 66 insertions(+), 8 deletions(-) diff --git a/modules/adfBidAdapter.js b/modules/adfBidAdapter.js index f7727a168b8..60e1f60c73f 100644 --- a/modules/adfBidAdapter.js +++ b/modules/adfBidAdapter.js @@ -58,7 +58,11 @@ export const spec = { aliases: BIDDER_ALIAS, gvlid: GVLID, supportedMediaTypes: [ NATIVE, BANNER, VIDEO ], - isBidRequestValid: bid => !!bid.params.mid, + isBidRequestValid: (bid) => { + const params = bid.params || {}; + const { mid, inv, mname } = params; + return !!(mid || (inv && mname)); + }, buildRequests: (validBidRequests, bidderRequest) => { let app, site; @@ -104,12 +108,19 @@ export const spec = { }) : {}; const bidfloor = floorInfo.floor; const bidfloorcur = floorInfo.currency; + const { mid, inv, mname } = bid.params; const imp = { id: id + 1, - tagid: bid.params.mid, + tagid: mid, bidfloor, - bidfloorcur + bidfloorcur, + ext: { + bidder: { + inv, + mname + } + } }; const assets = _map(bid.nativeParams, (bidParams, key) => { diff --git a/test/spec/modules/adfBidAdapter_spec.js b/test/spec/modules/adfBidAdapter_spec.js index c8697032b3f..0b115c37b5b 100644 --- a/test/spec/modules/adfBidAdapter_spec.js +++ b/test/spec/modules/adfBidAdapter_spec.js @@ -29,11 +29,34 @@ describe('Adf adapter', function () { it('should return true when required params found', function () { assert(spec.isBidRequestValid(bid)); + + bid.params = { + inv: 1234, + mname: 'some-placement' + }; + assert(spec.isBidRequestValid(bid)); + + bid.params = { + mid: 4332, + inv: 1234, + mname: 'some-placement' + }; + assert(spec.isBidRequestValid(bid)); }); it('should return false when required params are missing', function () { bid.params = { adxDomain: 'adx.adform.net' }; assert.isFalse(spec.isBidRequestValid(bid)); + + bid.params = { + mname: 'some-placement' + }; + assert.isFalse(spec.isBidRequestValid(bid)); + + bid.params = { + inv: 1234 + }; + assert.isFalse(spec.isBidRequestValid(bid)); }); }); @@ -331,6 +354,30 @@ describe('Adf adapter', function () { } }); + describe('dynamic placement tag', function () { + it('should add imp parameters correctly', function () { + const validBidRequests = [ + { bidId: 'bidId', params: { inv: 1000, mname: 'placement' }, mediaTypes: {video: {}} }, + { bidId: 'bidId', params: { mid: 1234, inv: 1002, mname: 'placement2' }, mediaTypes: {video: {}} }, + { bidId: 'bidId', params: { mid: 1234 }, mediaTypes: {video: {}} } + ]; + const [ imp1, imp2, imp3 ] = getRequestImps(validBidRequests); + + assert.equal(imp1.ext.bidder.inv, 1000); + assert.equal(imp1.ext.bidder.mname, 'placement'); + assert.equal('tagid' in imp1, false); + + assert.equal(imp2.ext.bidder.inv, 1002); + assert.equal(imp2.ext.bidder.mname, 'placement2'); + assert.equal(imp2.tagid, 1234); + + assert.ok(imp3.ext.bidder); + assert.equal('inv' in imp3.ext.bidder, false); + assert.equal('mname' in imp3.ext.bidder, false); + assert.equal(imp3.tagid, 1234); + }); + }); + describe('price floors', function () { it('should not add if floors module not configured', function () { const validBidRequests = [{ bidId: 'bidId', params: {mid: 1000}, mediaTypes: {video: {}} }]; @@ -376,14 +423,10 @@ describe('Adf adapter', function () { return { currency: currency, floor - } + }; } }; } - - function getRequestImps(validBidRequests) { - return JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }).data).imp; - } }); describe('multiple media types', function () { @@ -626,6 +669,10 @@ describe('Adf adapter', function () { }); }); }); + + function getRequestImps(validBidRequests) { + return JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }).data).imp; + } }); describe('interpretResponse', function () { From 5723d6f4b426768b7e551939249eec38a5c023a2 Mon Sep 17 00:00:00 2001 From: Jurij Sinickij Date: Wed, 6 Oct 2021 13:24:19 +0300 Subject: [PATCH 2/2] allow multi media type bids --- modules/adfBidAdapter.js | 20 ++++----- test/spec/modules/adfBidAdapter_spec.js | 55 ++++++++++++++----------- 2 files changed, 38 insertions(+), 37 deletions(-) diff --git a/modules/adfBidAdapter.js b/modules/adfBidAdapter.js index 60e1f60c73f..f0425a174ff 100644 --- a/modules/adfBidAdapter.js +++ b/modules/adfBidAdapter.js @@ -164,9 +164,6 @@ export const spec = { assets } }; - - bid.mediaType = NATIVE; - return imp; } const bannerParams = deepAccess(bid, 'mediaTypes.banner'); @@ -183,18 +180,14 @@ export const spec = { imp.banner = { format }; - bid.mediaType = BANNER; - - return imp; } const videoParams = deepAccess(bid, 'mediaTypes.video'); if (videoParams) { imp.video = videoParams; - bid.mediaType = VIDEO; - - return imp; } + + return imp; }); const request = { @@ -254,6 +247,7 @@ export const spec = { return bids.map((bid, id) => { const bidResponse = bidResponses[id]; if (bidResponse) { + const mediaType = deepAccess(bidResponse, 'ext.prebid.type'); const result = { requestId: bid.bidId, cpm: bidResponse.price, @@ -261,12 +255,12 @@ export const spec = { ttl: 360, netRevenue: bid.netRevenue === 'net', currency: cur, - mediaType: bid.mediaType, + mediaType, width: bidResponse.w, height: bidResponse.h, dealId: bidResponse.dealid, meta: { - mediaType: bid.mediaType, + mediaType, advertiserDomains: bidResponse.adomain } }; @@ -274,10 +268,10 @@ export const spec = { if (bidResponse.native) { result.native = parseNative(bidResponse); } else { - result[ bid.mediaType === VIDEO ? 'vastXml' : 'ad' ] = bidResponse.adm; + result[ mediaType === VIDEO ? 'vastXml' : 'ad' ] = bidResponse.adm; } - if (!bid.renderer && bid.mediaType === VIDEO && deepAccess(bid, 'mediaTypes.video.context') === 'outstream') { + if (!bid.renderer && mediaType === VIDEO && deepAccess(bid, 'mediaTypes.video.context') === 'outstream') { result.renderer = Renderer.install({id: bid.bidId, url: OUTSTREAM_RENDERER_URL, adUnitCode: bid.adUnitCode}); result.renderer.setRender(renderer); } diff --git a/test/spec/modules/adfBidAdapter_spec.js b/test/spec/modules/adfBidAdapter_spec.js index 0b115c37b5b..ed096e7189d 100644 --- a/test/spec/modules/adfBidAdapter_spec.js +++ b/test/spec/modules/adfBidAdapter_spec.js @@ -430,7 +430,7 @@ describe('Adf adapter', function () { }); describe('multiple media types', function () { - it('should use single media type for bidding', function () { + it('should use all configured media types for bidding', function () { let validBidRequests = [{ bidId: 'bidId', params: { mid: 1000 }, @@ -457,20 +457,23 @@ describe('Adf adapter', function () { banner: { sizes: [[100, 100], [200, 300]] }, - native: {} + native: {}, + video: {} } }]; - let [ banner, video, native ] = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }).data).imp; - - assert.ok(banner.banner); - assert.equal(banner.video, undefined); - assert.equal(banner.native, undefined); - assert.ok(video.video); - assert.equal(video.banner, undefined); - assert.equal(video.native, undefined); - assert.ok(native.native); - assert.equal(native.video, undefined); - assert.equal(native.banner, undefined); + let [ first, second, third ] = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }).data).imp; + + assert.ok(first.banner); + assert.ok(first.video); + assert.equal(first.native, undefined); + + assert.ok(second.video); + assert.equal(second.banner, undefined); + assert.equal(second.native, undefined); + + assert.ok(third.native); + assert.ok(third.video); + assert.ok(third.banner); }); }); @@ -801,7 +804,12 @@ describe('Adf adapter', function () { imptrackers: ['imptrackers url1', 'imptrackers url2'] }, dealid: 'deal-id', - adomain: [ 'demo.com' ] + adomain: [ 'demo.com' ], + ext: { + prebid: { + type: 'native' + } + } } ] }], @@ -814,7 +822,6 @@ describe('Adf adapter', function () { { bidId: 'bidId1', params: { mid: 1000 }, - mediaType: 'native', nativeParams: { title: { required: true, len: 140 }, image: { required: false, wmin: 836, hmin: 627, w: 325, h: 300, mimes: ['image/jpg', 'image/gif'] }, @@ -946,7 +953,7 @@ describe('Adf adapter', function () { let serverResponse = { body: { seatbid: [{ - bid: [{ impid: '1', adm: '' }] + bid: [{ impid: '1', adm: '', ext: { prebid: { type: 'banner' } } }] }] } }; @@ -955,8 +962,7 @@ describe('Adf adapter', function () { bids: [ { bidId: 'bidId1', - params: { mid: 1000 }, - mediaType: 'banner' + params: { mid: 1000 } } ] }; @@ -964,6 +970,8 @@ describe('Adf adapter', function () { bids = spec.interpretResponse(serverResponse, bidRequest); assert.equal(bids.length, 1); assert.equal(bids[0].ad, ''); + assert.equal(bids[0].mediaType, 'banner'); + assert.equal(bids[0].meta.mediaType, 'banner'); }); }); @@ -972,7 +980,7 @@ describe('Adf adapter', function () { let serverResponse = { body: { seatbid: [{ - bid: [{ impid: '1', adm: '' }] + bid: [{ impid: '1', adm: '', ext: { prebid: { type: 'video' } } }] }] } }; @@ -981,8 +989,7 @@ describe('Adf adapter', function () { bids: [ { bidId: 'bidId1', - params: { mid: 1000 }, - mediaType: 'video' + params: { mid: 1000 } } ] }; @@ -990,13 +997,15 @@ describe('Adf adapter', function () { bids = spec.interpretResponse(serverResponse, bidRequest); assert.equal(bids.length, 1); assert.equal(bids[0].vastXml, ''); + assert.equal(bids[0].mediaType, 'video'); + assert.equal(bids[0].meta.mediaType, 'video'); }); it('should add renderer for outstream bids', function () { let serverResponse = { body: { seatbid: [{ - bid: [{ impid: '1', adm: '' }, { impid: '2', adm: '' }] + bid: [{ impid: '1', adm: '', ext: { prebid: { type: 'video' } } }, { impid: '2', adm: '', ext: { prebid: { type: 'video' } } }] }] } }; @@ -1006,7 +1015,6 @@ describe('Adf adapter', function () { { bidId: 'bidId1', params: { mid: 1000 }, - mediaType: 'video', mediaTypes: { video: { context: 'outstream' @@ -1016,7 +1024,6 @@ describe('Adf adapter', function () { { bidId: 'bidId2', params: { mid: 1000 }, - mediaType: 'video', mediaTypes: { video: { constext: 'instream'