Skip to content

Commit

Permalink
* add floor prices to the prebid request (prebid#8507)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelErmer authored and renebaudisch committed Jun 28, 2022
1 parent 0a63dbf commit 35d09f4
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
30 changes: 30 additions & 0 deletions modules/aduptechBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,30 @@ export const internal = {
return null;
},

/**
* Extracts the floor price params from given bidRequest
*
* @param {BidRequest} bidRequest
* @returns {undefined|float}
*/
extractFloorPrice: (bidRequest) => {
let floorPrice;
if (bidRequest && bidRequest.params && bidRequest.params.floor) {
// if there is a manual floorPrice set
floorPrice = !isNaN(parseInt(bidRequest.params.floor)) ? bidRequest.params.floor : undefined;
}
if (typeof bidRequest.getFloor === 'function') {
// use prebid floor module
let floorInfo;
try {
floorInfo = bidRequest.getFloor();
} catch (e) {}
floorPrice = typeof floorInfo === 'object' && !isNaN(parseInt(floorInfo.floor)) ? floorInfo.floor : floorPrice;
}

return floorPrice;
},

/**
* Group given array of bidRequests by params.publisher
*
Expand Down Expand Up @@ -229,6 +253,12 @@ export const spec = {
bid.native = nativeConfig;
}

// add floor price
const floorPrice = internal.extractFloorPrice(bidRequest);
if (floorPrice) {
bid.floorPrice = floorPrice;
}

request.data.imp.push(bid);
});

Expand Down
65 changes: 65 additions & 0 deletions test/spec/modules/aduptechBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,71 @@ describe('AduptechBidAdapter', () => {
}
]);
});

it('should build a request with floorPrices', () => {
const bidderRequest = {
auctionId: 'auctionId123',
refererInfo: {
canonicalUrl: 'http://crazy.canonical.url',
referer: 'http://crazy.referer.url'
},
gdprConsent: {
consentString: 'consentString123',
gdprApplies: true
}
};

const getFloorResponse = {
currency: 'USD',
floor: '1.23'
};

const validBidRequests = [
{
bidId: 'bidId1',
adUnitCode: 'adUnitCode1',
transactionId: 'transactionId1',
mediaTypes: {
banner: {
sizes: [[100, 200], [300, 400]]
}
},
params: {
publisher: 'publisher1',
placement: 'placement1'
},
getFloor: () => {
return getFloorResponse
}
}
];

expect(spec.buildRequests(validBidRequests, bidderRequest)).to.deep.equal([
{
url: internal.buildEndpointUrl(validBidRequests[0].params.publisher),
method: ENDPOINT_METHOD,
data: {
auctionId: bidderRequest.auctionId,
pageUrl: bidderRequest.refererInfo.canonicalUrl,
referrer: bidderRequest.refererInfo.referer,
gdpr: {
consentString: bidderRequest.gdprConsent.consentString,
consentRequired: bidderRequest.gdprConsent.gdprApplies
},
imp: [
{
bidId: validBidRequests[0].bidId,
transactionId: validBidRequests[0].transactionId,
adUnitCode: validBidRequests[0].adUnitCode,
params: validBidRequests[0].params,
banner: validBidRequests[0].mediaTypes.banner,
floorPrice: getFloorResponse.floor
}
]
}
}
]);
});
});

describe('interpretResponse', () => {
Expand Down

0 comments on commit 35d09f4

Please sign in to comment.