Skip to content

Commit f14229a

Browse files
authored
SharedIdSystem: add configurable inserter (#12664)
1 parent 634ff5d commit f14229a

File tree

4 files changed

+55
-4
lines changed

4 files changed

+55
-4
lines changed

modules/sharedIdSystem.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,15 @@ export const sharedIdSystemSubmodule = {
183183

184184
domainOverride: domainOverrideToRootDomain(storage, 'sharedId'),
185185
eids: {
186-
'pubcid': {
187-
source: 'pubcid.org',
188-
atype: 1
186+
'pubcid'(values, config) {
187+
const eid = {
188+
source: 'pubcid.org',
189+
uids: values.map(id => ({id, atype: 1}))
190+
}
191+
if (config?.params?.inserter != null) {
192+
eid.inserter = config.params.inserter;
193+
}
194+
return eid;
189195
},
190196
}
191197
};

modules/userId/eids.js

+2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ export function createEidsArray(bidRequestUserId, eidConfigs = EID_CONFIG) {
6161
if (!Array.isArray(eids)) {
6262
eids = [eids];
6363
}
64+
eids.forEach(eid => eid.uids = eid.uids.filter(({id}) => isStr(id)))
65+
eids = eids.filter(({uids}) => uids?.length > 0);
6466
} catch (e) {
6567
logError(`Could not generate EID for "${name}"`, e);
6668
}

test/spec/modules/sharedIdSystem_spec.js

+25-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import {sharedIdSystemSubmodule, storage} from 'modules/sharedIdSystem.js';
22
import {coppaDataHandler} from 'src/adapterManager';
3+
import {config} from 'src/config.js';
34

45
import sinon from 'sinon';
56
import * as utils from 'src/utils.js';
67
import {createEidsArray} from '../../../modules/userId/eids.js';
7-
import {attachIdSystem} from '../../../modules/userId/index.js';
8+
import {attachIdSystem, init} from '../../../modules/userId/index.js';
9+
import {getGlobal} from '../../../src/prebidGlobal.js';
810

911
let expect = require('chai').expect;
1012

@@ -97,6 +99,9 @@ describe('SharedId System', function () {
9799
before(() => {
98100
attachIdSystem(sharedIdSystemSubmodule);
99101
});
102+
afterEach(() => {
103+
config.resetConfig();
104+
});
100105
it('pubCommonId', function() {
101106
const userId = {
102107
pubcid: 'some-random-id-value'
@@ -108,5 +113,24 @@ describe('SharedId System', function () {
108113
uids: [{id: 'some-random-id-value', atype: 1}]
109114
});
110115
});
116+
117+
it('should set inserter, if provided in config', async () => {
118+
config.setConfig({
119+
userSync: {
120+
userIds: [{
121+
name: 'sharedId',
122+
params: {
123+
inserter: 'mock-inserter'
124+
},
125+
value: {pubcid: 'mock-id'}
126+
}]
127+
}
128+
});
129+
const eids = getGlobal().getUserIdsAsEids();
130+
sinon.assert.match(eids[0], {
131+
source: 'pubcid.org',
132+
inserter: 'mock-inserter'
133+
})
134+
})
111135
})
112136
});

test/spec/modules/userId_spec.js

+19
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,25 @@ describe('User ID', function () {
479479
]);
480480
});
481481

482+
it('should filter out non-string uid returned by generator functions', () => {
483+
const eids = createEidsArray({
484+
mockId2v3: [null, 'id1', 123],
485+
});
486+
expect(eids[0].uids).to.eql([
487+
{
488+
atype: 2,
489+
id: 'id1'
490+
}
491+
]);
492+
});
493+
494+
it('should filter out entire EID if none of the uids are strings', () => {
495+
const eids = createEidsArray({
496+
mockId2v3: [null],
497+
});
498+
expect(eids).to.eql([]);
499+
})
500+
482501
it('should group UIDs by everything except uid', () => {
483502
const eids = createEidsArray({
484503
mockId1: ['mock-1-1', 'mock-1-2'],

0 commit comments

Comments
 (0)