diff --git a/modules/prebidServerBidAdapter.js b/modules/prebidServerBidAdapter.js index 7120d67eb56..a4497b52b07 100644 --- a/modules/prebidServerBidAdapter.js +++ b/modules/prebidServerBidAdapter.js @@ -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; }); }); } diff --git a/test/spec/modules/prebidServerBidAdapter_spec.js b/test/spec/modules/prebidServerBidAdapter_spec.js index 78eef4b016b..0403617a846 100644 --- a/test/spec/modules/prebidServerBidAdapter_spec.js +++ b/test/spec/modules/prebidServerBidAdapter_spec.js @@ -43,7 +43,10 @@ const REQUEST = { 'bidder': 'appnexus', 'params': { 'placementId': '10433394', - 'member': 123 + 'member': 123, + 'randomKey': 123456789, + 'single_test': null, + 'myMultiVar': ['myValue', 124578] } } ] @@ -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'); }); });