Skip to content

Commit

Permalink
PubMatic: add "acat" parameter (prebid#8246)
Browse files Browse the repository at this point in the history
* Passing acat array to translator call

* Merged acat fields from all slots and filtered unique values

* Renamed function name

* Considered ortb2 config to set acat params for translator request

* Added ortb2.bcat with bid.params.bcat before sending to request

Co-authored-by: Kapil Tuptewar <[email protected]>
  • Loading branch information
kapil-tuptewar and Kapil Tuptewar authored Apr 20, 2022
1 parent 19aba79 commit f40d1d6
Show file tree
Hide file tree
Showing 2 changed files with 163 additions and 2 deletions.
36 changes: 34 additions & 2 deletions modules/pubmaticBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,25 @@ function _blockedIabCategoriesValidation(payload, blockedIabCategories) {
}
}

function _allowedIabCategoriesValidation(payload, allowedIabCategories) {
allowedIabCategories = allowedIabCategories
.filter(function(category) {
if (typeof category === 'string') { // returns only strings
return true;
} else {
logWarn(LOG_WARN_PREFIX + 'acat: Each category should be a string, ignoring category: ' + category);
return false;
}
})
.map(category => category.trim()) // trim all categories
.filter((category, index, arr) => arr.indexOf(category) === index); // return unique values only

if (allowedIabCategories.length > 0) {
logWarn(LOG_WARN_PREFIX + 'acat: Selected: ', allowedIabCategories);
payload.ext.acat = allowedIabCategories;
}
}

function _assignRenderer(newBid, request) {
let bidParams, context, adUnitCode;
if (request.bidderRequest && request.bidderRequest.bids) {
Expand Down Expand Up @@ -1082,6 +1101,7 @@ export const spec = {
var dctrArr = [];
var bid;
var blockedIabCategories = [];
var allowedIabCategories = [];

validBidRequests.forEach(originalBid => {
bid = deepClone(originalBid);
Expand Down Expand Up @@ -1113,6 +1133,9 @@ export const spec = {
if (bid.params.hasOwnProperty('bcat') && isArray(bid.params.bcat)) {
blockedIabCategories = blockedIabCategories.concat(bid.params.bcat);
}
if (bid.params.hasOwnProperty('acat') && isArray(bid.params.acat)) {
allowedIabCategories = allowedIabCategories.concat(bid.params.acat);
}
var impObj = _createImpressionObject(bid, conf);
if (impObj) {
payload.imp.push(impObj);
Expand Down Expand Up @@ -1182,7 +1205,7 @@ export const spec = {
}

_handleEids(payload, validBidRequests);
_blockedIabCategoriesValidation(payload, blockedIabCategories);

_handleFlocId(payload, validBidRequests);
// First Party Data
const commonFpd = config.getConfig('ortb2') || {};
Expand All @@ -1192,7 +1215,16 @@ export const spec = {
if (commonFpd.user) {
mergeDeep(payload, {user: commonFpd.user});
}

if (commonFpd.bcat) {
blockedIabCategories = blockedIabCategories.concat(commonFpd.bcat)
}
if (commonFpd.ext?.prebid?.bidderparams?.[bidderRequest.bidderCode]?.acat) {
const acatParams = commonFpd.ext.prebid.bidderparams[bidderRequest.bidderCode].acat;
_allowedIabCategoriesValidation(payload, acatParams);
} else if (allowedIabCategories.length) {
_allowedIabCategoriesValidation(payload, allowedIabCategories);
}
_blockedIabCategoriesValidation(payload, blockedIabCategories);
// Note: Do not move this block up
// if site object is set in Prebid config then we need to copy required fields from site into app and unset the site object
if (typeof config.getConfig('app') === 'object') {
Expand Down
129 changes: 129 additions & 0 deletions test/spec/modules/pubmaticBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3130,6 +3130,115 @@ describe('PubMatic adapter', function () {
});
});

describe('Request param acat checking', 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',
dctr: 'key1=val1|key2=val2,!val3'
},
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',
dctr: 'key1=val3|key2=val1,!val3|key3=val123'
},
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'
}
];

it('acat: pass only strings', function() {
multipleBidRequests[0].params.acat = [1, 2, 3, 'IAB1', 'IAB2'];
let request = spec.buildRequests(multipleBidRequests, {
auctionId: 'new-auction-id'
});
let data = JSON.parse(request.data);
expect(data.ext.acat).to.exist.and.to.deep.equal(['IAB1', 'IAB2']);
});

it('acat: trim the strings', function() {
multipleBidRequests[0].params.acat = [' IAB1 ', ' IAB2 '];
let request = spec.buildRequests(multipleBidRequests, {
auctionId: 'new-auction-id'
});
let data = JSON.parse(request.data);
expect(data.ext.acat).to.exist.and.to.deep.equal(['IAB1', 'IAB2']);
});

it('acat: pass only unique strings', function() {
multipleBidRequests[0].params.acat = ['IAB1', 'IAB2', 'IAB1', 'IAB2', 'IAB1', 'IAB2'];
multipleBidRequests[1].params.acat = ['IAB1', 'IAB2', 'IAB1', 'IAB2', 'IAB1', 'IAB3'];
let request = spec.buildRequests(multipleBidRequests, {
auctionId: 'new-auction-id'
});
let data = JSON.parse(request.data);
expect(data.ext.acat).to.exist.and.to.deep.equal(['IAB1', 'IAB2', 'IAB3']);
});
it('ortb2.ext.prebid.bidderparams.pubmatic.acat should be passed in request payload', function() {
let sandbox = sinon.sandbox.create();
sandbox.stub(config, 'getConfig').callsFake(key => {
const config = {
'ortb2': {
ext: {
prebid: {
bidderparams: {
pubmatic: {
acat: ['IAB1', 'IAB2', 'IAB1', 'IAB2', 'IAB1', 'IAB2']
}
}
}
}
}
};
return config[key];
});
const request = spec.buildRequests(bidRequests, {
auctionId: 'new-auction-id',
bidderCode: 'pubmatic'
});
let data = JSON.parse(request.data);
expect(data.ext.acat).to.deep.equal(['IAB1', 'IAB2']);
sandbox.restore();
});
});

describe('Request param bcat checking', function() {
let multipleBidRequests = [
{
Expand Down Expand Up @@ -3231,6 +3340,26 @@ describe('PubMatic adapter', function () {
});
let data = JSON.parse(request.data);
expect(data.bcat).to.deep.equal(undefined);
});

it('ortb2.bcat should merged with slot level bcat param', function() {
multipleBidRequests[0].params.bcat = ['IAB-1', 'IAB-2'];
let sandbox = sinon.sandbox.create();
sandbox.stub(config, 'getConfig').callsFake(key => {
const config = {
'ortb2': {
bcat: ['IAB-3', 'IAB-4']
}
};
return config[key];
});
const request = spec.buildRequests(multipleBidRequests, {
auctionId: 'new-auction-id',
bidderCode: 'pubmatic'
});
let data = JSON.parse(request.data);
expect(data.bcat).to.deep.equal(['IAB-1', 'IAB-2', 'IAB-3', 'IAB-4']);
sandbox.restore();
});
});

Expand Down

0 comments on commit f40d1d6

Please sign in to comment.