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

add custom keyword support for pbs bid adapter #1763

Merged
merged 4 commits into from
Nov 14, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
19 changes: 19 additions & 0 deletions modules/prebidServerBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,25 @@ function PrebidServer() {
}
}
});
// will collect any custom params and place them under bid.params.keywords attribute in the following manner for pbs to ingest properly
// "keywords":[{"key":"randomKey","value":["123456789"]},{"key":"single_test"},{"key":"myMultiVar","value":["myValue","124578"]}]
let kwArray = [];
Object.keys(bid.params).forEach(key => {
if (bid.bidder === 'appnexus' && (key !== 'member' && key !== 'invCode' && key !== 'placementId')) {
let kvObj = {};
kvObj.key = key
if (bid.params[key] !== null) {
if (Array.isArray(bid.params[key])) {
kvObj.value = bid.params[key].map(val => tryConvertString(val));
} else {
kvObj.value = [tryConvertString(bid.params[key])];
}
}
kwArray.push(kvObj);
delete bid.params[key];
}
});
bid.params.keywords = kwArray;
});
});
}
Expand Down
7 changes: 6 additions & 1 deletion test/spec/modules/prebidServerBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ const REQUEST = {
'bidder': 'appnexus',
'params': {
'placementId': '10433394',
'member': 123
'member': 123,
'randomKey': 123456789,
'single_test': null,
'myMultiVar': ['myValue', 124578]
}
}
]
Expand Down Expand Up @@ -201,6 +204,8 @@ describe('S2S Adapter', () => {
const requestBid = JSON.parse(requests[0].requestBody);
expect(requestBid.ad_units[0].bids[0].params.placementId).to.exist.and.to.be.a('number');
expect(requestBid.ad_units[0].bids[0].params.member).to.exist.and.to.be.a('string');
expect(requestBid.ad_units[0].bids[0].params.keywords).to.exist.and.to.be.an('array').and.to.have.lengthOf(3);
expect(requestBid.ad_units[0].bids[0].params.keywords[0]).to.be.an('object').that.has.all.keys('key', 'value');
});
});

Expand Down