Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue #2315 sizeMapping not working with s2s requests #2332

Merged
merged 2 commits into from
Apr 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions modules/prebidServerBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,20 @@ function _appendSiteAppDevice(request) {
}
}

function transformHeightWidth(adUnit) {
let sizesObj = [];
let sizes = utils.parseSizesInput(adUnit.sizes);
sizes.forEach(size => {
let heightWidth = size.split('x');
let sizeObj = {
'w': parseInt(heightWidth[0]),
'h': parseInt(heightWidth[1])
};
sizesObj.push(sizeObj);
});
return sizesObj;
}

/*
* Protocol spec for legacy endpoint
* e.g., https://<prebid-server-url>/v1/auction
Expand All @@ -275,6 +289,7 @@ const LEGACY_PROTOCOL = {
buildRequest(s2sBidRequest, adUnits) {
// pbs expects an ad_unit.video attribute if the imp is video
adUnits.forEach(adUnit => {
adUnit.sizes = transformHeightWidth(adUnit);
const videoMediaType = utils.deepAccess(adUnit, 'mediaTypes.video');
if (videoMediaType) {
adUnit.video = Object.assign({}, videoMediaType);
Expand Down
27 changes: 11 additions & 16 deletions src/adaptermanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,27 +94,11 @@ function getBids({bidderCode, auctionId, bidderRequestId, adUnits, labels}) {
}, []).reduce(flatten, []).filter(val => val !== '');
}

function transformHeightWidth(adUnit) {
let sizesObj = [];
let sizes = utils.parseSizesInput(adUnit.sizes);
sizes.forEach(size => {
let heightWidth = size.split('x');
let sizeObj = {
'w': parseInt(heightWidth[0]),
'h': parseInt(heightWidth[1])
};
sizesObj.push(sizeObj);
});
return sizesObj;
}

function getAdUnitCopyForPrebidServer(adUnits) {
let adaptersServerSide = _s2sConfig.bidders;
let adUnitsCopy = utils.deepClone(adUnits);

adUnitsCopy.forEach((adUnit) => {
adUnit.sizes = transformHeightWidth(adUnit);

// filter out client side bids
adUnit.bids = adUnit.bids.filter((bid) => {
return includes(adaptersServerSide, bid.bidder) && (!doingS2STesting() || bid.finalSource !== s2sTestingModule.CLIENT);
Expand Down Expand Up @@ -281,6 +265,17 @@ exports.callBids = (adUnits, bidRequests, addBidResponse, doneCb) => {
const s2sAdapter = _bidderRegistry[_s2sConfig.adapter];
let tid = serverBidRequests[0].tid;
let adUnitsS2SCopy = serverBidRequests[0].adUnitsS2SCopy;
adUnitsS2SCopy.forEach((adUnitCopy) => {
let validBids = adUnitCopy.bids.filter((bid) => {
return serverBidRequests.find(request => {
return request.bidderCode === bid.bidder &&
request.bids.find((reqBid) => reqBid.adUnitCode === adUnitCopy.code);
});
});
adUnitCopy.bids = validBids;
});

adUnitsS2SCopy = adUnitsS2SCopy.filter(adUnitCopy => adUnitCopy.bids.length > 0);

if (s2sAdapter) {
let s2sBidRequest = {tid, 'ad_units': adUnitsS2SCopy};
Expand Down
20 changes: 3 additions & 17 deletions test/spec/modules/prebidServerBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,7 @@ const REQUEST = {
'ad_units': [
{
'code': 'div-gpt-ad-1460505748561-0',
'sizes': [
{
'w': 300,
'h': 250
},
{
'w': 300,
'h': 600
}
],
'sizes': [[300, 250], [300, 600]],
'mediaTypes': {
'banner': {
'sizes': [[ 300, 250 ], [ 300, 300 ]]
Expand Down Expand Up @@ -68,7 +59,7 @@ const VIDEO_REQUEST = {
'ad_units': [
{
'code': 'div-gpt-ad-1460505748561-0',
'sizes': [{ 'w': 640, 'h': 480 }],
'sizes': [640, 480],
'mediaTypes': {
'video': {
'playerSize': [[ 640, 480 ]],
Expand Down Expand Up @@ -103,12 +94,7 @@ const BID_REQUESTS = [
'bid_id': '123',
'adUnitCode': 'div-gpt-ad-1460505748561-0',
'transactionId': '4ef956ad-fd83-406d-bd35-e4bb786ab86c',
'sizes': [
{
'w': 300,
'h': 250
}
],
'sizes': [300, 250],
'bidId': '259fb43aaa06c1',
'bidderRequestId': '3d1063078dfcc8',
'auctionId': '173afb6d132ba3'
Expand Down