From d04412797b76c9a7293be5443f097dd837d72578 Mon Sep 17 00:00:00 2001 From: Jason Snellbaker Date: Tue, 24 Oct 2017 12:31:44 -0400 Subject: [PATCH 1/3] initial commit to add custom keyword support for pbs adapter --- modules/prebidServerBidAdapter.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/modules/prebidServerBidAdapter.js b/modules/prebidServerBidAdapter.js index 0906a1a0b3d..3edb496fce5 100644 --- a/modules/prebidServerBidAdapter.js +++ b/modules/prebidServerBidAdapter.js @@ -98,6 +98,25 @@ function PrebidServer() { } } }); + // will collect any custom params and place them under bid.params.keywords attribute in the following manner for pbs to injest properly + // "keywords":[{"key":"randomKey","value":["123456789"]},{"key":"single_test"},{"key":"myVar","value":["myValue","124578"]}] + let kw_array = []; + Object.keys(bid.params).forEach(key => { + if (bid.bidder === 'appnexus' && (key !== 'member' && key !== 'invCode' && key !== 'placementId')) { + let kv_obj = {}; + kv_obj.key = key + if (bid.params[key] !== null) { + if (Array.isArray(bid.params[key])) { + kv_obj.value = bid.params[key].map(val => tryConvertString(val)); + } else { + kv_obj.value = [tryConvertString(bid.params[key])]; + } + } + kw_array.push(kv_obj); + delete bid.params[key]; + } + }); + bid.params.keywords = kw_array; }); }); } From ebfdd7520b9e508a257649dadeb0a59bb8448bd4 Mon Sep 17 00:00:00 2001 From: Jason Snellbaker Date: Tue, 24 Oct 2017 14:03:35 -0400 Subject: [PATCH 2/3] fixing small typo --- modules/prebidServerBidAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/prebidServerBidAdapter.js b/modules/prebidServerBidAdapter.js index 3edb496fce5..3c30167d86c 100644 --- a/modules/prebidServerBidAdapter.js +++ b/modules/prebidServerBidAdapter.js @@ -98,7 +98,7 @@ function PrebidServer() { } } }); - // will collect any custom params and place them under bid.params.keywords attribute in the following manner for pbs to injest properly + // 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":"myVar","value":["myValue","124578"]}] let kw_array = []; Object.keys(bid.params).forEach(key => { From c7e31a04ef7faa38c30b2f98a34b5726cca1a129 Mon Sep 17 00:00:00 2001 From: Jason Snellbaker Date: Mon, 13 Nov 2017 13:50:09 -0500 Subject: [PATCH 3/3] modified variable convention and added unit test case --- modules/prebidServerBidAdapter.js | 16 ++++++++-------- test/spec/modules/prebidServerBidAdapter_spec.js | 7 ++++++- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/modules/prebidServerBidAdapter.js b/modules/prebidServerBidAdapter.js index 778401083cc..a4497b52b07 100644 --- a/modules/prebidServerBidAdapter.js +++ b/modules/prebidServerBidAdapter.js @@ -100,24 +100,24 @@ 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":"myVar","value":["myValue","124578"]}] - let kw_array = []; + // "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 kv_obj = {}; - kv_obj.key = key + let kvObj = {}; + kvObj.key = key if (bid.params[key] !== null) { if (Array.isArray(bid.params[key])) { - kv_obj.value = bid.params[key].map(val => tryConvertString(val)); + kvObj.value = bid.params[key].map(val => tryConvertString(val)); } else { - kv_obj.value = [tryConvertString(bid.params[key])]; + kvObj.value = [tryConvertString(bid.params[key])]; } } - kw_array.push(kv_obj); + kwArray.push(kvObj); delete bid.params[key]; } }); - bid.params.keywords = kw_array; + 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'); }); });