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

Rubicon Bid Adapter - ordered auction query params #2665

Merged
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
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