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

IX Bid Adapter: add support for handling vastXML responses in PBJS #7661

Merged
merged 11 commits into from
Nov 10, 2021
25 changes: 22 additions & 3 deletions modules/ixBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ const LOCAL_STORAGE_KEY = 'ixdiag';
let hasRegisteredHandler = false;
export const storage = getStorageManager(GLOBAL_VENDOR_ID, BIDDER_CODE);

// Possible values for bidResponse.seatBid[].bid[].mtype which indicates the type of the creative markup so that it can properly be associated with the right sub-object of the BidRequest.Imp.
const MEDIA_TYPES = {
Banner: 1,
Video: 2,
Audio: 3,
Native: 4
}

/**
* Transform valid bid request config object to banner impression object that will be sent to ad server.
*
Expand Down Expand Up @@ -275,9 +283,14 @@ function parseBid(rawBid, currency, bidRequest) {
bid.currency = currency;
bid.creativeId = rawBid.hasOwnProperty('crid') ? rawBid.crid : '-';

// in the event of a video
if (deepAccess(rawBid, 'ext.vasturl')) {
if (rawBid.mtype == MEDIA_TYPES.Video) {
bid.vastXml = rawBid.adm
} else if (rawBid.ext && rawBid.ext.vasturl) {
bid.vastUrl = rawBid.ext.vasturl
}

// in the event of a video
if ((rawBid.ext && rawBid.ext.vasturl) || rawBid.mtype == MEDIA_TYPES.Video) {
bid.width = bidRequest.video.w;
bid.height = bidRequest.video.h;
bid.mediaType = VIDEO;
Expand Down Expand Up @@ -1066,7 +1079,13 @@ function outstreamRenderer(bid) {
timeout: 3000
};

window.IXOutstreamPlayer(bid.vastUrl, bid.adUnitCode, config);
// IXOutstreamPlayer supports both vastUrl and vastXml, so we can pass either.
// Since vastUrl is going to be deprecated from exchange response, vastXml takes priority.
if (bid.vastXml) {
window.IXOutstreamPlayer(bid.vastXml, bid.adUnitCode, config);
} else {
window.IXOutstreamPlayer(bid.vastUrl, bid.adUnitCode, config);
}
});
}

Expand Down
70 changes: 70 additions & 0 deletions test/spec/modules/ixBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,37 @@ describe('IndexexchangeAdapter', function () {
]
};

const DEFAULT_VIDEO_BID_RESPONSE_WITH_MTYPE_SET = {
cur: 'USD',
id: '1aa2bb3cc4de',
seatbid: [
{
bid: [
{
crid: '12346',
adomain: ['www.abcd.com'],
adid: '14851456',
impid: '1a2b3c4e',
cid: '3051267',
price: 110,
id: '2',
mtype: 2,
adm: '<?xml version=\"1.0\" encoding=\"UTF-8\"?><VAST xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"vast.xsd\" version=\"3.0\"> <Ad id=\"488427365\"> <InLine> <AdSystem>Test</AdSystem> <AdTitle>In-Stream Video</AdTitle> </InLine> </Ad></VAST',
ext: {
vasturl: 'www.abcd.com/vast',
errorurl: 'www.abcd.com/error',
dspid: 51,
pricelevel: '_110',
advbrandid: 303326,
advbrand: 'OECTB'
}
}
],
seat: '3971'
}
]
};

const DEFAULT_OPTION = {
gdprConsent: {
gdprApplies: true,
Expand Down Expand Up @@ -2343,6 +2374,45 @@ describe('IndexexchangeAdapter', function () {
expect(result[0]).to.deep.equal(expectedParse[0]);
});

it('should get correct bid response for video ad and set bid.vastXml when mtype is 2 (video)', function () {
const expectedParse = [
{
requestId: '1a2b3c4e',
cpm: 1.1,
creativeId: '12346',
mediaType: 'video',
mediaTypes: {
video: {
context: 'instream',
playerSize: [
[
400,
100
]
]
}
},
width: 640,
height: 480,
currency: 'USD',
ttl: 3600,
netRevenue: true,
vastXml: '<?xml version=\"1.0\" encoding=\"UTF-8\"?><VAST xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"vast.xsd\" version=\"3.0\"> <Ad id=\"488427365\"> <InLine> <AdSystem>Test</AdSystem> <AdTitle>In-Stream Video</AdTitle> </InLine> </Ad></VAST',
meta: {
networkId: 51,
brandId: 303326,
brandName: 'OECTB',
advertiserDomains: ['www.abcd.com']
}
}
];
const result = spec.interpretResponse({ body: DEFAULT_VIDEO_BID_RESPONSE_WITH_MTYPE_SET }, {
data: DEFAULT_BIDDER_REQUEST_DATA, validBidRequests: ONE_VIDEO
});

expect(result[0]).to.deep.equal(expectedParse[0]);
});

it('bidrequest should not have page if options is undefined', function () {
const options = {};
const validBidWithoutreferInfo = spec.buildRequests(DEFAULT_BANNER_VALID_BID, options);
Expand Down