Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added keywords parameter to TheMediaGrid Bid Adapter #5353

Merged
merged 15 commits into from
Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions modules/gridBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const spec = {
const slotsMapByUid = {};
const sizeMap = {};
const bids = validBidRequests || [];
let pageKeywords;
let reqId;

bids.forEach(bid => {
Expand All @@ -55,6 +56,15 @@ export const spec = {
auids.push(uid);
const sizesId = utils.parseSizesInput(bid.sizes);

if (!pageKeywords && !utils.isEmpty(bid.params.keywords)) {
const keywords = utils.transformBidderParamKeywords(bid.params.keywords);

if (keywords.length > 0) {
keywords.forEach(deleteValues);
}
pageKeywords = keywords;
}

const addedSizes = {};
sizesId.forEach((sizeId) => {
addedSizes[sizeId] = true;
Expand Down Expand Up @@ -102,6 +112,10 @@ export const spec = {
wrapperVersion: '$prebid.version$'
};

if (pageKeywords) {
payload.keywords = JSON.stringify(pageKeywords);
}

if (bidderRequest) {
if (bidderRequest.refererInfo && bidderRequest.refererInfo.referer) {
payload.u = bidderRequest.refererInfo.referer;
Expand Down Expand Up @@ -180,6 +194,16 @@ export const spec = {
}
};

function isPopulatedArray(arr) {
return !!(utils.isArray(arr) && arr.length > 0);
}

function deleteValues(keyPairObj) {
if (isPopulatedArray(keyPairObj.value) && keyPairObj.value[0] === '') {
delete keyPairObj.value;
}
}

function _getBidFromResponse(respItem) {
if (!respItem) {
utils.logError(LOG_ERROR_MESS.emptySeatbid);
Expand Down
8 changes: 6 additions & 2 deletions modules/gridBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ Grid bid adapter supports Banner and Video (instream and outstream).
bidder: "grid",
params: {
uid: 2,
priceType: 'gross'
priceType: 'gross',
keywords: {
brandsafety: ['disaster'],
topic: ['stress', 'fear']
}
}
}
]
Expand All @@ -51,4 +55,4 @@ Grid bid adapter supports Banner and Video (instream and outstream).
]
}
];
```
```
49 changes: 49 additions & 0 deletions test/spec/modules/gridBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,55 @@ describe('TheMediaGrid Adapter', function () {
const payload = parseRequest(request.data);
expect(payload).to.have.property('us_privacy', '1YNN');
});

it('should convert keyword params to proper form and attaches to request', function () {
const bidRequestWithKeywords = [].concat(bidRequests);
bidRequestWithKeywords[1] = Object.assign({},
bidRequests[1],
{
params: {
uid: '1',
keywords: {
single: 'val',
singleArr: ['val'],
singleArrNum: [3],
multiValMixed: ['value1', 2, 'value3'],
singleValNum: 123,
emptyStr: '',
emptyArr: [''],
badValue: {'foo': 'bar'} // should be dropped
}
}
}
);

const request = spec.buildRequests(bidRequestWithKeywords, bidderRequest);
expect(request.data).to.be.an('string');
const payload = parseRequest(request.data);
expect(payload.keywords).to.be.an('string');
payload.keywords = JSON.parse(payload.keywords);

expect(payload.keywords).to.deep.equal([{
'key': 'single',
'value': ['val']
}, {
'key': 'singleArr',
'value': ['val']
}, {
'key': 'singleArrNum',
'value': ['3']
}, {
'key': 'multiValMixed',
'value': ['value1', '2', 'value3']
}, {
'key': 'singleValNum',
'value': ['123']
}, {
'key': 'emptyStr'
}, {
'key': 'emptyArr'
}]);
});
});

describe('interpretResponse', function () {
Expand Down