Skip to content

Commit

Permalink
Opera Ads Adapter: fix floor price support (prebid#7357)
Browse files Browse the repository at this point in the history
* Opera Ads Adapter: update example parameters in docs

* Opera Ads Adapter: fix floor price support

* Our OpenRTB server only supports USD, any other currency request will
  be ignored
  • Loading branch information
xingwangl authored and Chris Pabst committed Jan 10, 2022
1 parent be19ba4 commit 3b0e6a8
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 63 deletions.
77 changes: 31 additions & 46 deletions modules/operaadsBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,14 @@ export const spec = {
* @returns {Request}
*/
function buildOpenRtbBidRequest(bidRequest, bidderRequest) {
const currencies = getCurrencies(bidRequest);

const pageReferrer = utils.deepAccess(bidderRequest, 'refererInfo.referer');

// build OpenRTB request body
const payload = {
id: bidderRequest.auctionId,
tmax: bidderRequest.timeout || config.getConfig('bidderTimeout'),
test: config.getConfig('debug') ? 1 : 0,
imp: createImp(bidRequest, currencies[0]),
imp: createImp(bidRequest),
device: getDevice(),
site: {
id: String(utils.deepAccess(bidRequest, 'params.publisherId')),
Expand All @@ -208,7 +206,7 @@ function buildOpenRtbBidRequest(bidRequest, bidderRequest) {
},
at: 1,
bcat: getBcat(bidRequest),
cur: currencies,
cur: [DEFAULT_CURRENCY],
regs: {
coppa: config.getConfig('coppa') ? 1 : 0,
ext: {}
Expand Down Expand Up @@ -456,22 +454,19 @@ function interpretNativeAd(nativeResponse, currency, cpm) {
* @param {Currency} cur
* @returns {Imp[]}
*/
function createImp(bidRequest, cur) {
function createImp(bidRequest) {
const imp = [];

const floor = getBidFloor(bidRequest, cur);

const impItem = {
id: bidRequest.bidId,
tagid: String(utils.deepAccess(bidRequest, 'params.placementId')),
bidfloor: floor,
};

let mediaType;
let mediaType, size;
let bannerReq, videoReq, nativeReq;

if ((bannerReq = utils.deepAccess(bidRequest, 'mediaTypes.banner'))) {
const size = canonicalizeSizesArray(bannerReq.sizes || BANNER_DEFAULTS.SIZE)[0];
size = canonicalizeSizesArray(bannerReq.sizes || BANNER_DEFAULTS.SIZE)[0];

impItem.banner = {
w: size[0],
Expand All @@ -481,7 +476,7 @@ function createImp(bidRequest, cur) {

mediaType = BANNER;
} else if ((videoReq = utils.deepAccess(bidRequest, 'mediaTypes.video'))) {
const size = canonicalizeSizesArray(videoReq.playerSize || VIDEO_DEFAULTS.SIZE)[0];
size = canonicalizeSizesArray(videoReq.playerSize || VIDEO_DEFAULTS.SIZE)[0];

impItem.video = {
w: size[0],
Expand Down Expand Up @@ -516,6 +511,14 @@ function createImp(bidRequest, cur) {
mediaType = NATIVE;
}

const floorDetail = getBidFloor(bidRequest, {
mediaType: mediaType || '*',
size: size || '*'
})

impItem.bidfloor = floorDetail.floor;
impItem.bidfloorcur = floorDetail.currency;

if (mediaType) {
imp.push(impItem);
}
Expand Down Expand Up @@ -678,47 +681,29 @@ function getDomain(referer) {
* Get bid floor price
*
* @param {BidRequest} bid
* @param {String} cur
* @returns {Number} floor price
* @param {Params} params
* @returns {Floor} floor price
*/
function getBidFloor(bid, cur) {
let floorInfo = {};

if (typeof bid.getFloor === 'function') {
floorInfo = bid.getFloor({
currency: cur,
mediaType: '*',
size: '*'
function getBidFloor(bid, {mediaType = '*', size = '*'}) {
if (utils.isFn(bid.getFloor)) {
const floorInfo = bid.getFloor({
currency: DEFAULT_CURRENCY,
mediaType,
size
});
}

return floorInfo.floor || 0.0;
}

/**
* Get currencies from bid request
*
* @param {BidRequest} bidRequest
* @returns {String[]} currencies
*/
function getCurrencies(bidRequest) {
let currencies = [];

const pCur = utils.deepAccess(bidRequest, 'params.currency');
if (pCur) {
currencies = currencies.concat(pCur);
}

if (!currencies.length) {
let currency;
if ((currency = config.getConfig('currency')) && currency.adServerCurrency) {
currencies.push(currency.adServerCurrency);
} else {
currencies.push(DEFAULT_CURRENCY);
if (utils.isPlainObject(floorInfo) && !isNaN(floorInfo.floor)) {
return {
currency: floorInfo.currency || DEFAULT_CURRENCY,
floor: floorInfo.floor
};
}
}

return currencies;
return {
currency: DEFAULT_CURRENCY,
floor: 0.0
}
}

/**
Expand Down
25 changes: 12 additions & 13 deletions modules/operaadsBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ Module that connects to OperaAds's demand sources

| Name | Scope | Type | Description | Example
| ---- | ----- | ---- | ----------- | -------
| `placementId` | required | String | The Placement Id provided by Opera Ads. | `s12345678`
| `endpointId` | required | String | The Endpoint Id provided by Opera Ads. | `ep12345678`
| `publisherId` | required | String | The Publisher Id provided by Opera Ads. | `pub12345678`
| `currency` | optional | String or String[] | Currency. | `USD`
| `placementId` | required | String | The Placement Id provided by Opera Ads. | `s5340077725248`
| `endpointId` | required | String | The Endpoint Id provided by Opera Ads. | `ep3425464070464`
| `publisherId` | required | String | The Publisher Id provided by Opera Ads. | `pub3054952966336`
| `bcat` | optional | String or String[] | The bcat value. | `IAB9-31`

### Bid Video Parameters
Expand Down Expand Up @@ -66,9 +65,9 @@ var adUnits = [{
bids: [{
bidder: 'operaads',
params: {
placementId: 's12345678',
endpointId: 's12345678',
publisherId: 's12345678'
placementId: 's5340077725248',
endpointId: 'ep3425464070464',
publisherId: 'pub3054952966336'
}
}]
}];
Expand All @@ -92,9 +91,9 @@ var adUnits = [{
bids: [{
bidder: 'operaads',
params: {
placementId: 's12345678',
endpointId: 's12345678',
publisherId: 's12345678'
placementId: 's5340077725248',
endpointId: 'ep3425464070464',
publisherId: 'pub3054952966336'
}
}]
}];
Expand Down Expand Up @@ -126,9 +125,9 @@ var adUnits = [{
bids: [{
bidder: 'operaads',
params: {
placementId: 's12345678',
endpointId: 's12345678',
publisherId: 's12345678'
placementId: 's5340077725248',
endpointId: 'ep3425464070464',
publisherId: 'pub3054952966336'
}
}]
}];
Expand Down
15 changes: 11 additions & 4 deletions test/spec/modules/operaadsBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ describe('Opera Ads Bid Adapter', function () {
}
});

it('currency in params should be used', function () {
it('test getBidFloor', function() {
const bidRequests = [
{
adUnitCode: 'test-div',
Expand All @@ -276,8 +276,13 @@ describe('Opera Ads Bid Adapter', function () {
params: {
placementId: 's12345678',
publisherId: 'pub12345678',
endpointId: 'ep12345678',
currency: 'RMB'
endpointId: 'ep12345678'
},
getFloor: function() {
return {
currency: 'USD',
floor: 0.1
}
}
}
];
Expand All @@ -292,7 +297,9 @@ describe('Opera Ads Bid Adapter', function () {
requestData = JSON.parse(req.data);
}).to.not.throw();

expect(requestData.cur).to.be.an('array').that.includes('RMB');
expect(requestData.imp).to.be.an('array').that.have.lengthOf(1);
expect(requestData.imp[0].bidfloor).to.be.equal(0.1);
expect(requestData.imp[0].bidfloorcur).to.be.equal('USD');
}
});

Expand Down

0 comments on commit 3b0e6a8

Please sign in to comment.