diff --git a/modules/pairIdSystem.js b/modules/pairIdSystem.js index 778857bae1c..1d9f2c92203 100644 --- a/modules/pairIdSystem.js +++ b/modules/pairIdSystem.js @@ -16,7 +16,10 @@ import {MODULE_TYPE_UID} from '../src/activities/modules.js'; const MODULE_NAME = 'pairId'; const PAIR_ID_KEY = 'pairId'; -const DEFAULT_LIVERAMP_PAIR_ID_KEY = '_lr_pairId'; + +const DEFAULT_STORAGE_PAID_ID_KEYS = { + liveramp: '_lr_pairId' +}; export const storage = getStorageManager({moduleType: MODULE_TYPE_UID, moduleName: MODULE_NAME}); @@ -59,6 +62,7 @@ export const pairIdSubmodule = { getId(config) { const pairIdsString = pairIdFromLocalStorage(PAIR_ID_KEY) || pairIdFromCookie(PAIR_ID_KEY) let ids = [] + if (pairIdsString && typeof pairIdsString == 'string') { try { ids = ids.concat(JSON.parse(atob(pairIdsString))) @@ -67,14 +71,20 @@ export const pairIdSubmodule = { } } - const configParams = (config && config.params) || {}; - if (configParams && configParams.liveramp) { - let LRStorageLocation = configParams.liveramp.storageKey || DEFAULT_LIVERAMP_PAIR_ID_KEY; - const liverampValue = pairIdFromLocalStorage(LRStorageLocation) || pairIdFromCookie(LRStorageLocation); + const configParams = (config && config.params) ? config.params : {}; + const cleanRooms = Object.keys(configParams); + + for (let i = 0; i < cleanRooms.length; i++) { + const cleanRoom = cleanRooms[i]; + const cleanRoomParams = configParams[cleanRoom]; - if (liverampValue) { + const cleanRoomStorageLocation = cleanRoomParams.storageKey || DEFAULT_STORAGE_PAID_ID_KEYS[cleanRoom]; + const cleanRoomValue = pairIdFromLocalStorage(cleanRoomStorageLocation) || pairIdFromCookie(cleanRoomStorageLocation); + + if (cleanRoomValue) { try { - const parsedValue = atob(liverampValue); + const parsedValue = atob(cleanRoomValue); + if (parsedValue) { const obj = JSON.parse(parsedValue); @@ -90,7 +100,7 @@ export const pairIdSubmodule = { logInfo('Pairid: Error parsing JSON: ', error); } } else { - logInfo('Pairid: liverampValue for pairId from storage is empty or null'); + logInfo('Pairid: data clean room value for pairId from storage is empty or null'); } } @@ -98,11 +108,12 @@ export const pairIdSubmodule = { logInfo('PairId not found.') return undefined; } + return {'id': ids}; }, eids: { 'pairId': { - source: 'google.com', + source: 'iabtechlab.com', atype: 571187 }, } diff --git a/test/spec/modules/pairIdSystem_spec.js b/test/spec/modules/pairIdSystem_spec.js index 0bb42e56c25..a8f7dffd6ce 100644 --- a/test/spec/modules/pairIdSystem_spec.js +++ b/test/spec/modules/pairIdSystem_spec.js @@ -13,6 +13,39 @@ describe('pairId', function () { sandbox.restore(); }); + it('should read pairId from specified clean room if configured with storageKey', function() { + let pairIds = ['test-pair-id1', 'test-pair-id2', 'test-pair-id3']; + sandbox.stub(storage, 'getDataFromLocalStorage').withArgs('habu_pairId_custom').returns(btoa(JSON.stringify({'envelope': pairIds}))); + + let id = pairIdSubmodule.getId({ + params: { + habu: { + storageKey: 'habu_pairId_custom' + } + }}) + + expect(id).to.be.deep.equal({id: pairIds}); + }) + + it('should read pairID from liveramp with default storageKey and additional clean room with configured storageKey', function() { + let getDataStub = sandbox.stub(storage, 'getDataFromLocalStorage'); + let liveRampPairIds = ['lr-test-pair-id1', 'lr-test-pair-id2', 'lr-test-pair-id3']; + getDataStub.withArgs('_lr_pairId').returns(btoa(JSON.stringify({'envelope': liveRampPairIds}))); + + let habuPairIds = ['habu-test-pair-id1', 'habu-test-pair-id2', 'habu-test-pair-id3']; + getDataStub.withArgs('habu_pairId_custom').returns(btoa(JSON.stringify({'envelope': habuPairIds}))); + + let id = pairIdSubmodule.getId({ + params: { + habu: { + storageKey: 'habu_pairId_custom' + }, + liveramp: {} + }}) + + expect(id).to.be.deep.equal({id: habuPairIds.concat(liveRampPairIds)}); + }); + it('should log an error if no ID is found when getId', function() { pairIdSubmodule.getId({ params: {} }); expect(logInfoStub.calledOnce).to.be.true;