Skip to content

Commit

Permalink
smartx Bid Adapter: Add support for Floors Module (prebid#6902)
Browse files Browse the repository at this point in the history
* Add smartclipBidAdapter

* smartxBidAdapter.js - removed unused variables, removed debug, added window before the outstream related functions

* - made outstream player configurable

* remove wrong named files

* camelcase

* fix

* Out-Stream render update to SmartPlay 5.2

* ESlint fix

* ESlint fix

* ESlint fix

* adjust tests, fixes

* ESlint

* adjusted desired bitrate examples

* added bid.meta.advertiserDomains support

* bug fix for numeric elementID outstream render

* fix renderer url

* support for floors module

Co-authored-by: smartclip AdTechnology <[email protected]>
Co-authored-by: Gino Cirlini <[email protected]>
  • Loading branch information
3 people authored and agrandes-tappx committed Sep 29, 2021
1 parent 8e7bac5 commit 8e26733
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 17 deletions.
42 changes: 31 additions & 11 deletions modules/smartxBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,6 @@ export const spec = {
utils.logError(BIDDER_CODE + ': siteId is not present in bidder params');
return false;
}
if (!utils.getBidIdParameter('bidfloor', bid.params)) {
utils.logError(BIDDER_CODE + ': bidfloor is not present in bidder params');
return false;
}
if (!utils.getBidIdParameter('bidfloorcur', bid.params)) {
utils.logError(BIDDER_CODE + ': bidfloorcur is not present in bidder params');
return false;
}
if (utils.deepAccess(bid, 'mediaTypes.video.context') === 'outstream') {
if (!utils.getBidIdParameter('outstream_options', bid.params)) {
utils.logError(BIDDER_CODE + ': outstream_options parameter is not defined');
Expand Down Expand Up @@ -85,8 +77,8 @@ export const spec = {
const smartxRequests = bidRequests.map(function (bid) {
const tagId = utils.getBidIdParameter('tagId', bid.params);
const publisherId = utils.getBidIdParameter('publisherId', bid.params);
const bidfloor = utils.getBidIdParameter('bidfloor', bid.params);
const bidfloorcur = utils.getBidIdParameter('bidfloorcur', bid.params);
const bidfloor = getBidFloor(bid) || 0;
const bidfloorcur = utils.getBidIdParameter('bidfloorcur', bid.params) || 'EUR';
const siteId = utils.getBidIdParameter('siteId', bid.params);
const domain = utils.getBidIdParameter('domain', bid.params);
const cat = utils.getBidIdParameter('cat', bid.params);
Expand Down Expand Up @@ -161,7 +153,7 @@ export const spec = {

const at = utils.getBidIdParameter('at', bid.params) || 2;

const cur = utils.getBidIdParameter('cur', bid.params) || ['EUR'];
const cur = utils.getBidIdParameter('cur', bid.params) || 'EUR';

const requestPayload = {
id: utils.generateUUID(),
Expand Down Expand Up @@ -226,6 +218,8 @@ export const spec = {
}
}

// Todo: USER ID MODULE

requestPayload.user = {
ext: userExt,
data: targetingarr
Expand Down Expand Up @@ -412,4 +406,30 @@ 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) {
let floor = utils.getBidIdParameter('bidfloor', bid.params);
let floorcur = utils.getBidIdParameter('bidfloorcur', bid.params) || 'EUR';

if (!floor && utils.isFn(bid.getFloor)) {
const floorObj = bid.getFloor({
currency: floorcur,
mediaType: '*',
size: '*'
});

if (utils.isPlainObject(floorObj) && !isNaN(floorObj.floor) && floorObj.currency === floorcur) {
floor = floorObj.floor;
}
}

return floor;
}

registerBidder(spec);
108 changes: 102 additions & 6 deletions test/spec/modules/smartxBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,13 @@ describe('The smartx adapter', function () {
expect(spec.isBidRequestValid(bid)).to.equal(false);
});

it('should fail without bidfloor', function () {
it('should succeed with floor Module set', function () {
delete bid.params.bidfloor;
expect(spec.isBidRequestValid(bid)).to.equal(false);
});

it('should fail without bidfloorcur', function () {
delete bid.params.bidfloorcur;
expect(spec.isBidRequestValid(bid)).to.equal(false);
bid.floors = {
currency: 'EUR'
};
expect(spec.isBidRequestValid(bid)).to.equal(true);
});

it('should fail with context outstream but no options set for outstream', function () {
Expand Down Expand Up @@ -514,4 +513,101 @@ describe('The smartx adapter', function () {
window.document.getElementById.restore();
});
});

describe('price floor module', function () {
var bid,
bidRequestObj;

beforeEach(function () {
bid = getValidBidObject();
bidRequestObj = {
refererInfo: {
referer: 'prebid.js'
}
};
delete bid.params.bidfloor;
});

it('obtain floor from getFloor', function () {
bid.getFloor = () => {
return {
currency: 'EUR',
floor: 3.21
};
};

const payload = spec.buildRequests([bid], bidRequestObj)[0];
expect(payload.data.imp).to.have.property('bidfloor', 3.21);
});

it('obtain floor from params', function() {
bid.getFloor = () => {
return {
currency: 'EUR',
floor: 3.21
};
};
bid.params.bidfloor = 0.64;

const payload = spec.buildRequests([bid], bidRequestObj)[0];
expect(payload.data.imp).to.have.property('bidfloor', 0.64);
});

it('check currency USD', function() {
bid.getFloor = () => {
return {
currency: 'USD',
floor: 1.23
};
};
bid.params.bidfloorcur = 'USD'

const payload = spec.buildRequests([bid], bidRequestObj)[0];
expect(payload.data.imp).to.have.property('bidfloorcur', 'USD');
expect(payload.data.imp).to.have.property('bidfloor', 1.23);
});

it('check defaut currency EUR', function() {
delete bid.params.bidfloorcur;

bid.getFloor = () => {
return {
currency: 'EUR',
floor: 4.56
};
};

const payload = spec.buildRequests([bid], bidRequestObj)[0];
expect(payload.data.imp).to.have.property('bidfloorcur', 'EUR');
expect(payload.data.imp).to.have.property('bidfloor', 4.56);
});

it('bad floor value', function() {
bid.getFloor = () => {
return {
currency: 'EUR',
floor: 'bad'
};
};

const payload = spec.buildRequests([bid], bidRequestObj)[0];
expect(payload.data.imp).to.have.property('bidfloor', 0);
});

it('empty floor object', function() {
bid.getFloor = () => {
return {};
};

const payload = spec.buildRequests([bid], bidRequestObj)[0];
expect(payload.data.imp).to.have.property('bidfloor', 0);
});

it('undefined floor result', function() {
bid.getFloor = () => {};

const payload = spec.buildRequests([bid], bidRequestObj)[0];
expect(payload.data.imp).to.have.property('bidfloor', 0);
});
});
})

0 comments on commit 8e26733

Please sign in to comment.