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

Adf adapter: new bidder params added, multiformat bids supported #7570

Merged
merged 2 commits into from
Oct 19, 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
37 changes: 21 additions & 16 deletions modules/adfBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ export const spec = {
aliases: BIDDER_ALIAS,
gvlid: GVLID,
supportedMediaTypes: [ NATIVE, BANNER, VIDEO ],
isBidRequestValid: bid => !!bid.params.mid,
isBidRequestValid: (bid) => {
const params = bid.params || {};
const { mid, inv, mname } = params;
return !!(mid || (inv && mname));
},
buildRequests: (validBidRequests, bidderRequest) => {
let app, site;

Expand Down Expand Up @@ -104,12 +108,19 @@ export const spec = {
}) : {};
const bidfloor = floorInfo.floor;
const bidfloorcur = floorInfo.currency;
const { mid, inv, mname } = bid.params;

const imp = {
id: id + 1,
tagid: bid.params.mid,
tagid: mid,
bidfloor,
bidfloorcur
bidfloorcur,
ext: {
bidder: {
inv,
mname
}
}
};

const assets = _map(bid.nativeParams, (bidParams, key) => {
Expand Down Expand Up @@ -153,9 +164,6 @@ export const spec = {
assets
}
};

bid.mediaType = NATIVE;
return imp;
}

const bannerParams = deepAccess(bid, 'mediaTypes.banner');
Expand All @@ -172,18 +180,14 @@ export const spec = {
imp.banner = {
format
};
bid.mediaType = BANNER;

return imp;
}

const videoParams = deepAccess(bid, 'mediaTypes.video');
if (videoParams) {
imp.video = videoParams;
bid.mediaType = VIDEO;

return imp;
}

return imp;
});

const request = {
Expand Down Expand Up @@ -243,30 +247,31 @@ export const spec = {
return bids.map((bid, id) => {
const bidResponse = bidResponses[id];
if (bidResponse) {
const mediaType = deepAccess(bidResponse, 'ext.prebid.type');
const result = {
requestId: bid.bidId,
cpm: bidResponse.price,
creativeId: bidResponse.crid,
ttl: 360,
netRevenue: bid.netRevenue === 'net',
currency: cur,
mediaType: bid.mediaType,
mediaType,
width: bidResponse.w,
height: bidResponse.h,
dealId: bidResponse.dealid,
meta: {
mediaType: bid.mediaType,
mediaType,
advertiserDomains: bidResponse.adomain
}
};

if (bidResponse.native) {
result.native = parseNative(bidResponse);
} else {
result[ bid.mediaType === VIDEO ? 'vastXml' : 'ad' ] = bidResponse.adm;
result[ mediaType === VIDEO ? 'vastXml' : 'ad' ] = bidResponse.adm;
}

if (!bid.renderer && bid.mediaType === VIDEO && deepAccess(bid, 'mediaTypes.video.context') === 'outstream') {
if (!bid.renderer && mediaType === VIDEO && deepAccess(bid, 'mediaTypes.video.context') === 'outstream') {
result.renderer = Renderer.install({id: bid.bidId, url: OUTSTREAM_RENDERER_URL, adUnitCode: bid.adUnitCode});
result.renderer.setRender(renderer);
}
Expand Down
112 changes: 83 additions & 29 deletions test/spec/modules/adfBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,34 @@ describe('Adf adapter', function () {

it('should return true when required params found', function () {
assert(spec.isBidRequestValid(bid));

bid.params = {
inv: 1234,
mname: 'some-placement'
};
assert(spec.isBidRequestValid(bid));

bid.params = {
mid: 4332,
inv: 1234,
mname: 'some-placement'
};
assert(spec.isBidRequestValid(bid));
});

it('should return false when required params are missing', function () {
bid.params = { adxDomain: 'adx.adform.net' };
assert.isFalse(spec.isBidRequestValid(bid));

bid.params = {
mname: 'some-placement'
};
assert.isFalse(spec.isBidRequestValid(bid));

bid.params = {
inv: 1234
};
assert.isFalse(spec.isBidRequestValid(bid));
});
});

Expand Down Expand Up @@ -331,6 +354,30 @@ describe('Adf adapter', function () {
}
});

describe('dynamic placement tag', function () {
it('should add imp parameters correctly', function () {
const validBidRequests = [
{ bidId: 'bidId', params: { inv: 1000, mname: 'placement' }, mediaTypes: {video: {}} },
{ bidId: 'bidId', params: { mid: 1234, inv: 1002, mname: 'placement2' }, mediaTypes: {video: {}} },
{ bidId: 'bidId', params: { mid: 1234 }, mediaTypes: {video: {}} }
];
const [ imp1, imp2, imp3 ] = getRequestImps(validBidRequests);

assert.equal(imp1.ext.bidder.inv, 1000);
assert.equal(imp1.ext.bidder.mname, 'placement');
assert.equal('tagid' in imp1, false);

assert.equal(imp2.ext.bidder.inv, 1002);
assert.equal(imp2.ext.bidder.mname, 'placement2');
assert.equal(imp2.tagid, 1234);

assert.ok(imp3.ext.bidder);
assert.equal('inv' in imp3.ext.bidder, false);
assert.equal('mname' in imp3.ext.bidder, false);
assert.equal(imp3.tagid, 1234);
});
});

describe('price floors', function () {
it('should not add if floors module not configured', function () {
const validBidRequests = [{ bidId: 'bidId', params: {mid: 1000}, mediaTypes: {video: {}} }];
Expand Down Expand Up @@ -376,18 +423,14 @@ describe('Adf adapter', function () {
return {
currency: currency,
floor
}
};
}
};
}

function getRequestImps(validBidRequests) {
return JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }).data).imp;
}
});

describe('multiple media types', function () {
it('should use single media type for bidding', function () {
it('should use all configured media types for bidding', function () {
let validBidRequests = [{
bidId: 'bidId',
params: { mid: 1000 },
Expand All @@ -414,20 +457,23 @@ describe('Adf adapter', function () {
banner: {
sizes: [[100, 100], [200, 300]]
},
native: {}
native: {},
video: {}
}
}];
let [ banner, video, native ] = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }).data).imp;

assert.ok(banner.banner);
assert.equal(banner.video, undefined);
assert.equal(banner.native, undefined);
assert.ok(video.video);
assert.equal(video.banner, undefined);
assert.equal(video.native, undefined);
assert.ok(native.native);
assert.equal(native.video, undefined);
assert.equal(native.banner, undefined);
let [ first, second, third ] = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }).data).imp;

assert.ok(first.banner);
assert.ok(first.video);
assert.equal(first.native, undefined);

assert.ok(second.video);
assert.equal(second.banner, undefined);
assert.equal(second.native, undefined);

assert.ok(third.native);
assert.ok(third.video);
assert.ok(third.banner);
});
});

