Skip to content

Commit

Permalink
feat: signal imp.displaymanager [PB-551] (prebid#10131)
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Corbo <chris.corbo@indexexchange.com>
  • Loading branch information
2 people authored and github-ishara-chan-tung committed Jul 12, 2023
1 parent 8d12fb6 commit 867514c
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 1 deletion.
39 changes: 38 additions & 1 deletion modules/ixBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,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.
*
Expand All @@ -199,8 +234,10 @@ export 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) {
Expand Down
72 changes: 72 additions & 0 deletions test/spec/modules/ixBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2357,6 +2357,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 () {
let request;
before(() => {
Expand Down

0 comments on commit 867514c

Please sign in to comment.