Skip to content

Commit

Permalink
FTRACK USER ID MODULE: tweaking the createEidsArray() method to accep…
Browse files Browse the repository at this point in the history
…t two schema patterns (prebid#9123)

* JDB-563: tweaking the createEidsArray() method to accept two schema patterns

* JDB-563: further cleanup now that I understand the the decode method should be used to prepare the data

* JDB-563: adding shortcircuit back into decode method

Co-authored-by: Jason Lydon <jason.lydon@flashtalking.com>
  • Loading branch information
2 people authored and jorgeluisrocha committed May 18, 2023
1 parent 8fe1874 commit d307cbf
Show file tree
Hide file tree
Showing 4 changed files with 246 additions and 117 deletions.
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

0 comments on commit d307cbf

Please sign in to comment.