From 0c178436d2f2a758919ba1bf0df064afec7718d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Sok=C3=B3=C5=82?= Date: Wed, 28 Jul 2021 10:15:38 +0200 Subject: [PATCH 1/3] SADR-2305 Add support for floors module --- modules/smartadserverBidAdapter.js | 81 +++-- .../modules/smartadserverBidAdapter_spec.js | 300 +++++++++++++++++- 2 files changed, 347 insertions(+), 34 deletions(-) diff --git a/modules/smartadserverBidAdapter.js b/modules/smartadserverBidAdapter.js index bb9364c72c3..fcc115ecbda 100644 --- a/modules/smartadserverBidAdapter.js +++ b/modules/smartadserverBidAdapter.js @@ -1,19 +1,13 @@ import * as utils from '../src/utils.js'; -import { - BANNER, - VIDEO -} from '../src/mediaTypes.js'; -import { - config -} from '../src/config.js'; -import { - registerBidder -} from '../src/adapters/bidderFactory.js'; -import { - createEidsArray -} from './userId/eids.js'; +import { BANNER, VIDEO } from '../src/mediaTypes.js'; +import { config } from '../src/config.js'; +import { createEidsArray } from './userId/eids.js'; +import { registerBidder } from '../src/adapters/bidderFactory.js'; + const BIDDER_CODE = 'smartadserver'; const GVL_ID = 45; +const DEFAULT_FLOOR = 0.0; + export const spec = { code: BIDDER_CODE, gvlid: GVL_ID, @@ -53,8 +47,8 @@ export const spec = { */ buildRequests: function (validBidRequests, bidderRequest) { // use bidderRequest.bids[] to get bidder-dependent request info - // if your bidder supports multiple currencies, use config.getConfig(currency) - // to find which one the ad server needs + + const adServerCurrency = config.getConfig('currency.adServerCurrency'); // pull requested transaction ID from bidderRequest.bids[].transactionId return validBidRequests.map(bid => { @@ -63,8 +57,8 @@ export const spec = { siteid: bid.params.siteId, pageid: bid.params.pageId, formatid: bid.params.formatId, - currencyCode: config.getConfig('currency.adServerCurrency'), - bidfloor: bid.params.bidfloor || 0.0, + currencyCode: adServerCurrency, + bidfloor: bid.params.bidfloor || spec.getBidFloor(bid, adServerCurrency), targeting: bid.params.target && bid.params.target !== '' ? bid.params.target : undefined, buid: bid.params.buId && bid.params.buId !== '' ? bid.params.buId : undefined, appname: bid.params.appName && bid.params.appName !== '' ? bid.params.appName : undefined, @@ -86,15 +80,36 @@ export const spec = { h: size[1] })); } else if (videoMediaType && (videoMediaType.context === 'instream' || videoMediaType.context === 'outstream')) { + // use IAB ORTB values if the corresponding values weren't already set by bid.params.video + // Assign a default protocol, the highest value possible means we are retrocompatible with all older values. + var protocol = null; + if (bid.params.video && bid.params.video.protocol) { + protocol = bid.params.video.protocol; + } else if (Array.isArray(videoMediaType.protocols)) { + protocol = Math.max.apply(Math, videoMediaType.protocols); + } + + // Default value for all exotic cases set to bid.params.video.startDelay midroll hence 2. + var startDelay = 2; + if (bid.params.video && bid.params.video.startDelay) { + startDelay = bid.params.video.startDelay + } else if (videoMediaType.startdelay == 0) { + startDelay = 1; + } else if (videoMediaType.startdelay == -1) { + startDelay = 2; + } else if (videoMediaType.startdelay == -2) { + startDelay = 3; + } + // Specific attributes for instream. let playerSize = videoMediaType.playerSize[0]; payload.isVideo = videoMediaType.context === 'instream'; payload.mediaType = VIDEO; payload.videoData = { - videoProtocol: bid.params.video.protocol, + videoProtocol: protocol, playerWidth: playerSize[0], playerHeight: playerSize[1], - adBreak: bid.params.video.startDelay || 1 + adBreak: startDelay }; } else { return {}; @@ -148,7 +163,8 @@ export const spec = { currency: response.currency, netRevenue: response.isNetCpm, ttl: response.ttl, - dspPixels: response.dspPixels + dspPixels: response.dspPixels, + meta: { advertiserDomains: response.adomain ? response.adomain : [] } }; if (bidRequest.mediaType === VIDEO) { @@ -169,6 +185,31 @@ export const spec = { return bidResponses; }, + /** + * Get floors from Prebid Price Floors module + * + * @param {object} bid Bid request object + * @param {string} currency Ad server currency + * @return {number} Floor price + */ + getBidFloor: function (bid, currency) { + if (!utils.isFn(bid.getFloor)) { + return DEFAULT_FLOOR; + } + + const floor = bid.getFloor({ + currency: currency || 'USD', + mediaType: '*', + size: '*' + }); + + if (utils.isPlainObject(floor) && !isNaN(floor.floor)) { + return floor.floor; + } + + return DEFAULT_FLOOR; + }, + /** * User syncs. * diff --git a/test/spec/modules/smartadserverBidAdapter_spec.js b/test/spec/modules/smartadserverBidAdapter_spec.js index 749de43b9af..366cc01c48c 100644 --- a/test/spec/modules/smartadserverBidAdapter_spec.js +++ b/test/spec/modules/smartadserverBidAdapter_spec.js @@ -1,17 +1,6 @@ -import { - expect -} from 'chai'; -import { - spec -} from 'modules/smartadserverBidAdapter.js'; -import { - newBidder -} from 'src/adapters/bidderFactory.js'; -import { - config -} from 'src/config.js'; -import * as utils from 'src/utils.js'; -import { requestBidsHook } from 'modules/consentManagement.js'; +import { expect } from 'chai'; +import { config } from 'src/config.js'; +import { spec } from 'modules/smartadserverBidAdapter.js'; // Default params with optional ones describe('Smart bid adapter tests', function () { @@ -539,6 +528,130 @@ describe('Smart bid adapter tests', function () { expect(request[0]).to.be.empty; expect(request[1]).to.not.be.empty; }); + + describe('Instream videoData meta & params tests', function () { + it('Verify videoData assigns values from meta', function () { + config.setConfig({ + 'currency': { + 'adServerCurrency': 'EUR' + } + }); + const request = spec.buildRequests([{ + adUnitCode: 'sas_42', + bidId: 'abcd1234', + bidder: 'smartadserver', + mediaTypes: { + video: { + context: 'instream', + playerSize: [[640, 480]], // It seems prebid.js transforms the player size array into an array of array... + protocols: [8, 2], + startdelay: 0 + } + }, + params: { + siteId: '1234', + pageId: '5678', + formatId: '90', + target: 'test=prebid', + bidfloor: 0.420, + buId: '7569', + appName: 'Mozilla', + ckId: 42, + }, + requestId: 'efgh5678', + transactionId: 'zsfgzzg' + }]); + + expect(request[0]).to.have.property('url').and.to.equal('https://prg.smartadserver.com/prebid/v1'); + expect(request[0]).to.have.property('method').and.to.equal('POST'); + const requestContent = JSON.parse(request[0].data); + expect(requestContent).to.have.property('videoData'); + expect(requestContent.videoData).to.have.property('videoProtocol').and.to.equal(8); + expect(requestContent.videoData).to.have.property('adBreak').and.to.equal(1); + }); + + it('Verify videoData default values assigned', function () { + config.setConfig({ + 'currency': { + 'adServerCurrency': 'EUR' + } + }); + const request = spec.buildRequests([{ + adUnitCode: 'sas_42', + bidId: 'abcd1234', + bidder: 'smartadserver', + mediaTypes: { + video: { + context: 'instream', + playerSize: [[640, 480]] // It seems prebid.js transforms the player size array into an array of array... + } + }, + params: { + siteId: '1234', + pageId: '5678', + formatId: '90', + target: 'test=prebid', + bidfloor: 0.420, + buId: '7569', + appName: 'Mozilla', + ckId: 42, + }, + requestId: 'efgh5678', + transactionId: 'zsfgzzg' + }]); + + expect(request[0]).to.have.property('url').and.to.equal('https://prg.smartadserver.com/prebid/v1'); + expect(request[0]).to.have.property('method').and.to.equal('POST'); + const requestContent = JSON.parse(request[0].data); + expect(requestContent).to.have.property('videoData'); + expect(requestContent.videoData).to.have.property('videoProtocol').and.to.equal(null); + expect(requestContent.videoData).to.have.property('adBreak').and.to.equal(2); + }); + + it('Verify videoData params override meta values', function () { + config.setConfig({ + 'currency': { + 'adServerCurrency': 'EUR' + } + }); + const request = spec.buildRequests([{ + adUnitCode: 'sas_42', + bidId: 'abcd1234', + bidder: 'smartadserver', + mediaTypes: { + video: { + context: 'instream', + playerSize: [[640, 480]], // It seems prebid.js transforms the player size array into an array of array... + protocols: [8, 2], + startdelay: 0 + } + }, + params: { + siteId: '1234', + pageId: '5678', + formatId: '90', + target: 'test=prebid', + bidfloor: 0.420, + buId: '7569', + appName: 'Mozilla', + ckId: 42, + video: { + protocol: 6, + startDelay: 3 + } + }, + requestId: 'efgh5678', + transactionId: 'zsfgzzg' + }]); + + expect(request[0]).to.have.property('url').and.to.equal('https://prg.smartadserver.com/prebid/v1'); + expect(request[0]).to.have.property('method').and.to.equal('POST'); + const requestContent = JSON.parse(request[0].data); + expect(requestContent).to.have.property('videoData'); + expect(requestContent.videoData).to.have.property('videoProtocol').and.to.equal(6); + expect(requestContent.videoData).to.have.property('adBreak').and.to.equal(3); + }); + }); }); describe('Outstream video tests', function () { @@ -644,6 +757,130 @@ describe('Smart bid adapter tests', function () { }); }); + describe('Outstream videoData meta & params tests', function () { + it('Verify videoData assigns values from meta', function () { + config.setConfig({ + 'currency': { + 'adServerCurrency': 'EUR' + } + }); + const request = spec.buildRequests([{ + adUnitCode: 'sas_42', + bidId: 'abcd1234', + bidder: 'smartadserver', + mediaTypes: { + video: { + context: 'outstream', + playerSize: [[640, 480]], // It seems prebid.js transforms the player size array into an array of array... + protocols: [8, 2], + startdelay: 0 + } + }, + params: { + siteId: '1234', + pageId: '5678', + formatId: '90', + target: 'test=prebid-outstream', + bidfloor: 0.420, + buId: '7569', + appName: 'Mozilla', + ckId: 42, + }, + requestId: 'efgh5678', + transactionId: 'zsfgzzg' + }]); + + expect(request[0]).to.have.property('url').and.to.equal('https://prg.smartadserver.com/prebid/v1'); + expect(request[0]).to.have.property('method').and.to.equal('POST'); + const requestContent = JSON.parse(request[0].data); + expect(requestContent).to.have.property('videoData'); + expect(requestContent.videoData).to.have.property('videoProtocol').and.to.equal(8); + expect(requestContent.videoData).to.have.property('adBreak').and.to.equal(1); + }); + + it('Verify videoData default values assigned', function () { + config.setConfig({ + 'currency': { + 'adServerCurrency': 'EUR' + } + }); + const request = spec.buildRequests([{ + adUnitCode: 'sas_42', + bidId: 'abcd1234', + bidder: 'smartadserver', + mediaTypes: { + video: { + context: 'outstream', + playerSize: [[640, 480]] // It seems prebid.js transforms the player size array into an array of array... + } + }, + params: { + siteId: '1234', + pageId: '5678', + formatId: '90', + target: 'test=prebid-outstream', + bidfloor: 0.420, + buId: '7569', + appName: 'Mozilla', + ckId: 42, + }, + requestId: 'efgh5678', + transactionId: 'zsfgzzg' + }]); + + expect(request[0]).to.have.property('url').and.to.equal('https://prg.smartadserver.com/prebid/v1'); + expect(request[0]).to.have.property('method').and.to.equal('POST'); + const requestContent = JSON.parse(request[0].data); + expect(requestContent).to.have.property('videoData'); + expect(requestContent.videoData).to.have.property('videoProtocol').and.to.equal(null); + expect(requestContent.videoData).to.have.property('adBreak').and.to.equal(2); + }); + + it('Verify videoData params override meta values', function () { + config.setConfig({ + 'currency': { + 'adServerCurrency': 'EUR' + } + }); + const request = spec.buildRequests([{ + adUnitCode: 'sas_42', + bidId: 'abcd1234', + bidder: 'smartadserver', + mediaTypes: { + video: { + context: 'outstream', + playerSize: [[640, 480]], // It seems prebid.js transforms the player size array into an array of array... + protocols: [8, 2], + startdelay: 0 + } + }, + params: { + siteId: '1234', + pageId: '5678', + formatId: '90', + target: 'test=prebid-outstream', + bidfloor: 0.420, + buId: '7569', + appName: 'Mozilla', + ckId: 42, + video: { + protocol: 6, + startDelay: 3 + } + }, + requestId: 'efgh5678', + transactionId: 'zsfgzzg' + }]); + + expect(request[0]).to.have.property('url').and.to.equal('https://prg.smartadserver.com/prebid/v1'); + expect(request[0]).to.have.property('method').and.to.equal('POST'); + const requestContent = JSON.parse(request[0].data); + expect(requestContent).to.have.property('videoData'); + expect(requestContent.videoData).to.have.property('videoProtocol').and.to.equal(6); + expect(requestContent.videoData).to.have.property('adBreak').and.to.equal(3); + }); + }); + describe('External ids tests', function () { it('Verify external ids in request and ids found', function () { config.setConfig({ @@ -715,4 +952,39 @@ describe('Smart bid adapter tests', function () { expect(null, actual); }); }); + + describe('Floors module', function () { + it('should include floor from bid params', function() { + const bidRequest = JSON.parse((spec.buildRequests(DEFAULT_PARAMS))[0].data); + expect(bidRequest.bidfloor).to.deep.equal(DEFAULT_PARAMS[0].params.bidfloor); + }); + + it('should return floor from module', function() { + const moduleFloor = 1.5; + const bidRequest = JSON.parse((spec.buildRequests(DEFAULT_PARAMS_WO_OPTIONAL))[0].data); + bidRequest.getFloor = function () { + return { floor: moduleFloor }; + }; + + const floor = spec.getBidFloor(bidRequest, 'EUR'); + expect(floor).to.deep.equal(moduleFloor); + }); + + it('should return default floor when module not activated', function() { + const bidRequest = JSON.parse((spec.buildRequests(DEFAULT_PARAMS_WO_OPTIONAL))[0].data); + + const floor = spec.getBidFloor(bidRequest, 'EUR'); + expect(floor).to.deep.equal(0); + }); + + it('should return default floor when getFloor returns not proper object', function() { + const bidRequest = JSON.parse((spec.buildRequests(DEFAULT_PARAMS_WO_OPTIONAL))[0].data); + bidRequest.getFloor = function () { + return { floor: 'one' }; + }; + + const floor = spec.getBidFloor(bidRequest, 'EUR'); + expect(floor).to.deep.equal(0.0); + }); + }); }); From b5d4de3a3dec355f65be3d0c41edb3dc0bc64d43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Sok=C3=B3=C5=82?= Date: Wed, 28 Jul 2021 11:17:51 +0200 Subject: [PATCH 2/3] SADR-2305 Add unit test for unknown currency --- test/spec/modules/smartadserverBidAdapter_spec.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/spec/modules/smartadserverBidAdapter_spec.js b/test/spec/modules/smartadserverBidAdapter_spec.js index 366cc01c48c..d3916a91e71 100644 --- a/test/spec/modules/smartadserverBidAdapter_spec.js +++ b/test/spec/modules/smartadserverBidAdapter_spec.js @@ -986,5 +986,12 @@ describe('Smart bid adapter tests', function () { const floor = spec.getBidFloor(bidRequest, 'EUR'); expect(floor).to.deep.equal(0.0); }); + + it('should return default floor when currency unknown', function() { + const bidRequest = JSON.parse((spec.buildRequests(DEFAULT_PARAMS_WO_OPTIONAL))[0].data); + + const floor = spec.getBidFloor(bidRequest, null); + expect(floor).to.deep.equal(0); + }); }); }); From b7eeacce101ae3a6e817014f007135016fc7659e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Sok=C3=B3=C5=82?= Date: Wed, 4 Aug 2021 13:18:10 +0200 Subject: [PATCH 3/3] lint fix --- test/spec/modules/smartadserverBidAdapter_spec.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/spec/modules/smartadserverBidAdapter_spec.js b/test/spec/modules/smartadserverBidAdapter_spec.js index 282d15b203f..727a7d7c1d6 100644 --- a/test/spec/modules/smartadserverBidAdapter_spec.js +++ b/test/spec/modules/smartadserverBidAdapter_spec.js @@ -1085,6 +1085,5 @@ describe('Smart bid adapter tests', function () { expect(bannerRequest).to.have.property('pageid').and.to.equal('5678'); expect(bannerRequest).to.have.property('formatid').and.to.equal('90'); }); - }); });