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

appnexus bid adapter - add price floor module support #6653

Merged
merged 2 commits into from
May 3, 2021
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
21 changes: 19 additions & 2 deletions modules/appnexusBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -703,8 +703,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 @@ -1036,4 +1037,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