Skip to content

Commit

Permalink
Rubicon Bid Adapter - ordered auction query params (#2665)
Browse files Browse the repository at this point in the history
* ordered ae query params

* updated tg_v and tg_i filter strings

* linting fix

* extracted ordering code to a function

* fixed param names for lat long

* Added unit test to check AE param ordering

* changed test for tg_i and tg_v

* fix removed duplicated 'rf' in order params function
  • Loading branch information
idettman authored and snapwich committed Jun 7, 2018
1 parent d04127a commit 1c53a2a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
43 changes: 41 additions & 2 deletions modules/rubiconBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()}`,
Expand Down Expand Up @@ -225,11 +225,12 @@ export const spec = {
const combinedSlotParams = spec.combineSlotUrlParams(bidsInGroup.map(bidRequest => {
return spec.createSlotParams(bidRequest, bidderRequest);
}));

// SRA request returns grouped bidRequest arrays not a plain bidRequest
return {
method: 'GET',
url: FASTLANE_ENDPOINT,
data: Object.keys(combinedSlotParams).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()}`,
Expand All @@ -240,6 +241,40 @@ export const spec = {
return requests;
},

getOrderedParams: function(params) {
const containsTgV = /^tg_v/
const containsTgI = /^tg_i/

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',
'p_geo.latitude',
'p_geo.longitude',
'kw'
].concat(Object.keys(params).filter(item => containsTgV.test(item)))
.concat(Object.keys(params).filter(item => containsTgI.test(item)))
.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.
Expand Down Expand Up @@ -291,6 +326,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,
Expand All @@ -305,6 +342,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)
};
Expand Down
11 changes: 11 additions & 0 deletions test/spec/modules/rubiconBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 1c53a2a

Please sign in to comment.