Skip to content

Commit 749e3c4

Browse files
jsnellbakermkendall07
authored andcommitted
fix issue #2315 sizeMapping not working with s2s requests (#2332)
* initial commit to fix issue #2315 * moved transformHeightWidth function to prebidServerBidAdapter
1 parent a6b42d4 commit 749e3c4

File tree

3 files changed

+29
-33
lines changed

3 files changed

+29
-33
lines changed

modules/prebidServerBidAdapter.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,20 @@ function _appendSiteAppDevice(request) {
266266
}
267267
}
268268

269+
function transformHeightWidth(adUnit) {
270+
let sizesObj = [];
271+
let sizes = utils.parseSizesInput(adUnit.sizes);
272+
sizes.forEach(size => {
273+
let heightWidth = size.split('x');
274+
let sizeObj = {
275+
'w': parseInt(heightWidth[0]),
276+
'h': parseInt(heightWidth[1])
277+
};
278+
sizesObj.push(sizeObj);
279+
});
280+
return sizesObj;
281+
}
282+
269283
/*
270284
* Protocol spec for legacy endpoint
271285
* e.g., https://<prebid-server-url>/v1/auction
@@ -275,6 +289,7 @@ const LEGACY_PROTOCOL = {
275289
buildRequest(s2sBidRequest, adUnits) {
276290
// pbs expects an ad_unit.video attribute if the imp is video
277291
adUnits.forEach(adUnit => {
292+
adUnit.sizes = transformHeightWidth(adUnit);
278293
const videoMediaType = utils.deepAccess(adUnit, 'mediaTypes.video');
279294
if (videoMediaType) {
280295
adUnit.video = Object.assign({}, videoMediaType);

src/adaptermanager.js

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -94,27 +94,11 @@ function getBids({bidderCode, auctionId, bidderRequestId, adUnits, labels}) {
9494
}, []).reduce(flatten, []).filter(val => val !== '');
9595
}
9696

97-
function transformHeightWidth(adUnit) {
98-
let sizesObj = [];
99-
let sizes = utils.parseSizesInput(adUnit.sizes);
100-
sizes.forEach(size => {
101-
let heightWidth = size.split('x');
102-
let sizeObj = {
103-
'w': parseInt(heightWidth[0]),
104-
'h': parseInt(heightWidth[1])
105-
};
106-
sizesObj.push(sizeObj);
107-
});
108-
return sizesObj;
109-
}
110-
11197
function getAdUnitCopyForPrebidServer(adUnits) {
11298
let adaptersServerSide = _s2sConfig.bidders;
11399
let adUnitsCopy = utils.deepClone(adUnits);
114100

115101
adUnitsCopy.forEach((adUnit) => {
116-
adUnit.sizes = transformHeightWidth(adUnit);
117-
118102
// filter out client side bids
119103
adUnit.bids = adUnit.bids.filter((bid) => {
120104
return includes(adaptersServerSide, bid.bidder) && (!doingS2STesting() || bid.finalSource !== s2sTestingModule.CLIENT);
@@ -290,6 +274,17 @@ exports.callBids = (adUnits, bidRequests, addBidResponse, doneCb) => {
290274
const s2sAdapter = _bidderRegistry[_s2sConfig.adapter];
291275
let tid = serverBidRequests[0].tid;
292276
let adUnitsS2SCopy = serverBidRequests[0].adUnitsS2SCopy;
277+
adUnitsS2SCopy.forEach((adUnitCopy) => {
278+
let validBids = adUnitCopy.bids.filter((bid) => {
279+
return serverBidRequests.find(request => {
280+
return request.bidderCode === bid.bidder &&
281+
request.bids.find((reqBid) => reqBid.adUnitCode === adUnitCopy.code);
282+
});
283+
});
284+
adUnitCopy.bids = validBids;
285+
});
286+
287+
adUnitsS2SCopy = adUnitsS2SCopy.filter(adUnitCopy => adUnitCopy.bids.length > 0);
293288

294289
if (s2sAdapter) {
295290
let s2sBidRequest = {tid, 'ad_units': adUnitsS2SCopy};

test/spec/modules/prebidServerBidAdapter_spec.js

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,7 @@ const REQUEST = {
2727
'ad_units': [
2828
{
2929
'code': 'div-gpt-ad-1460505748561-0',
30-
'sizes': [
31-
{
32-
'w': 300,
33-
'h': 250
34-
},
35-
{
36-
'w': 300,
37-
'h': 600
38-
}
39-
],
30+
'sizes': [[300, 250], [300, 600]],
4031
'mediaTypes': {
4132
'banner': {
4233
'sizes': [[ 300, 250 ], [ 300, 300 ]]
@@ -68,7 +59,7 @@ const VIDEO_REQUEST = {
6859
'ad_units': [
6960
{
7061
'code': 'div-gpt-ad-1460505748561-0',
71-
'sizes': [{ 'w': 640, 'h': 480 }],
62+
'sizes': [640, 480],
7263
'mediaTypes': {
7364
'video': {
7465
'playerSize': [[ 640, 480 ]],
@@ -103,12 +94,7 @@ const BID_REQUESTS = [
10394
'bid_id': '123',
10495
'adUnitCode': 'div-gpt-ad-1460505748561-0',
10596
'transactionId': '4ef956ad-fd83-406d-bd35-e4bb786ab86c',
106-
'sizes': [
107-
{
108-
'w': 300,
109-
'h': 250
110-
}
111-
],
97+
'sizes': [300, 250],
11298
'bidId': '259fb43aaa06c1',
11399
'bidderRequestId': '3d1063078dfcc8',
114100
'auctionId': '173afb6d132ba3'

0 commit comments

Comments
 (0)