Skip to content

Commit 4f6c826

Browse files
pm-nitin-shirsatChrisHuie
authored andcommitted
Pubmatic Bid Adapter: use new dealpriority in deal tier module execution (prebid#9103)
* Implement functionality for deal priority * Update test cases * kick off test manually Co-authored-by: Chris Huie <[email protected]>
1 parent 1a577a6 commit 4f6c826

File tree

2 files changed

+87
-8
lines changed

2 files changed

+87
-8
lines changed

modules/pubmaticBidAdapter.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { logWarn, _each, isBoolean, isStr, isArray, inIframe, mergeDeep, deepAccess, isNumber, deepSetValue, logInfo, logError, deepClone, convertTypes, uniques } from '../src/utils.js';
1+
import { getBidRequest, logWarn, _each, isBoolean, isStr, isArray, inIframe, mergeDeep, deepAccess, isNumber, deepSetValue, logInfo, logError, deepClone, convertTypes, uniques } from '../src/utils.js';
22
import { registerBidder } from '../src/adapters/bidderFactory.js';
3-
import { BANNER, VIDEO, NATIVE } from '../src/mediaTypes.js';
4-
import {config} from '../src/config.js';
3+
import { BANNER, VIDEO, NATIVE, ADPOD } from '../src/mediaTypes.js';
4+
import { config } from '../src/config.js';
55
import { Renderer } from '../src/Renderer.js';
66
import { bidderSettings } from '../src/bidderSettings.js';
77
import { convertOrtbRequestToProprietaryNative } from '../src/native.js';
@@ -953,6 +953,29 @@ function _assignRenderer(newBid, request) {
953953
}
954954
}
955955

956+
/**
957+
* In case of adpod video context, assign prebiddealpriority to the dealtier property of adpod-video bid,
958+
* so that adpod module can set the hb_pb_cat_dur targetting key.
959+
* @param {*} newBid
960+
* @param {*} bid
961+
* @param {*} request
962+
* @returns
963+
*/
964+
export function assignDealTier(newBid, bid, request) {
965+
if (!bid?.ext?.prebiddealpriority) return;
966+
const bidRequest = getBidRequest(newBid.requestId, [request.bidderRequest]);
967+
const videoObj = deepAccess(bidRequest, 'mediaTypes.video');
968+
if (videoObj?.context != ADPOD) return;
969+
970+
const duration = bid?.ext?.video?.duration || videoObj?.maxduration;
971+
// if (!duration) return;
972+
newBid.video = {
973+
context: ADPOD,
974+
durationSeconds: duration,
975+
dealTier: bid.ext.prebiddealpriority
976+
};
977+
}
978+
956979
function isNonEmptyArray(test) {
957980
if (isArray(test) === true) {
958981
if (test.length > 0) {
@@ -1265,6 +1288,7 @@ export const spec = {
12651288
newBid.height = bid.hasOwnProperty('h') ? bid.h : req.video.h;
12661289
newBid.vastXml = bid.adm;
12671290
_assignRenderer(newBid, request);
1291+
assignDealTier(newBid, bid, request);
12681292
break;
12691293
case NATIVE:
12701294
_parseNativeResponse(bid, newBid);

test/spec/modules/pubmaticBidAdapter_spec.js

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import {expect} from 'chai';
2-
import {spec, checkVideoPlacement, _getDomainFromURL} from 'modules/pubmaticBidAdapter.js';
1+
import { expect } from 'chai';
2+
import { spec, checkVideoPlacement, _getDomainFromURL, assignDealTier } from 'modules/pubmaticBidAdapter.js';
33
import * as utils from 'src/utils.js';
4-
import {config} from 'src/config.js';
4+
import { config } from 'src/config.js';
55
import { createEidsArray } from 'modules/userId/eids.js';
66
import { bidderSettings } from 'src/bidderSettings.js';
77
const constants = require('src/constants.json');
@@ -4063,9 +4063,64 @@ describe('PubMatic adapter', function () {
40634063
expect(data.imp[0]['video']['h']).to.equal(videoBidRequests[0].mediaTypes.video.playerSize[1]);
40644064
expect(data.imp[0]['video']['battr']).to.equal(undefined);
40654065
});
4066+
4067+
describe('Assign Deal Tier (i.e. prebidDealPriority)', function () {
4068+
let videoSeatBid, request, newBid;
4069+
// let data = JSON.parse(request.data);
4070+
beforeEach(function () {
4071+
videoSeatBid = videoBidResponse.body.seatbid[0].bid[0];
4072+
// const adpodValidOutstreamBidRequest = validOutstreamBidRequest.bids[0].mediaTypes.video.context = 'adpod';
4073+
request = spec.buildRequests(bidRequests, validOutstreamBidRequest);
4074+
newBid = {
4075+
requestId: '47acc48ad47af5'
4076+
};
4077+
videoSeatBid.ext = videoSeatBid.ext || {};
4078+
videoSeatBid.ext.video = videoSeatBid.ext.video || {};
4079+
// videoBidRequests[0].mediaTypes.video = videoBidRequests[0].mediaTypes.video || {};
4080+
});
4081+
4082+
it('should not assign video object if deal priority is missing', function () {
4083+
assignDealTier(newBid, videoSeatBid, request);
4084+
expect(newBid.video).to.equal(undefined);
4085+
expect(newBid.video).to.not.exist;
4086+
});
4087+
4088+
it('should not assign video object if context is not a adpod', function () {
4089+
videoSeatBid.ext.prebiddealpriority = 5;
4090+
assignDealTier(newBid, videoSeatBid, request);
4091+
expect(newBid.video).to.equal(undefined);
4092+
expect(newBid.video).to.not.exist;
4093+
});
4094+
4095+
describe('when video deal tier object is present', function () {
4096+
beforeEach(function () {
4097+
videoSeatBid.ext.prebiddealpriority = 5;
4098+
request.bidderRequest.bids[0].mediaTypes.video = {
4099+
...request.bidderRequest.bids[0].mediaTypes.video,
4100+
context: 'adpod',
4101+
maxduration: 50
4102+
};
4103+
});
4104+
4105+
it('should set video deal tier object, when maxduration is present in ext', function () {
4106+
assignDealTier(newBid, videoSeatBid, request);
4107+
expect(newBid.video.durationSeconds).to.equal(50);
4108+
expect(newBid.video.context).to.equal('adpod');
4109+
expect(newBid.video.dealTier).to.equal(5);
4110+
});
4111+
4112+
it('should set video deal tier object, when duration is present in ext', function () {
4113+
videoSeatBid.ext.video.duration = 20;
4114+
assignDealTier(newBid, videoSeatBid, request);
4115+
expect(newBid.video.durationSeconds).to.equal(20);
4116+
expect(newBid.video.context).to.equal('adpod');
4117+
expect(newBid.video.dealTier).to.equal(5);
4118+
});
4119+
});
4120+
});
40664121
});
40674122

4068-
describe('Marketplace params', function() {
4123+
describe('Marketplace params', function () {
40694124
let sandbox, utilsMock, newBidRequests, newBidResponses;
40704125
beforeEach(() => {
40714126
utilsMock = sinon.mock(utils);
@@ -4082,7 +4137,7 @@ describe('PubMatic adapter', function () {
40824137
sandbox.restore();
40834138
})
40844139

4085-
it('Should add bidder code as groupm for marketplace groupm response', function () {
4140+
it('Should add bidder code as groupm for marketplace groupm response ', function () {
40864141
let request = spec.buildRequests(newBidRequests, {
40874142
auctionId: 'new-auction-id'
40884143
});

0 commit comments

Comments
 (0)