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

SmileWanted Adapter: Fixing issues related to Prebid 5.0 #6953

Merged
merged 1 commit into from
Jun 5, 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
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