From caeae81e1da2a32ea7b37ab828f3ff40f16efd25 Mon Sep 17 00:00:00 2001 From: Chris Corbo Date: Wed, 21 Jun 2023 13:22:04 -0400 Subject: [PATCH] feat: signal imp.displaymanager [PB-551] --- modules/ixBidAdapter.js | 39 +++++++++++++- test/spec/modules/ixBidAdapter_spec.js | 72 ++++++++++++++++++++++++++ 2 files changed, 110 insertions(+), 1 deletion(-) diff --git a/modules/ixBidAdapter.js b/modules/ixBidAdapter.js index 000131d9e03..ab96d6d78c4 100644 --- a/modules/ixBidAdapter.js +++ b/modules/ixBidAdapter.js @@ -177,6 +177,41 @@ function bidToBannerImp(bid) { return imp; } +/** + * Sets imp.displaymanager + * + * @param {object} imp + * @param {object} bid + */ +function setDisplayManager(imp, bid) { + if (deepAccess(bid, 'mediaTypes.video.context') === OUTSTREAM) { + let renderer = deepAccess(bid, 'mediaTypes.video.renderer'); + if (!renderer) { + renderer = deepAccess(bid, 'renderer'); + } + + if (deepAccess(bid, 'schain', false)) { + imp.displaymanager = 'pbjs_wrapper'; + } else if (renderer && typeof (renderer) === 'object') { + if (renderer.url !== undefined) { + let domain = ''; + try { + domain = new URL(renderer.url).hostname + } catch { + return; + } + if (domain.includes('js-sec.indexww')) { + imp.displaymanager = 'ix'; + } else { + imp.displaymanager = renderer.url; + } + } + } else { + imp.displaymanager = 'ix'; + } + } +} + /** * Transform valid bid request config object to video impression object that will be sent to ad server. * @@ -196,8 +231,10 @@ function bidToVideoImp(bid) { // populate imp level transactionId imp.ext.tid = deepAccess(bid, 'ortb2Imp.ext.tid'); + setDisplayManager(imp, bid); + // AdUnit-Specific First Party Data - addAdUnitFPD(imp, bid) + addAdUnitFPD(imp, bid); // copy all video properties to imp object for (const adUnitProperty in videoAdUnitRef) { diff --git a/test/spec/modules/ixBidAdapter_spec.js b/test/spec/modules/ixBidAdapter_spec.js index 783d273e425..a2527fffe63 100644 --- a/test/spec/modules/ixBidAdapter_spec.js +++ b/test/spec/modules/ixBidAdapter_spec.js @@ -2332,6 +2332,78 @@ describe('IndexexchangeAdapter', function () { }); }); + describe('video request should set displaymanager', () => { + it('ix renderer preferrered', () => { + const bid = utils.deepClone(DEFAULT_VIDEO_VALID_BID); + bid[0].mediaTypes.video.context = 'outstream'; + bid[0].mediaTypes.video.w = [[300, 143]]; + bid[0].schain = undefined; + const request = spec.buildRequests(bid); + const videoImpression = extractPayload(request[0]).imp[0]; + expect(videoImpression.displaymanager).to.equal('ix'); + }); + it('ix renderer not preferrered', () => { + const bid = utils.deepClone(DEFAULT_VIDEO_VALID_BID); + bid[0].mediaTypes.video.context = 'outstream'; + bid[0].mediaTypes.video.w = [[300, 143]]; + bid[0].mediaTypes.video.renderer = { + url: 'http://publisherplayer.js', + render: () => { } + }; + bid[0].schain = undefined; + const request = spec.buildRequests(bid); + const videoImpression = extractPayload(request[0]).imp[0]; + expect(videoImpression.displaymanager).to.equal('http://publisherplayer.js'); + }); + it('ix renderer not preferrered - bad url', () => { + const bid = utils.deepClone(DEFAULT_VIDEO_VALID_BID); + bid[0].mediaTypes.video.context = 'outstream'; + bid[0].mediaTypes.video.w = [[300, 143]]; + bid[0].mediaTypes.video.renderer = { + url: 'publisherplayer.js', + render: () => { } + }; + bid[0].schain = undefined; + const request = spec.buildRequests(bid); + const videoImpression = extractPayload(request[0]).imp[0]; + expect(videoImpression.displaymanager).to.be.undefined; + }); + it('renderer url provided and is ix renderer', () => { + const bid = utils.deepClone(DEFAULT_VIDEO_VALID_BID); + bid[0].mediaTypes.video.context = 'outstream'; + bid[0].mediaTypes.video.w = [[300, 143]]; + bid[0].mediaTypes.video.renderer = { + url: 'http://js-sec.indexww.rendererplayer.com', + render: () => { } + }; + bid[0].schain = undefined; + const request = spec.buildRequests(bid); + const videoImpression = extractPayload(request[0]).imp[0]; + expect(videoImpression.displaymanager).to.equal('ix'); + }); + it('renderer url undefined and is ix renderer', () => { + const bid = utils.deepClone(DEFAULT_VIDEO_VALID_BID); + bid[0].mediaTypes.video.context = 'outstream'; + bid[0].mediaTypes.video.w = [[300, 143]]; + bid[0].mediaTypes.video.renderer = { + render: () => { } + }; + bid[0].schain = undefined; + const request = spec.buildRequests(bid); + const videoImpression = extractPayload(request[0]).imp[0]; + expect(videoImpression.displaymanager).to.be.undefined; + }); + it('schain', () => { + const bid = utils.deepClone(DEFAULT_VIDEO_VALID_BID); + bid[0].mediaTypes.video.context = 'outstream'; + bid[0].mediaTypes.video.w = [[300, 143]]; + bid[0].schain = SAMPLE_SCHAIN; + const request = spec.buildRequests(bid); + const videoImpression = extractPayload(request[0]).imp[0]; + expect(videoImpression.displaymanager).to.equal('pbjs_wrapper'); + }); + }); + describe('request should contain both banner and native requests', function () { const request = spec.buildRequests([DEFAULT_BANNER_VALID_BID[0], DEFAULT_NATIVE_VALID_BID[0]]);