From 566701d6a087c41cdded8c463ed3996c9c4c606a Mon Sep 17 00:00:00 2001 From: Isaac Dettman Date: Thu, 31 May 2018 14:17:17 -0700 Subject: [PATCH 1/8] ordered ae query params --- modules/rubiconBidAdapter.js | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/modules/rubiconBidAdapter.js b/modules/rubiconBidAdapter.js index 46d53e22ab7..2da2b6e1ace 100644 --- a/modules/rubiconBidAdapter.js +++ b/modules/rubiconBidAdapter.js @@ -225,11 +225,42 @@ export const spec = { const combinedSlotParams = spec.combineSlotUrlParams(bidsInGroup.map(bidRequest => { return spec.createSlotParams(bidRequest, bidderRequest); })); + + const orderedParams = [ + 'account_id', + 'site_id', + 'zone_id', + 'size_id', + 'alt_size_ids', + 'p_pos', + 'gdpr', + 'gdpr_consent', + 'rf', + 'dt.id', + 'dt.keyv', + 'dt.pref', + 'latitude', + 'longitude', + 'kw' + ].concat(Object.keys(combinedSlotParams).filter(item => (item.indexOf('tg_v') !== -1))) + .concat(Object.keys(combinedSlotParams).filter(item => (item.indexOf('tg_i') !== -1))) + .concat([ + 'tk_flint', + 'x_source.tid', + 'p_screen_res', + 'rp_floor', + 'rp_secure', + 'tk_user_key' + ]); + + const unorderedParams = Object.keys(combinedSlotParams).filter(item => (orderedParams.indexOf(item) === -1)) + + // SRA request returns grouped bidRequest arrays not a plain bidRequest return { method: 'GET', url: FASTLANE_ENDPOINT, - data: Object.keys(combinedSlotParams).reduce((paramString, key) => { + data: orderedParams.concat(unorderedParams).reduce((paramString, key) => { const propValue = combinedSlotParams[key]; return ((utils.isStr(propValue) && propValue !== '') || utils.isNumber(propValue)) ? `${paramString}${key}=${encodeURIComponent(propValue)}&` : paramString; }, '') + `slots=${bidsInGroup.length}&rand=${Math.random()}`, From 7ec3650789e20fcae0448b4507151b793eba9c89 Mon Sep 17 00:00:00 2001 From: Isaac Dettman Date: Thu, 31 May 2018 14:27:02 -0700 Subject: [PATCH 2/8] updated tg_v and tg_i filter strings --- modules/rubiconBidAdapter.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/rubiconBidAdapter.js b/modules/rubiconBidAdapter.js index 2da2b6e1ace..846f651d5e2 100644 --- a/modules/rubiconBidAdapter.js +++ b/modules/rubiconBidAdapter.js @@ -242,8 +242,8 @@ export const spec = { 'latitude', 'longitude', 'kw' - ].concat(Object.keys(combinedSlotParams).filter(item => (item.indexOf('tg_v') !== -1))) - .concat(Object.keys(combinedSlotParams).filter(item => (item.indexOf('tg_i') !== -1))) + ].concat(Object.keys(combinedSlotParams).filter(item => (item.indexOf('tg_v.') !== -1))) + .concat(Object.keys(combinedSlotParams).filter(item => (item.indexOf('tg_i.') !== -1))) .concat([ 'tk_flint', 'x_source.tid', From 9171ec8849526153ec7d609cac22c79400103938 Mon Sep 17 00:00:00 2001 From: Isaac Dettman Date: Thu, 31 May 2018 14:29:00 -0700 Subject: [PATCH 3/8] linting fix --- modules/rubiconBidAdapter.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/modules/rubiconBidAdapter.js b/modules/rubiconBidAdapter.js index 846f651d5e2..1615768fe3d 100644 --- a/modules/rubiconBidAdapter.js +++ b/modules/rubiconBidAdapter.js @@ -243,19 +243,18 @@ export const spec = { 'longitude', 'kw' ].concat(Object.keys(combinedSlotParams).filter(item => (item.indexOf('tg_v.') !== -1))) - .concat(Object.keys(combinedSlotParams).filter(item => (item.indexOf('tg_i.') !== -1))) - .concat([ - 'tk_flint', - 'x_source.tid', - 'p_screen_res', - 'rp_floor', - 'rp_secure', - 'tk_user_key' - ]); + .concat(Object.keys(combinedSlotParams).filter(item => (item.indexOf('tg_i.') !== -1))) + .concat([ + 'tk_flint', + 'x_source.tid', + 'p_screen_res', + 'rp_floor', + 'rp_secure', + 'tk_user_key' + ]); const unorderedParams = Object.keys(combinedSlotParams).filter(item => (orderedParams.indexOf(item) === -1)) - // SRA request returns grouped bidRequest arrays not a plain bidRequest return { method: 'GET', From 347f655adcb1148e7b92fe8bad0c0473c8a7c87a Mon Sep 17 00:00:00 2001 From: Isaac Dettman Date: Thu, 31 May 2018 14:45:08 -0700 Subject: [PATCH 4/8] extracted ordering code to a function --- modules/rubiconBidAdapter.js | 64 +++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/modules/rubiconBidAdapter.js b/modules/rubiconBidAdapter.js index 1615768fe3d..c87696667c6 100644 --- a/modules/rubiconBidAdapter.js +++ b/modules/rubiconBidAdapter.js @@ -197,7 +197,7 @@ export const spec = { return { method: 'GET', url: FASTLANE_ENDPOINT, - data: Object.keys(bidParams).reduce((paramString, key) => { + data: spec.getOrderedParams(bidParams).reduce((paramString, key) => { const propValue = bidParams[key]; return ((utils.isStr(propValue) && propValue !== '') || utils.isNumber(propValue)) ? `${paramString}${key}=${encodeURIComponent(propValue)}&` : paramString; }, '') + `slots=1&rand=${Math.random()}`, @@ -226,40 +226,11 @@ export const spec = { return spec.createSlotParams(bidRequest, bidderRequest); })); - const orderedParams = [ - 'account_id', - 'site_id', - 'zone_id', - 'size_id', - 'alt_size_ids', - 'p_pos', - 'gdpr', - 'gdpr_consent', - 'rf', - 'dt.id', - 'dt.keyv', - 'dt.pref', - 'latitude', - 'longitude', - 'kw' - ].concat(Object.keys(combinedSlotParams).filter(item => (item.indexOf('tg_v.') !== -1))) - .concat(Object.keys(combinedSlotParams).filter(item => (item.indexOf('tg_i.') !== -1))) - .concat([ - 'tk_flint', - 'x_source.tid', - 'p_screen_res', - 'rp_floor', - 'rp_secure', - 'tk_user_key' - ]); - - const unorderedParams = Object.keys(combinedSlotParams).filter(item => (orderedParams.indexOf(item) === -1)) - // SRA request returns grouped bidRequest arrays not a plain bidRequest return { method: 'GET', url: FASTLANE_ENDPOINT, - data: orderedParams.concat(unorderedParams).reduce((paramString, key) => { + data: spec.getOrderedParams(combinedSlotParams).reduce((paramString, key) => { const propValue = combinedSlotParams[key]; return ((utils.isStr(propValue) && propValue !== '') || utils.isNumber(propValue)) ? `${paramString}${key}=${encodeURIComponent(propValue)}&` : paramString; }, '') + `slots=${bidsInGroup.length}&rand=${Math.random()}`, @@ -270,6 +241,37 @@ export const spec = { return requests; }, + getOrderedParams: function(params) { + const orderedParams = [ + 'account_id', + 'site_id', + 'zone_id', + 'size_id', + 'alt_size_ids', + 'p_pos', + 'gdpr', + 'gdpr_consent', + 'rf', + 'dt.id', + 'dt.keyv', + 'dt.pref', + 'latitude', + 'longitude', + 'kw' + ].concat(Object.keys(params).filter(item => (item.indexOf('tg_v.') !== -1))) + .concat(Object.keys(params).filter(item => (item.indexOf('tg_i.') !== -1))) + .concat([ + 'tk_flint', + 'x_source.tid', + 'p_screen_res', + 'rp_floor', + 'rp_secure', + 'tk_user_key' + ]); + + return orderedParams.concat(Object.keys(params).filter(item => (orderedParams.indexOf(item) === -1))); + }, + /** * @summary combines param values from an array of slots into a single semicolon delineated value * or just one value if they are all the same. From 3ea9f96e8a115d51d486c25eef5a54a8755aaa4f Mon Sep 17 00:00:00 2001 From: Isaac Dettman Date: Thu, 31 May 2018 15:22:06 -0700 Subject: [PATCH 5/8] fixed param names for lat long --- modules/rubiconBidAdapter.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/rubiconBidAdapter.js b/modules/rubiconBidAdapter.js index c87696667c6..479f813c317 100644 --- a/modules/rubiconBidAdapter.js +++ b/modules/rubiconBidAdapter.js @@ -255,8 +255,8 @@ export const spec = { 'dt.id', 'dt.keyv', 'dt.pref', - 'latitude', - 'longitude', + 'p_geo.latitude', + 'p_geo.longitude', 'kw' ].concat(Object.keys(params).filter(item => (item.indexOf('tg_v.') !== -1))) .concat(Object.keys(params).filter(item => (item.indexOf('tg_i.') !== -1))) @@ -323,6 +323,8 @@ export const spec = { // use rubicon sizes if provided, otherwise adUnit.sizes const parsedSizes = parseSizes(bidRequest); + const [latitude, longitude] = params.latLong || []; + const data = { 'account_id': params.accountId, 'site_id': params.siteId, @@ -337,6 +339,8 @@ export const spec = { 'p_screen_res': _getScreenResolution(), 'kw': Array.isArray(params.keywords) ? params.keywords.join(',') : '', 'tk_user_key': params.userId, + 'p_geo.latitude': isNaN(parseFloat(latitude)) ? undefined : parseFloat(latitude).toFixed(4), + 'p_geo.longitude': isNaN(parseFloat(longitude)) ? undefined : parseFloat(longitude).toFixed(4), 'tg_fl.eid': bidRequest.code, 'rf': _getPageUrl(bidRequest) }; From e844ba6afd817a0fdf3d502856125fb053d459b6 Mon Sep 17 00:00:00 2001 From: Isaac Dettman Date: Thu, 31 May 2018 15:34:26 -0700 Subject: [PATCH 6/8] Added unit test to check AE param ordering --- test/spec/modules/rubiconBidAdapter_spec.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/spec/modules/rubiconBidAdapter_spec.js b/test/spec/modules/rubiconBidAdapter_spec.js index e6418d715e1..d254423bb0b 100644 --- a/test/spec/modules/rubiconBidAdapter_spec.js +++ b/test/spec/modules/rubiconBidAdapter_spec.js @@ -392,6 +392,17 @@ describe('the rubicon adapter', () => { }); }); + it('ad engine query params should be ordered correctly', () => { + sandbox.stub(Math, 'random').callsFake(() => 0.1); + let [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); + + const referenceOrdering = ['account_id', 'site_id', 'zone_id', 'size_id', 'alt_size_ids', 'p_pos', 'rf', 'p_geo.latitude', 'p_geo.longitude', 'kw', 'tg_v.ucat', 'tg_v.lastsearch', 'tg_i.rating', 'tg_i.prodtype', 'tk_flint', 'x_source.tid', 'p_screen_res', 'rp_floor', 'rp_secure', 'tk_user_key', 'tg_fl.eid', 'slots', 'rand']; + + request.data.split('&').forEach((item, i) => { + expect(item.split('=')[0]).to.equal(referenceOrdering[i]); + }); + }); + it('should make a well-formed request object without latLong', () => { let expectedQuery = { 'account_id': '14062', From fe1ada667dbf126e699114fee6e11ce78f89770c Mon Sep 17 00:00:00 2001 From: Isaac Dettman Date: Sat, 2 Jun 2018 22:44:13 -0700 Subject: [PATCH 7/8] changed test for tg_i and tg_v --- modules/rubiconBidAdapter.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/rubiconBidAdapter.js b/modules/rubiconBidAdapter.js index 479f813c317..10bbf4ba395 100644 --- a/modules/rubiconBidAdapter.js +++ b/modules/rubiconBidAdapter.js @@ -242,6 +242,9 @@ export const spec = { }, getOrderedParams: function(params) { + const containsTgV = /^tg_v/ + const containsTgI = /^tg_i/ + const orderedParams = [ 'account_id', 'site_id', @@ -252,14 +255,15 @@ export const spec = { 'gdpr', 'gdpr_consent', 'rf', + 'rf', 'dt.id', 'dt.keyv', 'dt.pref', 'p_geo.latitude', 'p_geo.longitude', 'kw' - ].concat(Object.keys(params).filter(item => (item.indexOf('tg_v.') !== -1))) - .concat(Object.keys(params).filter(item => (item.indexOf('tg_i.') !== -1))) + ].concat(Object.keys(params).filter(item => containsTgV.test(item))) + .concat(Object.keys(params).filter(item => containsTgI.test(item))) .concat([ 'tk_flint', 'x_source.tid', From cf2cb6946f8db85b621e7e07984856ad6b9879ed Mon Sep 17 00:00:00 2001 From: Isaac Dettman Date: Thu, 7 Jun 2018 14:04:19 -0700 Subject: [PATCH 8/8] fix removed duplicated 'rf' in order params function --- modules/rubiconBidAdapter.js | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/rubiconBidAdapter.js b/modules/rubiconBidAdapter.js index 10bbf4ba395..499cd205d1e 100644 --- a/modules/rubiconBidAdapter.js +++ b/modules/rubiconBidAdapter.js @@ -255,7 +255,6 @@ export const spec = { 'gdpr', 'gdpr_consent', 'rf', - 'rf', 'dt.id', 'dt.keyv', 'dt.pref',