Skip to content

Commit

Permalink
Remove hard string req, just convert instead (#6160)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertrmartinez committed Jan 5, 2021
1 parent 0fc9e23 commit 56d9930
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
8 changes: 6 additions & 2 deletions modules/rubiconAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,12 @@ function getUtmParams() {
function getFpkvs() {
rubiConf.fpkvs = Object.assign((rubiConf.fpkvs || {}), getUtmParams());

const isValid = rubiConf.fpkvs && typeof rubiConf.fpkvs === 'object' && Object.keys(rubiConf.fpkvs).every(key => typeof rubiConf.fpkvs[key] === 'string');
return isValid ? rubiConf.fpkvs : {};
// convert all values to strings
Object.keys(rubiConf.fpkvs).forEach(key => {
rubiConf.fpkvs[key] = rubiConf.fpkvs[key] + '';
});

return rubiConf.fpkvs;
}

let samplingFactor = 1;
Expand Down
28 changes: 28 additions & 0 deletions test/spec/modules/rubiconAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,34 @@ describe('rubicon analytics adapter', function () {
expect(message).to.deep.equal(expectedMessage);
});

it('should convert kvs to strings before sending', function () {
config.setConfig({rubicon: {
fpkvs: {
number: 24,
boolean: false,
string: 'hello',
array: ['one', 2, 'three'],
object: {one: 'two'}
}
}});
performStandardAuction();
expect(server.requests.length).to.equal(1);
let request = server.requests[0];
let message = JSON.parse(request.requestBody);
validate(message);

let expectedMessage = utils.deepClone(ANALYTICS_MESSAGE);
expectedMessage.session.pvid = STUBBED_UUID.slice(0, 8);
expectedMessage.fpkvs = [
{key: 'number', value: '24'},
{key: 'boolean', value: 'false'},
{key: 'string', value: 'hello'},
{key: 'array', value: 'one,2,three'},
{key: 'object', value: '[object Object]'}
]
expect(message).to.deep.equal(expectedMessage);
});

it('should use the query utm param rubicon kv value and pass updated kv and pvid when defined', function () {
sandbox.stub(utils, 'getWindowLocation').returns({'search': '?utm_source=other', 'pbjs_debug': 'true'});

Expand Down

0 comments on commit 56d9930

Please sign in to comment.