Expand Down Expand Up @@ -626,6 +672,10 @@ describe('Adf adapter', function () {
});
});
});

function getRequestImps(validBidRequests) {
return JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }).data).imp;
}
});

describe('interpretResponse', function () {
Expand Down Expand Up @@ -754,7 +804,12 @@ describe('Adf adapter', function () {
imptrackers: ['imptrackers url1', 'imptrackers url2']
},
dealid: 'deal-id',
adomain: [ 'demo.com' ]
adomain: [ 'demo.com' ],
ext: {
prebid: {
type: 'native'
}
}
}
]
}],
Expand All @@ -767,7 +822,6 @@ describe('Adf adapter', function () {
{
bidId: 'bidId1',
params: { mid: 1000 },
mediaType: 'native',
nativeParams: {
title: { required: true, len: 140 },
image: { required: false, wmin: 836, hmin: 627, w: 325, h: 300, mimes: ['image/jpg', 'image/gif'] },
Expand Down Expand Up @@ -899,7 +953,7 @@ describe('Adf adapter', function () {
let serverResponse = {
body: {
seatbid: [{
bid: [{ impid: '1', adm: '<banner>' }]
bid: [{ impid: '1', adm: '<banner>', ext: { prebid: { type: 'banner' } } }]
}]
}
};
Expand All @@ -908,15 +962,16 @@ describe('Adf adapter', function () {
bids: [
{
bidId: 'bidId1',
params: { mid: 1000 },
mediaType: 'banner'
params: { mid: 1000 }
}
]
};

bids = spec.interpretResponse(serverResponse, bidRequest);
assert.equal(bids.length, 1);
assert.equal(bids[0].ad, '<banner>');
assert.equal(bids[0].mediaType, 'banner');
assert.equal(bids[0].meta.mediaType, 'banner');
});
});

Expand All @@ -925,7 +980,7 @@ describe('Adf adapter', function () {
let serverResponse = {
body: {
seatbid: [{
bid: [{ impid: '1', adm: '<vast>' }]
bid: [{ impid: '1', adm: '<vast>', ext: { prebid: { type: 'video' } } }]
}]
}
};
Expand All @@ -934,22 +989,23 @@ describe('Adf adapter', function () {
bids: [
{
bidId: 'bidId1',
params: { mid: 1000 },
mediaType: 'video'
params: { mid: 1000 }
}
]
};

bids = spec.interpretResponse(serverResponse, bidRequest);
assert.equal(bids.length, 1);
assert.equal(bids[0].vastXml, '<vast>');
assert.equal(bids[0].mediaType, 'video');
assert.equal(bids[0].meta.mediaType, 'video');
});

it('should add renderer for outstream bids', function () {
let serverResponse = {
body: {
seatbid: [{
bid: [{ impid: '1', adm: '<vast>' }, { impid: '2', adm: '<vast>' }]
bid: [{ impid: '1', adm: '<vast>', ext: { prebid: { type: 'video' } } }, { impid: '2', adm: '<vast>', ext: { prebid: { type: 'video' } } }]
}]
}
};
Expand All @@ -959,7 +1015,6 @@ describe('Adf adapter', function () {
{
bidId: 'bidId1',
params: { mid: 1000 },
mediaType: 'video',
mediaTypes: {
video: {
context: 'outstream'
Expand All @@ -969,7 +1024,6 @@ describe('Adf adapter', function () {
{
bidId: 'bidId2',
params: { mid: 1000 },
mediaType: 'video',
mediaTypes: {
video: {
constext: 'instream'
Expand Down