Skip to content

Commit

Permalink
Outbrain bid adapter: added floor module and privacy link support (pr…
Browse files Browse the repository at this point in the history
…ebid#8223)

* add floor support

* add additional validation for bid request format

* add privacy link support

* fixes

* set privacy in mapper

* fix test
  • Loading branch information
markkuhar authored Mar 30, 2022
1 parent 3015515 commit ca0c0f1
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 6 deletions.
49 changes: 45 additions & 4 deletions modules/outbrainBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,28 @@ export const spec = {
gvlid: GVLID,
supportedMediaTypes: [ NATIVE, BANNER ],
isBidRequestValid: (bid) => {
if (typeof bid.params !== 'object') {
return false;
}

if (typeof deepAccess(bid, 'params.publisher.id') !== 'string') {
return false;
}

if (!!bid.params.tagid && typeof bid.params.tagid !== 'string') {
return false;
}

if (!!bid.params.bcat && (typeof bid.params.bcat !== 'object' || !bid.params.bcat.every(item => typeof item === 'string'))) {
return false;
}

if (!!bid.params.badv && (typeof bid.params.badv !== 'object' || !bid.params.badv.every(item => typeof item === 'string'))) {
return false;
}

return (
!!config.getConfig('outbrain.bidderUrl') &&
!!deepAccess(bid, 'params.publisher.id') &&
!!(bid.nativeParams || bid.sizes)
);
},
Expand Down Expand Up @@ -67,6 +86,13 @@ export const spec = {
}
}

if (typeof bid.getFloor === 'function') {
const floor = _getFloor(bid, bid.nativeParams ? NATIVE : BANNER);
if (floor) {
imp.bidfloor = floor;
}
}

return imp;
});

Expand Down Expand Up @@ -190,7 +216,7 @@ export const spec = {
registerBidder(spec);

function parseNative(bid) {
const { assets, link, eventtrackers } = JSON.parse(bid.adm);
const { assets, link, privacy, eventtrackers } = JSON.parse(bid.adm);
const result = {
clickUrl: link.url,
clickTrackers: link.clicktrackers || undefined
Expand All @@ -202,6 +228,9 @@ function parseNative(bid) {
result[kind] = content.text || content.value || { url: content.url, width: content.w, height: content.h };
}
});
if (privacy) {
result.privacyLink = privacy;
}
if (eventtrackers) {
result.impressionTrackers = [];
eventtrackers.forEach(tracker => {
Expand Down Expand Up @@ -251,8 +280,8 @@ function getNativeAssets(bid) {

if (bidParams.sizes) {
const sizes = flatten(bidParams.sizes);
w = sizes[0];
h = sizes[1];
w = parseInt(sizes[0], 10);
h = parseInt(sizes[1], 10);
}

asset[props.name] = {
Expand Down Expand Up @@ -291,3 +320,15 @@ function transformSizes(requestSizes) {

return [];
}

function _getFloor(bid, type) {
const floorInfo = bid.getFloor({
currency: CURRENCY,
mediaType: type,
size: '*'
});
if (typeof floorInfo === 'object' && floorInfo.currency === CURRENCY && !isNaN(parseFloat(floorInfo.floor))) {
return parseFloat(floorInfo.floor);
}
return null;
}
94 changes: 92 additions & 2 deletions test/spec/modules/outbrainBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,38 @@ describe('Outbrain Adapter', function () {
}
expect(spec.isBidRequestValid(bid)).to.equal(false)
})
it('should fail if tag id is not string', function () {
const bid = {
bidder: 'outbrain',
params: {
tagid: 123
},
...nativeBidRequestParams,
}
expect(spec.isBidRequestValid(bid)).to.equal(false)
})
it('should fail if badv does not include strings', function () {
const bid = {
bidder: 'outbrain',
params: {
tagid: 123,
badv: ['a', 2, 'c']
},
...nativeBidRequestParams,
}
expect(spec.isBidRequestValid(bid)).to.equal(false)
})
it('should fail if bcat does not include strings', function () {
const bid = {
bidder: 'outbrain',
params: {
tagid: 123,
bcat: ['a', 2, 'c']
},
...nativeBidRequestParams,
}
expect(spec.isBidRequestValid(bid)).to.equal(false)
})
it('should succeed with outbrain config', function () {
const bid = {
bidder: 'outbrain',
Expand Down Expand Up @@ -362,6 +394,63 @@ describe('Outbrain Adapter', function () {
{source: 'liveramp.com', uids: [{id: 'id-value', atype: 3}]}
]);
});

it('should pass bidfloor', function () {
const bidRequest = {
...commonBidRequest,
...nativeBidRequestParams,
}
bidRequest.getFloor = function() {
return {
currency: 'USD',
floor: 1.23,
}
}

const res = spec.buildRequests([bidRequest], commonBidderRequest)
const resData = JSON.parse(res.data)
expect(resData.imp[0].bidfloor).to.equal(1.23)
});

it('should transform string sizes to numbers', function () {
let bidRequest = {
bidId: 'bidId',
params: {},
...commonBidRequest,
...nativeBidRequestParams,
};
bidRequest.nativeParams.image.sizes = ['120', '100']

const expectedNativeAssets = {
assets: [
{
required: 1,
id: 3,
img: {
type: 3,
w: 120,
h: 100
}
},
{
required: 1,
id: 0,
title: {}
},
{
required: 0,
id: 5,
data: {
type: 1
}
}
]
}

let res = spec.buildRequests([bidRequest], commonBidderRequest);
const resData = JSON.parse(res.data)
expect(resData.imp[0].native.request).to.equal(JSON.stringify(expectedNativeAssets));
});
})

describe('interpretResponse', function () {
Expand All @@ -382,7 +471,7 @@ describe('Outbrain Adapter', function () {
impid: '1',
price: 1.1,
nurl: 'http://example.com/win/${AUCTION_PRICE}',
adm: '{"ver":"1.2","assets":[{"id":3,"required":1,"img":{"url":"http://example.com/img/url","w":120,"h":100}},{"id":0,"required":1,"title":{"text":"Test title"}},{"id":5,"data":{"value":"Test sponsor"}}],"link":{"url":"http://example.com/click/url"},"eventtrackers":[{"event":1,"method":1,"url":"http://example.com/impression"}]}',
adm: '{"ver":"1.2","assets":[{"id":3,"required":1,"img":{"url":"http://example.com/img/url","w":120,"h":100}},{"id":0,"required":1,"title":{"text":"Test title"}},{"id":5,"data":{"value":"Test sponsor"}}],"privacy":"http://example.com/privacy","link":{"url":"http://example.com/click/url"},"eventtrackers":[{"event":1,"method":1,"url":"http://example.com/impression"}]}',
adomain: [
'example.com'
],
Expand Down Expand Up @@ -435,7 +524,8 @@ describe('Outbrain Adapter', function () {
sponsoredBy: 'Test sponsor',
impressionTrackers: [
'http://example.com/impression',
]
],
privacyLink: 'http://example.com/privacy'
}
}
]
Expand Down

0 comments on commit ca0c0f1

Please sign in to comment.