Skip to content

Commit 7557fbf

Browse files
pm-harshad-maneiggyfisk
authored andcommitted
UserId module to export user ids as eids with pbjs.getUserIdsAsEids() (prebid#5108)
* added support for pubcommon, digitrust, id5id * added support for IdentityLink * changed the source for id5 * added unit test cases * changed source param for identityLink * exposing a new function to export userIds in Eids format * added test cases for functions that export userIds * added the missing semicolon :-)
1 parent 0b7362c commit 7557fbf

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

modules/userId/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,16 @@ function getUserIds() {
382382
return getCombinedSubmoduleIds(initializedSubmodules);
383383
}
384384

385+
/**
386+
* This function will be exposed in global-name-space so that userIds stored by Prebid UserId module can be used by external codes as well.
387+
* Simple use case will be passing these UserIds to A9 wrapper solution
388+
*/
389+
function getUserIdsAsEids() {
390+
// initialize submodules only when undefined
391+
initializeSubmodulesAndExecuteCallbacks();
392+
return createEidsArray(getCombinedSubmoduleIds(initializedSubmodules));
393+
}
394+
385395
/**
386396
* This hook returns updated list of submodules which are allowed to do get user id based on TCF 2 enforcement rules configured
387397
*/
@@ -576,6 +586,7 @@ export function init(config) {
576586

577587
// exposing getUserIds function in global-name-space so that userIds stored in Prebid can be used by external codes.
578588
(getGlobal()).getUserIds = getUserIds;
589+
(getGlobal()).getUserIdsAsEids = getUserIdsAsEids;
579590
}
580591

581592
// init config update listener to start the application

test/spec/modules/userId_spec.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ import {
77
syncDelay,
88
coreStorage
99
} from 'modules/userId/index.js';
10+
import {createEidsArray} from 'modules/userId/eids.js';
1011
import {config} from 'src/config.js';
1112
import * as utils from 'src/utils.js';
1213
import events from 'src/events.js';
1314
import CONSTANTS from 'src/constants.json';
15+
import {getGlobal} from 'src/prebidGlobal.js';
1416
import {unifiedIdSubmodule} from 'modules/unifiedIdSystem.js';
1517
import {pubCommonIdSubmodule} from 'modules/pubCommonIdSystem.js';
1618
import {britepoolIdSubmodule} from 'modules/britepoolIdSystem.js';
@@ -233,6 +235,36 @@ describe('User ID', function() {
233235
});
234236
expect(coreStorage.setCookie.callCount).to.equal(0);
235237
});
238+
239+
it('pbjs.getUserIds', function() {
240+
setSubmoduleRegistry([pubCommonIdSubmodule]);
241+
init(config);
242+
config.setConfig({
243+
userSync: {
244+
syncDelay: 0,
245+
userIds: [{
246+
name: 'pubCommonId', value: {'pubcid': '11111'}
247+
}]
248+
}
249+
});
250+
expect(typeof (getGlobal()).getUserIds).to.equal('function');
251+
expect((getGlobal()).getUserIds()).to.deep.equal({pubcid: '11111'});
252+
});
253+
254+
it('pbjs.getUserIdsAsEids', function() {
255+
setSubmoduleRegistry([pubCommonIdSubmodule]);
256+
init(config);
257+
config.setConfig({
258+
userSync: {
259+
syncDelay: 0,
260+
userIds: [{
261+
name: 'pubCommonId', value: {'pubcid': '11111'}
262+
}]
263+
}
264+
});
265+
expect(typeof (getGlobal()).getUserIdsAsEids).to.equal('function');
266+
expect((getGlobal()).getUserIdsAsEids()).to.deep.equal(createEidsArray((getGlobal()).getUserIds()));
267+
});
236268
});
237269

238270
describe('Opt out', function () {

0 commit comments

Comments
 (0)