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

Make adhese adapter prebid 3.0 compatible #4507

Merged
merged 8 commits into from
Nov 27, 2019
Merged
40 changes: 30 additions & 10 deletions modules/adheseBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const spec = {
supportedMediaTypes: [BANNER, VIDEO],

isBidRequestValid: function(bid) {
return !!(bid.params.account && bid.params.location && bid.params.format);
return !!(bid.params.account && bid.params.location && (bid.params.format || bid.mediaTypes.banner.sizes));
},

buildRequests: function(validBidRequests, bidderRequest) {
Expand Down Expand Up @@ -83,7 +83,10 @@ function adResponse(bid, ad) {
width: Number(ad.width),
height: Number(ad.height),
creativeId: adDetails.creativeId,
dealId: adDetails.dealId
dealId: adDetails.dealId,
adhese: {
originData: adDetails.originData
}
});

if (bidResponse.mediaType === VIDEO) {
Expand Down Expand Up @@ -112,7 +115,19 @@ function mergeTargets(targets, target) {
}

function bidToSlotName(bid) {
return bid.params.location + '-' + bid.params.format;
if (bid.params.format) {
return bid.params.location + '-' + bid.params.format;
}

var sizes = bid.mediaTypes.banner.sizes;
sizes.sort();
var format = sizes.map(size => size[0] + 'x' + size[1]).join('_');

if (format.length > 0) {
return bid.params.location + '-' + format;
} else {
return bid.params.location;
}
}

function getAccount(validBidRequests) {
Expand Down Expand Up @@ -150,22 +165,27 @@ function getPrice(ad) {
function getAdDetails(ad) {
let creativeId = '';
let dealId = '';
let originData = {};

if (isAdheseAd(ad)) {
creativeId = ad.id;
dealId = ad.orderId;
originData = { priority: ad.priority, orderProperty: ad.orderProperty, adFormat: ad.adFormat, adType: ad.adType, libId: ad.libId, adspaceId: ad.adspaceId, viewableImpressionCounter: ad.viewableImpressionCounter };
} else {
creativeId = ad.origin + (ad.originInstance ? '-' + ad.originInstance : '');
if (ad.originData && ad.originData.seatbid && ad.originData.seatbid.length) {
const seatbid = ad.originData.seatbid[0];
if (seatbid.bid && seatbid.bid.length) {
const bid = seatbid.bid[0];
creativeId = String(bid.crid || '');
dealId = String(bid.dealid || '');
if (ad.originData) {
originData = ad.originData;
if (ad.originData.seatbid && ad.originData.seatbid.length) {
const seatbid = ad.originData.seatbid[0];
if (seatbid.bid && seatbid.bid.length) {
const bid = seatbid.bid[0];
creativeId = String(bid.crid || '');
dealId = String(bid.dealid || '');
}
}
}
}
return { creativeId: creativeId, dealId: dealId };
return { creativeId: creativeId, dealId: dealId, originData: originData };
}

function base64urlEncode(s) {
Expand Down
33 changes: 33 additions & 0 deletions test/spec/modules/adheseBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,16 @@ describe('AdheseAdapter', function () {
mediaType: 'banner',
netRevenue: NET_REVENUE,
ttl: TTL,
adhese: {
originData: {
seatbid: [
{
bid: [ { crid: '60613369', dealid: null } ],
seat: '958'
}
]
}
}
}];
expect(spec.interpretResponse(sspBannerResponse, bidRequest)).to.deep.equal(expectedResponse);
});
Expand Down Expand Up @@ -185,6 +195,7 @@ describe('AdheseAdapter', function () {
mediaType: 'video',
netRevenue: NET_REVENUE,
ttl: TTL,
adhese: { originData: {} }
}];
expect(spec.interpretResponse(sspVideoResponse, bidRequest)).to.deep.equal(expectedResponse);
});
Expand Down Expand Up @@ -235,6 +246,17 @@ describe('AdheseAdapter', function () {
let expectedResponse = [{
requestId: BID_ID,
ad: '<script id="body" type="text/javascript"></script><img src=\'https://hosts-demo.adhese.com/track/742898\' style=\'height:1px; width:1px; margin: -1px -1px; display:none;\'/>',
adhese: {
originData: {
adFormat: 'largeleaderboard',
adType: 'largeleaderboard',
adspaceId: '162363',
libId: '90511',
orderProperty: undefined,
priority: undefined,
viewableImpressionCounter: undefined
}
},
cpm: 5.96,
currency: 'USD',
creativeId: '742898',
Expand Down Expand Up @@ -279,6 +301,17 @@ describe('AdheseAdapter', function () {
let expectedResponse = [{
requestId: BID_ID,
vastXml: '<?xml version=\'1.0\' encoding=\'UTF-8\' standalone=\'no\'?><VAST version=\'2.0\' xmlns:xsi=\'http://www.w3.org/2001/XMLSchema-instance\' xsi:noNamespaceSchemaLocation=\'vast.xsd\'></VAST>',
adhese: {
originData: {
adFormat: '',
adType: 'preroll',
adspaceId: '164196',
libId: '89860',
orderProperty: undefined,
priority: undefined,
viewableImpressionCounter: undefined
}
},
cpm: 0,
currency: 'USD',
creativeId: '742470',
Expand Down