From 9e8aa4f2d7cce33cfa930540c549cdc18fc435c2 Mon Sep 17 00:00:00 2001 From: Love Sharma Date: Sun, 30 Oct 2022 22:34:14 -0400 Subject: [PATCH] added support for media type specific siteIds --- modules/ixBidAdapter.js | 27 +++++-- test/spec/modules/ixBidAdapter_spec.js | 103 +++++++++++++++++++++++++ 2 files changed, 124 insertions(+), 6 deletions(-) diff --git a/modules/ixBidAdapter.js b/modules/ixBidAdapter.js index a8ffc4be721..27e6d0aee02 100644 --- a/modules/ixBidAdapter.js +++ b/modules/ixBidAdapter.js @@ -158,7 +158,7 @@ const MEDIA_TYPES = { * @return {object} A impression object that will be sent to ad server. */ function bidToBannerImp(bid) { - const imp = bidToImp(bid); + const imp = bidToImp(bid, BANNER); imp.banner = {}; const impSize = deepAccess(bid, 'params.size'); if (impSize) { @@ -180,7 +180,7 @@ function bidToBannerImp(bid) { * @return {object} A impression object that will be sent to ad server. */ function bidToVideoImp(bid) { - const imp = bidToImp(bid); + const imp = bidToImp(bid, VIDEO); const videoAdUnitRef = deepAccess(bid, 'mediaTypes.video'); const videoParamRef = deepAccess(bid, 'params.video'); const videoParamErrors = checkVideoParams(videoAdUnitRef, videoParamRef); @@ -248,7 +248,7 @@ function bidToVideoImp(bid) { * @return {object} A impression object that will be sent to ad server. */ function bidToNativeImp(bid) { - const imp = bidToImp(bid); + const imp = bidToImp(bid, NATIVE); const request = bid.nativeOrtbRequest request.eventtrackers = [{ @@ -275,13 +275,28 @@ function bidToNativeImp(bid) { * @param {object} bid PBJS bid object * @returns {object} IX impression object */ -function bidToImp(bid) { +function bidToImp(bid, mediaType) { const imp = {}; imp.id = bid.bidId; imp.ext = {}; - imp.ext.siteID = bid.params.siteId.toString(); + + if (deepAccess(bid, `params.${mediaType}.siteId`) && !isNaN(Number(bid.params[mediaType].siteId))) { + switch (mediaType) { + case BANNER: + imp.ext.siteID = bid.params.banner.siteId.toString(); + break; + case VIDEO: + imp.ext.siteID = bid.params.video.siteId.toString(); + break; + case NATIVE: + imp.ext.siteID = bid.params.native.siteId.toString(); + break; + } + } else { + imp.ext.siteID = bid.params.siteId.toString(); + } // populate imp level sid if (bid.params.hasOwnProperty('id') && (typeof bid.params.id === 'string' || typeof bid.params.id === 'number')) { @@ -1426,7 +1441,7 @@ export const spec = { // Step 1: Create impresssions from IX params validBidRequests.forEach((validBidRequest) => { - const adUnitMediaTypes = Object.keys(deepAccess(validBidRequest, 'mediaTypes', {})) + const adUnitMediaTypes = Object.keys(deepAccess(validBidRequest, 'mediaTypes', {})); for (const type in adUnitMediaTypes) { switch (adUnitMediaTypes[type]) { diff --git a/test/spec/modules/ixBidAdapter_spec.js b/test/spec/modules/ixBidAdapter_spec.js index ec749398019..0de300e4a32 100644 --- a/test/spec/modules/ixBidAdapter_spec.js +++ b/test/spec/modules/ixBidAdapter_spec.js @@ -402,6 +402,78 @@ describe('IndexexchangeAdapter', function () { } ]; + const DEFAULT_MULTIFORMAT_VALID_BID = [ + { + bidder: 'ix', + params: { + tagId: '123', + siteId: '456', + video: { + siteId: '1111' + }, + banner: { + siteId: '2222' + }, + native: { + siteId: '3333' + }, + size: [300, 250] + }, + mediaTypes: { + video: { + context: 'outstream', + playerSize: [[300, 250]], + skippable: false, + mimes: [ + 'video/mp4', + 'video/webm' + ], + minduration: 0, + maxduration: 60, + protocols: [1] + }, + banner: { + sizes: [[300, 250], [300, 600]] + }, + native: { + icon: { + required: false + }, + title: { + len: 25, + required: true + }, + body: { + required: true + }, + image: { + required: true + }, + sponsoredBy: { + required: true + } + } + }, + ortb2Imp: { + ext: { + tid: '173f49a8-7549-4218-a23c-e7ba59b47230', + data: { + pbadslot: 'div-gpt-ad-1460505748562-0' + } + } + }, + nativeOrtbRequest: { + assets: [{id: 0, required: 0, img: {type: 1}}, {id: 1, required: 1, title: {len: 140}}, {id: 2, required: 1, data: {type: 2}}, {id: 3, required: 1, img: {type: 3}}, {id: 4, required: false, video: {mimes: ['video/mp4', 'video/webm'], minduration: 0, maxduration: 120, protocols: [2, 3, 5, 6]}}] + }, + adUnitCode: 'div-gpt-ad-1460505748562-0', + transactionId: '273f49a8-7549-4218-a23c-e7ba59b47230', + bidId: '1a2b3c4e', + bidderRequestId: '11a22b33c44e', + auctionId: '1aa2bb3cc4de', + schain: SAMPLE_SCHAIN + } + ]; + const DEFAULT_NATIVE_VALID_BID = [ { bidder: 'ix', @@ -2685,6 +2757,37 @@ describe('IndexexchangeAdapter', function () { expect(diagObj.adunitcode).to.equal(DEFAULT_MULTIFORMAT_VIDEO_VALID_BID[0].adUnitCode) }); }); + + describe('siteId overrides', function () { + it('should use siteId override', function () { + const validBids = DEFAULT_MULTIFORMAT_VALID_BID; + const request = spec.buildRequests(validBids, {}); + const bannerImps = request[0].data.imp[0]; + const videoImps = request[1].data.imp[0]; + const nativeImps = request[2].data.imp[0]; + expect(videoImps.ext.siteID).to.equal('1111'); + bannerImps.banner.format.map(({ ext }) => { + expect(ext.siteID).to.equal('2222'); + }); + expect(nativeImps.ext.siteID).to.equal('3333'); + }); + + it('should use default siteId if overrides are not provided', function () { + const validBids = DEFAULT_MULTIFORMAT_VALID_BID; + delete validBids[0].params.banner; + delete validBids[0].params.video; + delete validBids[0].params.native; + const request = spec.buildRequests(validBids, {}); + const bannerImps = request[0].data.imp[0]; + const videoImps = request[1].data.imp[0]; + const nativeImps = request[2].data.imp[0]; + expect(videoImps.ext.siteID).to.equal('456'); + bannerImps.banner.format.map(({ ext }) => { + expect(ext.siteID).to.equal('456'); + }); + expect(nativeImps.ext.siteID).to.equal('456'); + }); + }); }); describe('interpretResponse', function () {