Skip to content

Commit

Permalink
OpenX Adapter: Support out of order bids.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimmy Tu committed Apr 24, 2018
1 parent d94404c commit 336eba9
Show file tree
Hide file tree
Showing 2 changed files with 456 additions and 131 deletions.
38 changes: 3 additions & 35 deletions modules/openxBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,10 @@ function createBannerBidResponses(oxResponseObj, {bids, startTime}) {
}
for (let i = 0; i < adUnits.length; i++) {
let adUnit = adUnits[i];
let adUnitIdx = parseInt(adUnit.idx, 10);
let bidResponse = {};
if (adUnits.length === bids.length) {
// request and response length match, directly assign the request id based on positioning
bidResponse.requestId = bids[i].bidId;
} else {
for (let j = i; j < bids.length; j++) {
let bid = bids[j];
if (String(bid.params.unit) === String(adUnit.adunitid) && adUnitHasValidSizeFromBid(adUnit, bid) && !bid.matched) {
// ad unit and size match, this is the correct bid response to bid
bidResponse.requestId = bid.bidId;
bid.matched = true;
break;
}
}
}

bidResponse.requestId = bids[adUnitIdx].bidId;

if (adUnit.pub_rev) {
bidResponse.cpm = Number(adUnit.pub_rev) / 1000;
Expand Down Expand Up @@ -134,27 +123,6 @@ function buildQueryStringFromParams(params) {
.join('&');
}

function adUnitHasValidSizeFromBid(adUnit, bid) {
let sizes = utils.parseSizesInput(bid.sizes);
if (!sizes) {
return false;
}
let found = false;
let creative = adUnit.creative && adUnit.creative[0];
let creative_size = String(creative.width) + 'x' + String(creative.height);

if (utils.isArray(sizes)) {
for (let i = 0; i < sizes.length; i++) {
let size = sizes[i];
if (String(size) === String(creative_size)) {
found = true;
break;
}
}
}
return found;
}

function getViewportDimensions(isIfr) {
let width;
let height;
Expand Down
Loading

0 comments on commit 336eba9

Please sign in to comment.