Skip to content

Commit

Permalink
Fixing issues related to Prebid 5.0 (#6953)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxSmileWanted authored Jun 5, 2021
1 parent d026a10 commit 9c8706e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
39 changes: 38 additions & 1 deletion modules/smilewantedBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export const spec = {
var payload = {
zoneId: bid.params.zoneId,
currencyCode: config.getConfig('currency.adServerCurrency') || 'EUR',
bidfloor: bid.params.bidfloor || 0.0,
tagId: bid.adUnitCode,
sizes: bid.sizes.map(size => ({
w: size[0],
Expand All @@ -41,6 +40,15 @@ export const spec = {
prebidVersion: '$prebid.version$'
};

const floor = getBidFloor(bid);
if (floor) {
payload.bidfloor = floor;
}

if (bid.params.bidfloor) {
payload.bidfloor = bid.params.bidfloor;
}

if (bidderRequest && bidderRequest.refererInfo) {
payload.pageDomain = bidderRequest.refererInfo.referer || '';
}
Expand Down Expand Up @@ -70,6 +78,7 @@ export const spec = {

try {
if (response) {
const dealId = response.dealId || '';
const bidResponse = {
requestId: JSON.parse(bidRequest.data).bidId,
cpm: response.cpm,
Expand All @@ -93,6 +102,14 @@ export const spec = {
bidResponse['renderer'] = newRenderer(JSON.parse(bidRequest.data), response);
}

if (dealId.length > 0) {
bidResponse.dealId = dealId;
}

bidResponse.meta = {};
if (response.meta && response.meta.advertiserDomains && utils.isArray(response.meta.advertiserDomains)) {
bidResponse.meta.advertiserDomains = response.meta.advertiserDomains;
}
bidResponses.push(bidResponse);
}
} catch (error) {
Expand Down Expand Up @@ -172,4 +189,24 @@ function outstreamRender(bid) {
});
}

/**
* Get the floor price from bid.params for backward compatibility.
* If not found, then check floor module.
* @param bid A valid bid object
* @returns {*|number} floor price
*/
function getBidFloor(bid) {
if (utils.isFn(bid.getFloor)) {
const floorInfo = bid.getFloor({
currency: 'USD',
mediaType: 'banner',
size: bid.sizes.map(size => ({ w: size[0], h: size[1] }))
});
if (utils.isPlainObject(floorInfo) && !isNaN(floorInfo.floor) && floorInfo.currency === 'USD') {
return parseFloat(floorInfo.floor);
}
}
return null;
}

registerBidder(spec);
6 changes: 1 addition & 5 deletions test/spec/modules/smilewantedBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ const DISPLAY_REQUEST = [{
],
bidder: 'smilewanted',
params: {
zoneId: 1,
bidfloor: 2.50
zoneId: 1
},
requestId: 'request_abcd1234',
transactionId: 'trans_abcd1234'
Expand Down Expand Up @@ -115,7 +114,6 @@ describe('smilewantedBidAdapterTests', function () {
const requestDisplayContent = JSON.parse(requestDisplay[0].data);
expect(requestDisplayContent).to.have.property('zoneId').and.to.equal(1);
expect(requestDisplayContent).to.have.property('currencyCode').and.to.equal('EUR');
expect(requestDisplayContent).to.have.property('bidfloor').and.to.equal(2.50);
expect(requestDisplayContent).to.have.property('sizes');
expect(requestDisplayContent.sizes[0]).to.have.property('w').and.to.equal(300);
expect(requestDisplayContent.sizes[0]).to.have.property('h').and.to.equal(250);
Expand All @@ -129,7 +127,6 @@ describe('smilewantedBidAdapterTests', function () {
const requestVideoInstreamContent = JSON.parse(requestVideoInstream[0].data);
expect(requestVideoInstreamContent).to.have.property('zoneId').and.to.equal(2);
expect(requestVideoInstreamContent).to.have.property('currencyCode').and.to.equal('EUR');
expect(requestVideoInstreamContent).to.have.property('bidfloor').and.to.equal(2.50);
expect(requestVideoInstreamContent).to.have.property('sizes');
expect(requestVideoInstreamContent.sizes[0]).to.have.property('w').and.to.equal(640);
expect(requestVideoInstreamContent.sizes[0]).to.have.property('h').and.to.equal(480);
Expand All @@ -141,7 +138,6 @@ describe('smilewantedBidAdapterTests', function () {
const requestVideoOutstreamContent = JSON.parse(requestVideoOutstream[0].data);
expect(requestVideoOutstreamContent).to.have.property('zoneId').and.to.equal(3);
expect(requestVideoOutstreamContent).to.have.property('currencyCode').and.to.equal('EUR');
expect(requestVideoOutstreamContent).to.have.property('bidfloor').and.to.equal(2.50);
expect(requestVideoOutstreamContent).to.have.property('sizes');
expect(requestVideoOutstreamContent.sizes[0]).to.have.property('w').and.to.equal(640);
expect(requestVideoOutstreamContent.sizes[0]).to.have.property('h').and.to.equal(480);
Expand Down

0 comments on commit 9c8706e

Please sign in to comment.