Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SharedIdSystem: add configurable inserter #12664

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions modules/sharedIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,15 @@ export const sharedIdSystemSubmodule = {

domainOverride: domainOverrideToRootDomain(storage, 'sharedId'),
eids: {
'pubcid': {
source: 'pubcid.org',
atype: 1
'pubcid'(values, config) {
const eid = {
source: 'pubcid.org',
uids: values.map(id => ({id, atype: 1}))
}
if (config?.params?.inserter != null) {
eid.inserter = config.params.inserter;
}
return eid;
},
}
};
Expand Down
2 changes: 2 additions & 0 deletions modules/userId/eids.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export function createEidsArray(bidRequestUserId, eidConfigs = EID_CONFIG) {
if (!Array.isArray(eids)) {
eids = [eids];
}
eids.forEach(eid => eid.uids = eid.uids.filter(({id}) => isStr(id)))
eids = eids.filter(({uids}) => uids?.length > 0);
} catch (e) {
logError(`Could not generate EID for "${name}"`, e);
}
Expand Down
26 changes: 25 additions & 1 deletion test/spec/modules/sharedIdSystem_spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import {sharedIdSystemSubmodule, storage} from 'modules/sharedIdSystem.js';
import {coppaDataHandler} from 'src/adapterManager';
import {config} from 'src/config.js';

import sinon from 'sinon';
import * as utils from 'src/utils.js';
import {createEidsArray} from '../../../modules/userId/eids.js';
import {attachIdSystem} from '../../../modules/userId/index.js';
import {attachIdSystem, init} from '../../../modules/userId/index.js';
import {getGlobal} from '../../../src/prebidGlobal.js';

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

Expand Down Expand Up @@ -97,6 +99,9 @@ describe('SharedId System', function () {
before(() => {
attachIdSystem(sharedIdSystemSubmodule);
});
afterEach(() => {
config.resetConfig();
});
it('pubCommonId', function() {
const userId = {
pubcid: 'some-random-id-value'
Expand All @@ -108,5 +113,24 @@ describe('SharedId System', function () {
uids: [{id: 'some-random-id-value', atype: 1}]
});
});

it('should set inserter, if provided in config', async () => {
config.setConfig({
userSync: {
userIds: [{
name: 'sharedId',
params: {
inserter: 'mock-inserter'
},
value: {pubcid: 'mock-id'}
}]
}
});
const eids = getGlobal().getUserIdsAsEids();
sinon.assert.match(eids[0], {
source: 'pubcid.org',
inserter: 'mock-inserter'
})
})
})
});
19 changes: 19 additions & 0 deletions test/spec/modules/userId_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,25 @@ describe('User ID', function () {
]);
});

it('should filter out non-string uid returned by generator functions', () => {
const eids = createEidsArray({
mockId2v3: [null, 'id1', 123],
});
expect(eids[0].uids).to.eql([
{
atype: 2,
id: 'id1'
}
]);
});

it('should filter out entire EID if none of the uids are strings', () => {
const eids = createEidsArray({
mockId2v3: [null],
});
expect(eids).to.eql([]);
})

it('should group UIDs by everything except uid', () => {
const eids = createEidsArray({
mockId1: ['mock-1-1', 'mock-1-2'],
Expand Down
Loading