Skip to content

Commit

Permalink
handle edge case where all mediaTypes get filtered out and the case w…
Browse files Browse the repository at this point in the history
…hen bidder gets filtered out
  • Loading branch information
Fawke committed Dec 6, 2019
1 parent cbf2a61 commit 60847f0
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions modules/sizeMappingV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ function getFilteredMediaTypes(mediaTypes) {
function isSizeConfigActivated(mediaType, sizeConfig) {
switch (mediaType) {
case 'banner':
return sizeConfig.sizes && sizeConfig.sizes.length > 0;
return sizeConfig.sizes && sizeConfig.sizes[0].length > 0;
case 'video':
return sizeConfig.playerSize && sizeConfig.playerSize.length > 0;
return sizeConfig.playerSize && sizeConfig.playerSize[0].length > 0;
case 'native':
return sizeConfig.active;
default:
Expand Down Expand Up @@ -207,6 +207,13 @@ function getBids({ bidderCode, auctionId, bidderRequestId, adUnits, labels, src
logInfo(`SizeMappingV2:: AdUnit:: ${adUnit.code}, Active size buckets after filtration: `, activeSizeBucket);
logInfo(`SizeMappingV2:: AdUnit:: ${adUnit.code}, Transformed mediaTypes after filtration: `, transformedMediaTypes);
logInfo(`SizeMappingV2:: AdUnit:: ${adUnit.code}, mediaTypes that got filtered out: `, Object.keys(mediaTypes).filter(mt => Object.keys(transformedMediaTypes).indexOf(mt) === -1));

// check if adUnit has any active media types remaining, if not drop the adUnit from auction,
// else proceed to evaluate the bids object.
if (Object.keys(transformedMediaTypes).length === 0) {
logInfo(`SizeMappingV2:: Ad Unit: ${adUnit.code} is disabled since there are no active media types after sizeConfig filtration.`);
return result;
}
result
.push(adUnit.bids.filter(bid => bid.bidder === bidderCode)
.reduce((bids, bid) => {
Expand Down Expand Up @@ -235,10 +242,12 @@ function getBids({ bidderCode, auctionId, bidderRequestId, adUnits, labels, src
if (Object.keys(bidderMediaTypes).length > 0) {
bid = Object.assign({}, bid, bidderMediaTypes);
} else {
return logInfo(`SizeMappingV2:: Bidder: ${bid.bidder} in Ad Unit: ${adUnit.code} is disabled.`);
logInfo(`SizeMappingV2:: Bidder: ${bid.bidder} in Ad Unit: ${adUnit.code} is disabled.`);
return bids;
}
} else {
return logInfo(`SizeMappingV2:: Bidder: ${bid.bidder} in Ad Unit: ${adUnit.code} is disabled due to failing sizeConfig check.`);
logInfo(`SizeMappingV2:: Bidder: ${bid.bidder} in Ad Unit: ${adUnit.code} is disabled due to failing sizeConfig check.`);
return bids;
}
}
bids.push(Object.assign({}, bid, {
Expand Down

0 comments on commit 60847f0

Please sign in to comment.