Skip to content

Commit

Permalink
AppNexus bid adapter: add price floor module support (prebid#6653)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsnellbaker authored and umakajan committed May 6, 2021
1 parent ceb1acb commit 335edb5
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
21 changes: 19 additions & 2 deletions modules/appnexusBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -707,8 +707,9 @@ function bidToTag(bid) {
tag.use_pmt_rule = bid.params.usePaymentRule || false
tag.prebid = true;
tag.disable_psa = true;
if (bid.params.reserve) {
tag.reserve = bid.params.reserve;
let bidFloor = getBidFloor(bid);
if (bidFloor) {
tag.reserve = bidFloor;
}
if (bid.params.position) {
tag.position = { 'above': 1, 'below': 2 }[bid.params.position] || 0;
Expand Down Expand Up @@ -1045,4 +1046,20 @@ function addUserId(eids, id, source, rti) {
return eids;
}

function getBidFloor(bid) {
if (!utils.isFn(bid.getFloor)) {
return (bid.params.reserve) ? bid.params.reserve : null;
}

let floor = bid.getFloor({
currency: 'USD',
mediaType: '*',
size: '*'
});
if (utils.isPlainObject(floor) && !isNaN(floor.floor) && floor.currency === 'USD') {
return floor.floor;
}
return null;
}

registerBidder(spec);
30 changes: 30 additions & 0 deletions test/spec/modules/appnexusBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,36 @@ describe('AppNexusAdapter', function () {
});
});

it('should attach reserve param when either bid param or getFloor function exists', function () {
let getFloorResponse = { currency: 'USD', floor: 3 };
let request, payload = null;
let bidRequest = deepClone(bidRequests[0]);

// 1 -> reserve not defined, getFloor not defined > empty
request = spec.buildRequests([bidRequest]);
payload = JSON.parse(request.data);

expect(payload.tags[0].reserve).to.not.exist;

// 2 -> reserve is defined, getFloor not defined > reserve is used
bidRequest.params = {
'placementId': '10433394',
'reserve': 0.5
};
request = spec.buildRequests([bidRequest]);
payload = JSON.parse(request.data);

expect(payload.tags[0].reserve).to.exist.and.to.equal(0.5);

// 3 -> reserve is defined, getFloor is defined > getFloor is used
bidRequest.getFloor = () => getFloorResponse;

request = spec.buildRequests([bidRequest]);
payload = JSON.parse(request.data);

expect(payload.tags[0].reserve).to.exist.and.to.equal(3);
});

it('should duplicate adpod placements into batches and set correct maxduration', function() {
let bidRequest = Object.assign({},
bidRequests[0],
Expand Down

0 comments on commit 335edb5

Please sign in to comment.