diff --git a/modules/userId/index.js b/modules/userId/index.js index 4a5c570331f..5de8ad75978 100644 --- a/modules/userId/index.js +++ b/modules/userId/index.js @@ -382,6 +382,16 @@ function getUserIds() { return getCombinedSubmoduleIds(initializedSubmodules); } +/** + * 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. + * Simple use case will be passing these UserIds to A9 wrapper solution + */ +function getUserIdsAsEids() { + // initialize submodules only when undefined + initializeSubmodulesAndExecuteCallbacks(); + return createEidsArray(getCombinedSubmoduleIds(initializedSubmodules)); +} + /** * This hook returns updated list of submodules which are allowed to do get user id based on TCF 2 enforcement rules configured */ @@ -576,6 +586,7 @@ export function init(config) { // exposing getUserIds function in global-name-space so that userIds stored in Prebid can be used by external codes. (getGlobal()).getUserIds = getUserIds; + (getGlobal()).getUserIdsAsEids = getUserIdsAsEids; } // init config update listener to start the application diff --git a/test/spec/modules/userId_spec.js b/test/spec/modules/userId_spec.js index 41c4841926a..b48d0a9a98c 100644 --- a/test/spec/modules/userId_spec.js +++ b/test/spec/modules/userId_spec.js @@ -7,10 +7,12 @@ import { syncDelay, coreStorage } from 'modules/userId/index.js'; +import {createEidsArray} from 'modules/userId/eids.js'; import {config} from 'src/config.js'; import * as utils from 'src/utils.js'; import events from 'src/events.js'; import CONSTANTS from 'src/constants.json'; +import {getGlobal} from 'src/prebidGlobal.js'; import {unifiedIdSubmodule} from 'modules/unifiedIdSystem.js'; import {pubCommonIdSubmodule} from 'modules/pubCommonIdSystem.js'; import {britepoolIdSubmodule} from 'modules/britepoolIdSystem.js'; @@ -233,6 +235,36 @@ describe('User ID', function() { }); expect(coreStorage.setCookie.callCount).to.equal(0); }); + + it('pbjs.getUserIds', function() { + setSubmoduleRegistry([pubCommonIdSubmodule]); + init(config); + config.setConfig({ + userSync: { + syncDelay: 0, + userIds: [{ + name: 'pubCommonId', value: {'pubcid': '11111'} + }] + } + }); + expect(typeof (getGlobal()).getUserIds).to.equal('function'); + expect((getGlobal()).getUserIds()).to.deep.equal({pubcid: '11111'}); + }); + + it('pbjs.getUserIdsAsEids', function() { + setSubmoduleRegistry([pubCommonIdSubmodule]); + init(config); + config.setConfig({ + userSync: { + syncDelay: 0, + userIds: [{ + name: 'pubCommonId', value: {'pubcid': '11111'} + }] + } + }); + expect(typeof (getGlobal()).getUserIdsAsEids).to.equal('function'); + expect((getGlobal()).getUserIdsAsEids()).to.deep.equal(createEidsArray((getGlobal()).getUserIds())); + }); }); describe('Opt out', function () {