From ba241b8dfe9bfe9af6e76bdac11a9c5b226e495a Mon Sep 17 00:00:00 2001 From: msmeza Date: Thu, 9 Feb 2023 13:09:22 +0100 Subject: [PATCH 1/6] Added support for the Price Floors Module --- modules/livewrappedBidAdapter.js | 34 ++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/modules/livewrappedBidAdapter.js b/modules/livewrappedBidAdapter.js index 3839eb80b91..26ea6eeebf1 100644 --- a/modules/livewrappedBidAdapter.js +++ b/modules/livewrappedBidAdapter.js @@ -1,4 +1,4 @@ -import {deepAccess, getWindowTop, isSafariBrowser, mergeDeep} from '../src/utils.js'; +import {deepAccess, getWindowTop, isSafariBrowser, mergeDeep, isFn, isPlainObject} from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {config} from '../src/config.js'; import {find} from '../src/polyfill.js'; @@ -63,12 +63,14 @@ export const spec = { const bundle = find(bidRequests, hasBundleParam); const tid = find(bidRequests, hasTidParam); const schain = bidRequests[0].schain; + let flrCur = find(bidRequests, hasFlrCur); let ortb2 = bidderRequest.ortb2; const eids = handleEids(bidRequests); bidUrl = bidUrl ? bidUrl.params.bidUrl : URL; url = url ? url.params.url : (getAppDomain() || getTopWindowLocation(bidderRequest)); test = test ? test.params.test : undefined; - var adRequests = bidRequests.map(bidToAdRequest); + flrCur = flrCur && flrCur.params.flrCur ? flrCur.params.flrCur : undefined; + var adRequests = bidRequests.map(b => bidToAdRequest(b, flrCur)); if (eids) { ortb2 = mergeDeep(mergeDeep({}, ortb2 || {}), eids); @@ -96,7 +98,8 @@ export const spec = { rcv: getAdblockerRecovered(), adRequests: [...adRequests], rtbData: ortb2, - schain: schain + schain: schain, + flrCur: flrCur }; if (config.getConfig().debug) { @@ -223,13 +226,18 @@ function hasPubcid(bid) { return !!bid.crumbs && !!bid.crumbs.pubcid; } -function bidToAdRequest(bid) { +function hasFlrCur(bid) { + return !!bid.params.flrCur; +} + +function bidToAdRequest(bid, currency) { var adRequest = { adUnitId: bid.params.adUnitId, callerAdUnitId: bid.params.adUnitName || bid.adUnitCode || bid.placementCode, bidId: bid.bidId, transactionId: bid.transactionId, formats: getSizes(bid).map(sizeToFormat), + flr: getBidFloor(bid, currency), options: bid.params.options }; @@ -264,6 +272,24 @@ function sizeToFormat(size) { } } +function getBidFloor(bid, currency) { + if (!isFn(bid.getFloor) || !currency) { + return bid.params.flr + ? bid.params.flr + : undefined; + } + + const floor = bid.getFloor({ + currency: currency, + mediaType: '*', + size: '*' + }); + + return isPlainObject(floor) && !isNaN(floor.floor) && floor.currency == currency + ? floor.floor + : undefined; +} + function getAdblockerRecovered() { try { return getWindowTop().I12C && getWindowTop().I12C.Morph === 1; From a235f25d6fefc278e83dd1bafc2254d6d2553f91 Mon Sep 17 00:00:00 2001 From: msmeza Date: Thu, 9 Feb 2023 17:07:00 +0100 Subject: [PATCH 2/6] Use the ad server's currency when getting prices from the floors module * Default to USD if the ad server's currency can't be retrieved --- modules/livewrappedBidAdapter.js | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/modules/livewrappedBidAdapter.js b/modules/livewrappedBidAdapter.js index 26ea6eeebf1..437d8e0fbad 100644 --- a/modules/livewrappedBidAdapter.js +++ b/modules/livewrappedBidAdapter.js @@ -63,14 +63,13 @@ export const spec = { const bundle = find(bidRequests, hasBundleParam); const tid = find(bidRequests, hasTidParam); const schain = bidRequests[0].schain; - let flrCur = find(bidRequests, hasFlrCur); let ortb2 = bidderRequest.ortb2; const eids = handleEids(bidRequests); bidUrl = bidUrl ? bidUrl.params.bidUrl : URL; url = url ? url.params.url : (getAppDomain() || getTopWindowLocation(bidderRequest)); test = test ? test.params.test : undefined; - flrCur = flrCur && flrCur.params.flrCur ? flrCur.params.flrCur : undefined; - var adRequests = bidRequests.map(b => bidToAdRequest(b, flrCur)); + const currency = config.getConfig('currency.adServerCurrency'); + var adRequests = bidRequests.map(b => bidToAdRequest(b, currency)); if (eids) { ortb2 = mergeDeep(mergeDeep({}, ortb2 || {}), eids); @@ -99,7 +98,7 @@ export const spec = { adRequests: [...adRequests], rtbData: ortb2, schain: schain, - flrCur: flrCur + flrCur: currency }; if (config.getConfig().debug) { @@ -226,10 +225,6 @@ function hasPubcid(bid) { return !!bid.crumbs && !!bid.crumbs.pubcid; } -function hasFlrCur(bid) { - return !!bid.params.flrCur; -} - function bidToAdRequest(bid, currency) { var adRequest = { adUnitId: bid.params.adUnitId, @@ -273,14 +268,12 @@ function sizeToFormat(size) { } function getBidFloor(bid, currency) { - if (!isFn(bid.getFloor) || !currency) { - return bid.params.flr - ? bid.params.flr - : undefined; + if (!isFn(bid.getFloor)) { + return undefined; } const floor = bid.getFloor({ - currency: currency, + currency: currency || 'USD', mediaType: '*', size: '*' }); From 67d6a2e46f044909505a87384af515827e195ba9 Mon Sep 17 00:00:00 2001 From: msmeza Date: Thu, 9 Feb 2023 18:15:24 +0100 Subject: [PATCH 3/6] Set the default currency at the right place --- modules/livewrappedBidAdapter.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/livewrappedBidAdapter.js b/modules/livewrappedBidAdapter.js index 437d8e0fbad..b5e9c29f421 100644 --- a/modules/livewrappedBidAdapter.js +++ b/modules/livewrappedBidAdapter.js @@ -68,7 +68,7 @@ export const spec = { bidUrl = bidUrl ? bidUrl.params.bidUrl : URL; url = url ? url.params.url : (getAppDomain() || getTopWindowLocation(bidderRequest)); test = test ? test.params.test : undefined; - const currency = config.getConfig('currency.adServerCurrency'); + const currency = config.getConfig('currency.adServerCurrency') || 'USD'; var adRequests = bidRequests.map(b => bidToAdRequest(b, currency)); if (eids) { @@ -273,7 +273,7 @@ function getBidFloor(bid, currency) { } const floor = bid.getFloor({ - currency: currency || 'USD', + currency: currency, mediaType: '*', size: '*' }); From b8691f55160d532db4cb61cabfd69ab772379c62 Mon Sep 17 00:00:00 2001 From: msmeza Date: Tue, 14 Feb 2023 11:34:27 +0100 Subject: [PATCH 4/6] Added tests and made a minor change in how device width and height are calculated --- modules/livewrappedBidAdapter.js | 22 +- .../modules/livewrappedBidAdapter_spec.js | 292 +++++++++++++++++- 2 files changed, 297 insertions(+), 17 deletions(-) diff --git a/modules/livewrappedBidAdapter.js b/modules/livewrappedBidAdapter.js index b5e9c29f421..f42815b12e9 100644 --- a/modules/livewrappedBidAdapter.js +++ b/modules/livewrappedBidAdapter.js @@ -68,7 +68,7 @@ export const spec = { bidUrl = bidUrl ? bidUrl.params.bidUrl : URL; url = url ? url.params.url : (getAppDomain() || getTopWindowLocation(bidderRequest)); test = test ? test.params.test : undefined; - const currency = config.getConfig('currency.adServerCurrency') || 'USD'; + const currency = config.getConfig('currency.adServerCurrency') || 'USD'; var adRequests = bidRequests.map(b => bidToAdRequest(b, currency)); if (eids) { @@ -232,7 +232,7 @@ function bidToAdRequest(bid, currency) { bidId: bid.bidId, transactionId: bid.transactionId, formats: getSizes(bid).map(sizeToFormat), - flr: getBidFloor(bid, currency), + flr: getBidFloor(bid, currency), options: bid.params.options }; @@ -280,7 +280,7 @@ function getBidFloor(bid, currency) { return isPlainObject(floor) && !isNaN(floor.floor) && floor.currency == currency ? floor.floor - : undefined; + : undefined; } function getAdblockerRecovered() { @@ -321,21 +321,13 @@ function getDeviceIfa() { } function getDeviceWidth() { - let device = config.getConfig('device'); - if (typeof device === 'object' && device.width) { - return device.width; - } - - return window.innerWidth; + const device = config.getConfig('device') || {}; + return device.w || window.innerWidth; } function getDeviceHeight() { - let device = config.getConfig('device'); - if (typeof device === 'object' && device.height) { - return device.height; - } - - return window.innerHeight; + const device = config.getConfig('device') || {}; + return device.h || window.innerHeight; } function getCoppa() { diff --git a/test/spec/modules/livewrappedBidAdapter_spec.js b/test/spec/modules/livewrappedBidAdapter_spec.js index a4fee5e3b26..211bd51a0d1 100644 --- a/test/spec/modules/livewrappedBidAdapter_spec.js +++ b/test/spec/modules/livewrappedBidAdapter_spec.js @@ -13,6 +13,10 @@ describe('Livewrapped adapter tests', function () { window.livewrapped = undefined; + config.setConfig({ + device: { w: 100, h: 100 } + }); + bidderRequest = { bidderCode: 'livewrapped', auctionId: 'c45dd708-a418-42ec-b8a7-b70a6c6fab0a', @@ -43,6 +47,7 @@ describe('Livewrapped adapter tests', function () { afterEach(function () { sandbox.restore(); + config.resetConfig(); }); describe('isBidRequestValid', function() { @@ -106,6 +111,7 @@ describe('Livewrapped adapter tests', function () { width: 100, height: 100, cookieSupport: true, + flrCur: 'USD', adRequests: [{ adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', callerAdUnitId: 'panorama_d_1', @@ -143,6 +149,7 @@ describe('Livewrapped adapter tests', function () { width: 100, height: 100, cookieSupport: true, + flrCur: 'USD', adRequests: [{ adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', callerAdUnitId: 'panorama_d_1', @@ -181,6 +188,7 @@ describe('Livewrapped adapter tests', function () { width: 100, height: 100, cookieSupport: true, + flrCur: 'USD', adRequests: [{ callerAdUnitId: 'caller id 1', bidId: '2ffb201a808da7', @@ -212,6 +220,7 @@ describe('Livewrapped adapter tests', function () { width: 100, height: 100, cookieSupport: true, + flrCur: 'USD', adRequests: [{ callerAdUnitId: 'panorama_d_1', bidId: '2ffb201a808da7', @@ -242,6 +251,7 @@ describe('Livewrapped adapter tests', function () { width: 100, height: 100, cookieSupport: true, + flrCur: 'USD', adRequests: [{ adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', callerAdUnitId: 'panorama_d_1', @@ -276,6 +286,7 @@ describe('Livewrapped adapter tests', function () { deviceId: 'deviceid', ifa: 'ifa', cookieSupport: true, + flrCur: 'USD', adRequests: [{ callerAdUnitId: 'panorama_d_1', bidId: '2ffb201a808da7', @@ -309,6 +320,7 @@ describe('Livewrapped adapter tests', function () { tid: 'tracking id', test: true, cookieSupport: true, + flrCur: 'USD', adRequests: [{ callerAdUnitId: 'panorama_d_1', bidId: '2ffb201a808da7', @@ -339,6 +351,7 @@ describe('Livewrapped adapter tests', function () { width: 100, height: 100, cookieSupport: true, + flrCur: 'USD', adRequests: [{ callerAdUnitId: 'panorama_d_1', bidId: '2ffb201a808da7', @@ -351,7 +364,7 @@ describe('Livewrapped adapter tests', function () { expect(data).to.deep.equal(expectedQuery); }); - it('should make a well-formed single request object with ad blocker revovered parameter', function() { + it('should make a well-formed single request object with ad blocker recovered parameter', function() { sandbox.stub(utils, 'getWindowTop').returns({ I12C: { Morph: 1 } }); sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); sandbox.stub(storage, 'cookiesAreEnabled').callsFake(() => true); @@ -371,6 +384,7 @@ describe('Livewrapped adapter tests', function () { height: 100, cookieSupport: true, rcv: true, + flrCur: 'USD', adRequests: [{ callerAdUnitId: 'panorama_d_1', bidId: '2ffb201a808da7', @@ -401,6 +415,7 @@ describe('Livewrapped adapter tests', function () { width: 100, height: 100, cookieSupport: true, + flrCur: 'USD', adRequests: [{ callerAdUnitId: 'panorama_d_1', bidId: '2ffb201a808da7', @@ -432,6 +447,7 @@ describe('Livewrapped adapter tests', function () { width: 100, height: 100, cookieSupport: true, + flrCur: 'USD', adRequests: [{ callerAdUnitId: 'panorama_d_1', bidId: '2ffb201a808da7', @@ -464,6 +480,7 @@ describe('Livewrapped adapter tests', function () { width: 100, height: 100, cookieSupport: true, + flrCur: 'USD', adRequests: [{ callerAdUnitId: 'panorama_d_1', bidId: '2ffb201a808da7', @@ -489,7 +506,7 @@ describe('Livewrapped adapter tests', function () { return {bundle: 'bundle', domain: 'https://appdomain.com'}; } if (key === 'device') { - return {ifa: 'ifa', width: 300, height: 200}; + return {ifa: 'ifa', w: 300, h: 200}; } return origGetConfig.apply(config, arguments); }); @@ -511,6 +528,7 @@ describe('Livewrapped adapter tests', function () { ifa: 'ifa', bundle: 'bundle', cookieSupport: true, + flrCur: 'USD', adRequests: [{ adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', callerAdUnitId: 'panorama_d_1', @@ -542,6 +560,7 @@ describe('Livewrapped adapter tests', function () { width: 100, height: 100, cookieSupport: true, + flrCur: 'USD', adRequests: [{ callerAdUnitId: 'panorama_d_1', bidId: '2ffb201a808da7', @@ -578,6 +597,7 @@ describe('Livewrapped adapter tests', function () { cookieSupport: true, gdprApplies: true, gdprConsent: 'test', + flrCur: 'USD', adRequests: [{ adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', callerAdUnitId: 'panorama_d_1', @@ -613,6 +633,7 @@ describe('Livewrapped adapter tests', function () { height: 100, cookieSupport: true, gdprApplies: false, + flrCur: 'USD', adRequests: [{ adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', callerAdUnitId: 'panorama_d_1', @@ -646,6 +667,7 @@ describe('Livewrapped adapter tests', function () { height: 100, cookieSupport: true, usPrivacy: '1---', + flrCur: 'USD', adRequests: [{ adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', callerAdUnitId: 'panorama_d_1', @@ -686,6 +708,7 @@ describe('Livewrapped adapter tests', function () { height: 100, cookieSupport: true, coppa: true, + flrCur: 'USD', adRequests: [{ adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', callerAdUnitId: 'panorama_d_1', @@ -716,6 +739,7 @@ describe('Livewrapped adapter tests', function () { width: 100, height: 100, cookieSupport: false, + flrCur: 'USD', adRequests: [{ adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', callerAdUnitId: 'panorama_d_1', @@ -746,6 +770,7 @@ describe('Livewrapped adapter tests', function () { width: 100, height: 100, cookieSupport: false, + flrCur: 'USD', adRequests: [{ adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', callerAdUnitId: 'panorama_d_1', @@ -796,6 +821,7 @@ describe('Livewrapped adapter tests', function () { width: 100, height: 100, cookieSupport: true, + flrCur: 'USD', adRequests: [{ adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', callerAdUnitId: 'panorama_d_1', @@ -828,6 +854,193 @@ describe('Livewrapped adapter tests', function () { width: 100, height: 100, cookieSupport: true, + flrCur: 'USD', + adRequests: [{ + adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}] + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + + it('width and height should default to values from window when not set in config', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(storage, 'cookiesAreEnabled').callsFake(() => true); + + config.resetConfig(); + + let testbidRequest = clone(bidderRequest); + let result = spec.buildRequests(testbidRequest.bids, testbidRequest); + let data = JSON.parse(result.data); + + expect(result.url).to.equal('https://lwadm.com/ad'); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + userId: 'user id', + url: 'https://www.domain.com', + seats: {'dsp': ['seat 1']}, + version: '1.4', + width: window.innerWidth, + height: window.innerHeight, + cookieSupport: true, + flrCur: 'USD', + adRequests: [{ + adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}] + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + + it('should use adServerCurrency', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(storage, 'cookiesAreEnabled').callsFake(() => true); + + let testbidRequest = clone(bidderRequest); + + let origGetConfig = config.getConfig; + sandbox.stub(config, 'getConfig').callsFake(function (key) { + if (key === 'currency.adServerCurrency') { + return 'EUR'; + } + return origGetConfig.apply(config, arguments); + }); + + let result = spec.buildRequests(testbidRequest.bids, testbidRequest); + let data = JSON.parse(result.data); + + expect(result.url).to.equal('https://lwadm.com/ad'); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + userId: 'user id', + url: 'https://www.domain.com', + seats: {'dsp': ['seat 1']}, + version: '1.4', + width: 100, + height: 100, + cookieSupport: true, + flrCur: 'EUR', + adRequests: [{ + adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}] + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + }); + + describe('price floors module', function() { + it('price floors module disabled', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(storage, 'cookiesAreEnabled').callsFake(() => true); + + let testbidRequest = clone(bidderRequest); + let result = spec.buildRequests(testbidRequest.bids, testbidRequest); + let data = JSON.parse(result.data); + + expect(result.url).to.equal('https://lwadm.com/ad'); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + userId: 'user id', + url: 'https://www.domain.com', + seats: {'dsp': ['seat 1']}, + version: '1.4', + width: 100, + height: 100, + cookieSupport: true, + flrCur: 'USD', + adRequests: [{ + adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}] + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + + it('getFloor does not return an object', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(storage, 'cookiesAreEnabled').callsFake(() => true); + + let testbidRequest = clone(bidderRequest); + let bids = testbidRequest.bids.map(b => { + b.getFloor = function () { return undefined; } + return b; + }); + let result = spec.buildRequests(bids, testbidRequest); + let data = JSON.parse(result.data); + + expect(result.url).to.equal('https://lwadm.com/ad'); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + userId: 'user id', + url: 'https://www.domain.com', + seats: {'dsp': ['seat 1']}, + version: '1.4', + width: 100, + height: 100, + cookieSupport: true, + flrCur: 'USD', + adRequests: [{ + adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}] + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + + it('getFloor returns a NaN floor', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(storage, 'cookiesAreEnabled').callsFake(() => true); + + let testbidRequest = clone(bidderRequest); + let bids = testbidRequest.bids.map(b => { + b.getFloor = function () { return { floor: undefined }; } + return b; + }); + let result = spec.buildRequests(bids, testbidRequest); + let data = JSON.parse(result.data); + + expect(result.url).to.equal('https://lwadm.com/ad'); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + userId: 'user id', + url: 'https://www.domain.com', + seats: {'dsp': ['seat 1']}, + version: '1.4', + width: 100, + height: 100, + cookieSupport: true, + flrCur: 'USD', adRequests: [{ adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', callerAdUnitId: 'panorama_d_1', @@ -839,6 +1052,81 @@ describe('Livewrapped adapter tests', function () { expect(data).to.deep.equal(expectedQuery); }); + + it('getFloor returns unexpected currency', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(storage, 'cookiesAreEnabled').callsFake(() => true); + + let testbidRequest = clone(bidderRequest); + let bids = testbidRequest.bids.map(b => { + b.getFloor = function () { return { floor: 10, currency: 'EUR' }; } + return b; + }); + let result = spec.buildRequests(bids, testbidRequest); + let data = JSON.parse(result.data); + + expect(result.url).to.equal('https://lwadm.com/ad'); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + userId: 'user id', + url: 'https://www.domain.com', + seats: {'dsp': ['seat 1']}, + version: '1.4', + width: 100, + height: 100, + cookieSupport: true, + flrCur: 'USD', + adRequests: [{ + adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}] + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + + it('getFloor returns valid floor', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(storage, 'cookiesAreEnabled').callsFake(() => true); + + let testbidRequest = clone(bidderRequest); + let bids = testbidRequest.bids.map(b => { + b.getFloor = function () { return { floor: 10, currency: 'USD' }; } + return b; + }); + let result = spec.buildRequests(bids, testbidRequest); + let data = JSON.parse(result.data); + + expect(result.url).to.equal('https://lwadm.com/ad'); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + userId: 'user id', + url: 'https://www.domain.com', + seats: {'dsp': ['seat 1']}, + version: '1.4', + width: 100, + height: 100, + cookieSupport: true, + flrCur: 'USD', + adRequests: [{ + adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}], + flr: 10 + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); }); it('should make use of user ids if available', function() { From 9d030739e636cc5d78eba0f3a8c5bd5d5dfeabfc Mon Sep 17 00:00:00 2001 From: msmeza Date: Tue, 14 Feb 2023 12:02:19 +0100 Subject: [PATCH 5/6] Only include flrCur when ad requests contain floors --- modules/livewrappedBidAdapter.js | 3 +- .../modules/livewrappedBidAdapter_spec.js | 95 +++++++------------ 2 files changed, 38 insertions(+), 60 deletions(-) diff --git a/modules/livewrappedBidAdapter.js b/modules/livewrappedBidAdapter.js index f42815b12e9..af754ae3ff0 100644 --- a/modules/livewrappedBidAdapter.js +++ b/modules/livewrappedBidAdapter.js @@ -70,6 +70,7 @@ export const spec = { test = test ? test.params.test : undefined; const currency = config.getConfig('currency.adServerCurrency') || 'USD'; var adRequests = bidRequests.map(b => bidToAdRequest(b, currency)); + const adRequestsContainFloors = adRequests.some(r => r.flr !== undefined); if (eids) { ortb2 = mergeDeep(mergeDeep({}, ortb2 || {}), eids); @@ -98,7 +99,7 @@ export const spec = { adRequests: [...adRequests], rtbData: ortb2, schain: schain, - flrCur: currency + flrCur: adRequestsContainFloors ? currency : undefined }; if (config.getConfig().debug) { diff --git a/test/spec/modules/livewrappedBidAdapter_spec.js b/test/spec/modules/livewrappedBidAdapter_spec.js index 211bd51a0d1..6bbdf6e1705 100644 --- a/test/spec/modules/livewrappedBidAdapter_spec.js +++ b/test/spec/modules/livewrappedBidAdapter_spec.js @@ -111,7 +111,6 @@ describe('Livewrapped adapter tests', function () { width: 100, height: 100, cookieSupport: true, - flrCur: 'USD', adRequests: [{ adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', callerAdUnitId: 'panorama_d_1', @@ -149,7 +148,6 @@ describe('Livewrapped adapter tests', function () { width: 100, height: 100, cookieSupport: true, - flrCur: 'USD', adRequests: [{ adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', callerAdUnitId: 'panorama_d_1', @@ -188,7 +186,6 @@ describe('Livewrapped adapter tests', function () { width: 100, height: 100, cookieSupport: true, - flrCur: 'USD', adRequests: [{ callerAdUnitId: 'caller id 1', bidId: '2ffb201a808da7', @@ -220,7 +217,6 @@ describe('Livewrapped adapter tests', function () { width: 100, height: 100, cookieSupport: true, - flrCur: 'USD', adRequests: [{ callerAdUnitId: 'panorama_d_1', bidId: '2ffb201a808da7', @@ -251,7 +247,6 @@ describe('Livewrapped adapter tests', function () { width: 100, height: 100, cookieSupport: true, - flrCur: 'USD', adRequests: [{ adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', callerAdUnitId: 'panorama_d_1', @@ -286,7 +281,6 @@ describe('Livewrapped adapter tests', function () { deviceId: 'deviceid', ifa: 'ifa', cookieSupport: true, - flrCur: 'USD', adRequests: [{ callerAdUnitId: 'panorama_d_1', bidId: '2ffb201a808da7', @@ -320,7 +314,6 @@ describe('Livewrapped adapter tests', function () { tid: 'tracking id', test: true, cookieSupport: true, - flrCur: 'USD', adRequests: [{ callerAdUnitId: 'panorama_d_1', bidId: '2ffb201a808da7', @@ -351,7 +344,6 @@ describe('Livewrapped adapter tests', function () { width: 100, height: 100, cookieSupport: true, - flrCur: 'USD', adRequests: [{ callerAdUnitId: 'panorama_d_1', bidId: '2ffb201a808da7', @@ -384,7 +376,6 @@ describe('Livewrapped adapter tests', function () { height: 100, cookieSupport: true, rcv: true, - flrCur: 'USD', adRequests: [{ callerAdUnitId: 'panorama_d_1', bidId: '2ffb201a808da7', @@ -415,7 +406,6 @@ describe('Livewrapped adapter tests', function () { width: 100, height: 100, cookieSupport: true, - flrCur: 'USD', adRequests: [{ callerAdUnitId: 'panorama_d_1', bidId: '2ffb201a808da7', @@ -447,7 +437,6 @@ describe('Livewrapped adapter tests', function () { width: 100, height: 100, cookieSupport: true, - flrCur: 'USD', adRequests: [{ callerAdUnitId: 'panorama_d_1', bidId: '2ffb201a808da7', @@ -480,7 +469,6 @@ describe('Livewrapped adapter tests', function () { width: 100, height: 100, cookieSupport: true, - flrCur: 'USD', adRequests: [{ callerAdUnitId: 'panorama_d_1', bidId: '2ffb201a808da7', @@ -528,7 +516,6 @@ describe('Livewrapped adapter tests', function () { ifa: 'ifa', bundle: 'bundle', cookieSupport: true, - flrCur: 'USD', adRequests: [{ adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', callerAdUnitId: 'panorama_d_1', @@ -560,7 +547,6 @@ describe('Livewrapped adapter tests', function () { width: 100, height: 100, cookieSupport: true, - flrCur: 'USD', adRequests: [{ callerAdUnitId: 'panorama_d_1', bidId: '2ffb201a808da7', @@ -597,7 +583,6 @@ describe('Livewrapped adapter tests', function () { cookieSupport: true, gdprApplies: true, gdprConsent: 'test', - flrCur: 'USD', adRequests: [{ adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', callerAdUnitId: 'panorama_d_1', @@ -633,7 +618,6 @@ describe('Livewrapped adapter tests', function () { height: 100, cookieSupport: true, gdprApplies: false, - flrCur: 'USD', adRequests: [{ adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', callerAdUnitId: 'panorama_d_1', @@ -667,7 +651,6 @@ describe('Livewrapped adapter tests', function () { height: 100, cookieSupport: true, usPrivacy: '1---', - flrCur: 'USD', adRequests: [{ adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', callerAdUnitId: 'panorama_d_1', @@ -708,7 +691,6 @@ describe('Livewrapped adapter tests', function () { height: 100, cookieSupport: true, coppa: true, - flrCur: 'USD', adRequests: [{ adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', callerAdUnitId: 'panorama_d_1', @@ -739,7 +721,6 @@ describe('Livewrapped adapter tests', function () { width: 100, height: 100, cookieSupport: false, - flrCur: 'USD', adRequests: [{ adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', callerAdUnitId: 'panorama_d_1', @@ -770,7 +751,6 @@ describe('Livewrapped adapter tests', function () { width: 100, height: 100, cookieSupport: false, - flrCur: 'USD', adRequests: [{ adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', callerAdUnitId: 'panorama_d_1', @@ -821,7 +801,6 @@ describe('Livewrapped adapter tests', function () { width: 100, height: 100, cookieSupport: true, - flrCur: 'USD', adRequests: [{ adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', callerAdUnitId: 'panorama_d_1', @@ -854,7 +833,6 @@ describe('Livewrapped adapter tests', function () { width: 100, height: 100, cookieSupport: true, - flrCur: 'USD', adRequests: [{ adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', callerAdUnitId: 'panorama_d_1', @@ -871,7 +849,7 @@ describe('Livewrapped adapter tests', function () { sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); sandbox.stub(storage, 'cookiesAreEnabled').callsFake(() => true); - config.resetConfig(); + config.resetConfig(); let testbidRequest = clone(bidderRequest); let result = spec.buildRequests(testbidRequest.bids, testbidRequest); @@ -889,7 +867,6 @@ describe('Livewrapped adapter tests', function () { width: window.innerWidth, height: window.innerHeight, cookieSupport: true, - flrCur: 'USD', adRequests: [{ adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', callerAdUnitId: 'panorama_d_1', @@ -901,21 +878,14 @@ describe('Livewrapped adapter tests', function () { expect(data).to.deep.equal(expectedQuery); }); + }); - it('should use adServerCurrency', function() { + describe('price floors module', function() { + it('price floors module disabled', function() { sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); sandbox.stub(storage, 'cookiesAreEnabled').callsFake(() => true); let testbidRequest = clone(bidderRequest); - - let origGetConfig = config.getConfig; - sandbox.stub(config, 'getConfig').callsFake(function (key) { - if (key === 'currency.adServerCurrency') { - return 'EUR'; - } - return origGetConfig.apply(config, arguments); - }); - let result = spec.buildRequests(testbidRequest.bids, testbidRequest); let data = JSON.parse(result.data); @@ -931,7 +901,6 @@ describe('Livewrapped adapter tests', function () { width: 100, height: 100, cookieSupport: true, - flrCur: 'EUR', adRequests: [{ adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', callerAdUnitId: 'panorama_d_1', @@ -943,15 +912,17 @@ describe('Livewrapped adapter tests', function () { expect(data).to.deep.equal(expectedQuery); }); - }); - describe('price floors module', function() { - it('price floors module disabled', function() { + it('getFloor does not return an object', function() { sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); sandbox.stub(storage, 'cookiesAreEnabled').callsFake(() => true); let testbidRequest = clone(bidderRequest); - let result = spec.buildRequests(testbidRequest.bids, testbidRequest); + let bids = testbidRequest.bids.map(b => { + b.getFloor = function () { return undefined; } + return b; + }); + let result = spec.buildRequests(bids, testbidRequest); let data = JSON.parse(result.data); expect(result.url).to.equal('https://lwadm.com/ad'); @@ -966,7 +937,6 @@ describe('Livewrapped adapter tests', function () { width: 100, height: 100, cookieSupport: true, - flrCur: 'USD', adRequests: [{ adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', callerAdUnitId: 'panorama_d_1', @@ -979,15 +949,15 @@ describe('Livewrapped adapter tests', function () { expect(data).to.deep.equal(expectedQuery); }); - it('getFloor does not return an object', function() { + it('getFloor returns a NaN floor', function() { sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); sandbox.stub(storage, 'cookiesAreEnabled').callsFake(() => true); let testbidRequest = clone(bidderRequest); - let bids = testbidRequest.bids.map(b => { - b.getFloor = function () { return undefined; } + let bids = testbidRequest.bids.map(b => { + b.getFloor = function () { return { floor: undefined }; } return b; - }); + }); let result = spec.buildRequests(bids, testbidRequest); let data = JSON.parse(result.data); @@ -1003,7 +973,6 @@ describe('Livewrapped adapter tests', function () { width: 100, height: 100, cookieSupport: true, - flrCur: 'USD', adRequests: [{ adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', callerAdUnitId: 'panorama_d_1', @@ -1016,15 +985,15 @@ describe('Livewrapped adapter tests', function () { expect(data).to.deep.equal(expectedQuery); }); - it('getFloor returns a NaN floor', function() { + it('getFloor returns unexpected currency', function() { sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); sandbox.stub(storage, 'cookiesAreEnabled').callsFake(() => true); let testbidRequest = clone(bidderRequest); - let bids = testbidRequest.bids.map(b => { - b.getFloor = function () { return { floor: undefined }; } + let bids = testbidRequest.bids.map(b => { + b.getFloor = function () { return { floor: 10, currency: 'EUR' }; } return b; - }); + }); let result = spec.buildRequests(bids, testbidRequest); let data = JSON.parse(result.data); @@ -1040,7 +1009,6 @@ describe('Livewrapped adapter tests', function () { width: 100, height: 100, cookieSupport: true, - flrCur: 'USD', adRequests: [{ adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', callerAdUnitId: 'panorama_d_1', @@ -1053,15 +1021,23 @@ describe('Livewrapped adapter tests', function () { expect(data).to.deep.equal(expectedQuery); }); - it('getFloor returns unexpected currency', function() { + it('getFloor returns valid floor - ad server currency', function() { sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); sandbox.stub(storage, 'cookiesAreEnabled').callsFake(() => true); + let origGetConfig = config.getConfig; + sandbox.stub(config, 'getConfig').callsFake(function (key) { + if (key === 'currency.adServerCurrency') { + return 'EUR'; + } + return origGetConfig.apply(config, arguments); + }); + let testbidRequest = clone(bidderRequest); - let bids = testbidRequest.bids.map(b => { + let bids = testbidRequest.bids.map(b => { b.getFloor = function () { return { floor: 10, currency: 'EUR' }; } return b; - }); + }); let result = spec.buildRequests(bids, testbidRequest); let data = JSON.parse(result.data); @@ -1077,28 +1053,29 @@ describe('Livewrapped adapter tests', function () { width: 100, height: 100, cookieSupport: true, - flrCur: 'USD', + flrCur: 'EUR', adRequests: [{ adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', callerAdUnitId: 'panorama_d_1', bidId: '2ffb201a808da7', transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', - formats: [{width: 980, height: 240}, {width: 980, height: 120}] + formats: [{width: 980, height: 240}, {width: 980, height: 120}], + flr: 10 }] }; expect(data).to.deep.equal(expectedQuery); }); - it('getFloor returns valid floor', function() { + it('getFloor returns valid floor - default currency', function() { sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); sandbox.stub(storage, 'cookiesAreEnabled').callsFake(() => true); let testbidRequest = clone(bidderRequest); - let bids = testbidRequest.bids.map(b => { + let bids = testbidRequest.bids.map(b => { b.getFloor = function () { return { floor: 10, currency: 'USD' }; } return b; - }); + }); let result = spec.buildRequests(bids, testbidRequest); let data = JSON.parse(result.data); @@ -1121,7 +1098,7 @@ describe('Livewrapped adapter tests', function () { bidId: '2ffb201a808da7', transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', formats: [{width: 980, height: 240}, {width: 980, height: 120}], - flr: 10 + flr: 10 }] }; From 6e83782cb9bc756ebaa437b90138807633faa97e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn?= Date: Thu, 9 Mar 2023 14:01:25 +0100 Subject: [PATCH 6/6] Added 1x2 (524) size to Rubicon adapter --- modules/rubiconBidAdapter.js | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/rubiconBidAdapter.js b/modules/rubiconBidAdapter.js index f93e3f4e5eb..11d60e77ece 100644 --- a/modules/rubiconBidAdapter.js +++ b/modules/rubiconBidAdapter.js @@ -123,6 +123,7 @@ var sizeMap = { 278: '320x500', 282: '320x400', 288: '640x380', + 524: '1x2', 548: '500x1000', 550: '980x480', 552: '300x200',