Skip to content

Commit

Permalink
PubMatic adapter to support PM Deals (prebid#4887)
Browse files Browse the repository at this point in the history
* added support for pubcommon, digitrust, id5id

* added support for IdentityLink

* changed the source for id5

* added unit test cases

* changed source param for identityLink

* PubMatic to support deals param

* more than 3 chars check added
  • Loading branch information
pm-harshad-mane authored and rjvelicaria committed Apr 9, 2020
1 parent 265ebc1 commit 38dd94a
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 2 deletions.
24 changes: 23 additions & 1 deletion modules/pubmaticBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,26 @@ function _createVideoRequest(bid) {
return videoObj;
}

// support for PMP deals
function _addPMPDealsInImpression(impObj, bid) {
if (bid.params.deals) {
if (utils.isArray(bid.params.deals)) {
bid.params.deals.forEach(function(dealId) {
if (utils.isStr(dealId) && dealId.length > 3) {
if (!impObj.pmp) {
impObj.pmp = { private_auction: 0, deals: [] };
}
impObj.pmp.deals.push({ id: dealId });
} else {
utils.logWarn(LOG_WARN_PREFIX + 'Error: deal-id present in array bid.params.deals should be a strings with more than 3 charaters length, deal-id ignored: ' + dealId);
}
});
} else {
utils.logWarn(LOG_WARN_PREFIX + 'Error: bid.params.deals should be an array of strings.');
}
}
}

function _createImpressionObject(bid, conf) {
var impObj = {};
var bannerObj;
Expand All @@ -516,6 +536,8 @@ function _createImpressionObject(bid, conf) {
bidfloorcur: bid.params.currency ? _parseSlotParam('currency', bid.params.currency) : DEFAULT_CURRENCY
};

_addPMPDealsInImpression(impObj, bid);

if (bid.hasOwnProperty('mediaTypes')) {
for (mediaTypes in bid.mediaTypes) {
switch (mediaTypes) {
Expand Down Expand Up @@ -747,7 +769,7 @@ function _blockedIabCategoriesValidation(payload, blockedIabCategories) {
}
})
.map(category => category.trim()) // trim all
.filter(function(category, index, arr) { // minimum 3 charaters length
.filter(function(category, index, arr) { // more than 3 charaters length
if (category.length > 3) {
return arr.indexOf(category) === index; // unique value only
} else {
Expand Down
3 changes: 2 additions & 1 deletion modules/pubmaticBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ var adUnits = [
kadfloor: '0.50', // optional
currency: 'AUD', // optional (Value configured only in the 1st adunit will be passed on. < br/> Values if present in subsequent adunits, will be ignored.)
dctr: 'key1=123|key2=345', // optional (Value configured only in the 1st adunit will be passed on. < br/> Values if present in subsequent adunits, will be ignored.)
bcat: ['IAB1-5', 'IAB1-7'] // Optional: Blocked IAB Categories. (Values from all slots will be combined and only unique values will be passed. An array of strings only. Each category should be a string of a length of more than 3 characters.)
bcat: ['IAB1-5', 'IAB1-7'], // Optional: Blocked IAB Categories. (Values from all slots will be combined and only unique values will be passed. An array of strings only. Each category should be a string of a length of more than 3 characters.)
deals: ['deal-id-1', 'deal-id-200'] // optional: PMP Deals, should be array of strings
}
}]
}];
Expand Down
106 changes: 106 additions & 0 deletions test/spec/modules/pubmaticBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2299,6 +2299,112 @@ describe('PubMatic adapter', function () {
expect(data.site.ext).to.not.exist;
});

it('Request params deals check', function () {
let multipleBidRequests = [
{
bidder: 'pubmatic',
params: {
publisherId: '301',
adSlot: '/15671365/DMDemo@300x250:0',
kadfloor: '1.2',
pmzoneid: 'aabc, ddef',
kadpageurl: 'www.publisher.com',
yob: '1986',
gender: 'M',
lat: '12.3',
lon: '23.7',
wiid: '1234567890',
profId: '100',
verId: '200',
currency: 'AUD',
deals: ['deal-id-1', 'deal-id-2', 'dea'] // "dea" will not be passed as more than 3 characters needed
},
placementCode: '/19968336/header-bid-tag-1',
sizes: [[300, 250], [300, 600]],
bidId: '23acc48ad47af5',
requestId: '0fb4905b-9456-4152-86be-c6f6d259ba99',
bidderRequestId: '1c56ad30b9b8ca8',
transactionId: '92489f71-1bf2-49a0-adf9-000cea934729'
},
{
bidder: 'pubmatic',
params: {
publisherId: '301',
adSlot: '/15671365/DMDemo@300x250:0',
kadfloor: '1.2',
pmzoneid: 'aabc, ddef',
kadpageurl: 'www.publisher.com',
yob: '1986',
gender: 'M',
lat: '12.3',
lon: '23.7',
wiid: '1234567890',
profId: '100',
verId: '200',
currency: 'GBP',
deals: ['deal-id-100', 'deal-id-200']
},
placementCode: '/19968336/header-bid-tag-1',
sizes: [[300, 250], [300, 600]],
bidId: '23acc48ad47af5',
requestId: '0fb4905b-9456-4152-86be-c6f6d259ba99',
bidderRequestId: '1c56ad30b9b8ca8',
transactionId: '92489f71-1bf2-49a0-adf9-000cea934729'
}
];

let request = spec.buildRequests(multipleBidRequests);
let data = JSON.parse(request.data);
// case 1 - deals are passed as expected, ['', ''] , in both adUnits
expect(data.imp[0].pmp).to.deep.equal({
'private_auction': 0,
'deals': [
{
'id': 'deal-id-1'
},
{
'id': 'deal-id-2'
}
]
});
expect(data.imp[1].pmp).to.deep.equal({
'private_auction': 0,
'deals': [
{
'id': 'deal-id-100'
},
{
'id': 'deal-id-200'
}
]
});

// case 2 - deals not present in adunit[0]
delete multipleBidRequests[0].params.deals;
request = spec.buildRequests(multipleBidRequests);
data = JSON.parse(request.data);
expect(data.imp[0].pmp).to.not.exist;

// case 3 - deals is present in adunit[0], but is not an array
multipleBidRequests[0].params.deals = 123;
request = spec.buildRequests(multipleBidRequests);
data = JSON.parse(request.data);
expect(data.imp[0].pmp).to.not.exist;

// case 4 - deals is present in adunit[0] as an array but one of the value is not a string
multipleBidRequests[0].params.deals = [123, 'deal-id-1'];
request = spec.buildRequests(multipleBidRequests);
data = JSON.parse(request.data);
expect(data.imp[0].pmp).to.deep.equal({
'private_auction': 0,
'deals': [
{
'id': 'deal-id-1'
}
]
});
});

describe('Request param bcat checking', function() {
let multipleBidRequests = [
{
Expand Down

0 comments on commit 38dd94a

Please sign in to comment.