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

FTRACK USER ID MODULE: tweaking the createEidsArray() method to accept two schema patterns #9123

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
37 changes: 28 additions & 9 deletions modules/ftrackIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,39 @@ export const ftrackIdSubmodule = {
* similar to the module name and ending in id or Id
*/
decode (value, config) {
if (!value) { return }
const ext = {}
if (!value) {
return;
};

for (var key in value) {
/** unpack the strings from the arrays */
ext[key] = value[key][0]
const DECODE_RESPONSE = {
ftrackId: {
uid: '',
ext: {}
}
}

return {
ftrackId: {
uid: value.DeviceID && value.DeviceID[0],
ext
// Loop over the value's properties:
// -- if string, assign value as is.
// -- if array, convert to string then assign value.
// -- If neither type, assign value as empty string
for (var key in value) {
let keyValue = value[key];
if (Array.isArray(keyValue)) {
keyValue = keyValue.join('|');
} else if (typeof value[key] !== 'string') {
// Unexpected value type, should be string or array
keyValue = '';
}

DECODE_RESPONSE.ftrackId.ext[key] = keyValue;
}

// If we have DeviceId value, assign it to the uid property
if (DECODE_RESPONSE.ftrackId.ext.hasOwnProperty('DeviceID')) {
DECODE_RESPONSE.ftrackId.uid = DECODE_RESPONSE.ftrackId.ext.DeviceID;
}

return DECODE_RESPONSE;
},

/**
Expand Down
18 changes: 7 additions & 11 deletions modules/userId/eids.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,17 +419,12 @@ export function createEidsArray(bidRequestUserId) {
if (subModuleKey === 'pubProvidedId') {
eids = eids.concat(bidRequestUserId['pubProvidedId']);
} else if (subModuleKey === 'ftrackId') {
// ftrack has multiple IDs so we add each one that exists
let eid = {
'atype': 1,
'id': (bidRequestUserId.ftrackId.DeviceID || []).join('|'),
'ext': {}
}
for (let id in bidRequestUserId.ftrackId) {
eid.ext[id] = (bidRequestUserId.ftrackId[id] || []).join('|');
}

eids.push(eid);
// Schema based on the return value of ftrack decode() method
eids.push({
atype: 1,
ext: bidRequestUserId.ftrackId.ext,
id: bidRequestUserId.ftrackId.uid
});
} else if (Array.isArray(bidRequestUserId[subModuleKey])) {
bidRequestUserId[subModuleKey].forEach((config, index, arr) => {
const eid = createEidObject(config, subModuleKey);
Expand All @@ -446,6 +441,7 @@ export function createEidsArray(bidRequestUserId) {
}
}
}

return eids;
}

Expand Down
18 changes: 11 additions & 7 deletions test/spec/modules/eids_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,11 +444,15 @@ describe('eids array generation for known sub-modules', function() {

describe('ftrackId', () => {
it('should return the correct EID schema', () => {
// This is the schema returned from the ftrack decode() method
expect(createEidsArray({
ftrackId: {
DeviceID: ['aaa', 'bbb'],
SingleDeviceID: ['ccc', 'ddd'],
HHID: ['eee', 'fff']
uid: 'test-device-id',
ext: {
DeviceID: 'test-device-id',
SingleDeviceID: 'test-single-device-id',
HHID: 'test-household-id'
}
},
foo: {
bar: 'baz'
Expand All @@ -458,11 +462,11 @@ describe('eids array generation for known sub-modules', function() {
}
})).to.deep.equal([{
atype: 1,
id: 'aaa|bbb',
id: 'test-device-id',
ext: {
DeviceID: 'aaa|bbb',
SingleDeviceID: 'ccc|ddd',
HHID: 'eee|fff'
DeviceID: 'test-device-id',
SingleDeviceID: 'test-single-device-id',
HHID: 'test-household-id'
}
}]);
});
Expand Down
Loading