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

ID5 User Id module - expose euid as a separate eid object #11158

Merged
merged 1 commit into from
Mar 4, 2024
Merged
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
32 changes: 28 additions & 4 deletions modules/id5IdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
deepSetValue,
isEmpty,
isEmptyStr,
isPlainObject,
logError,
logInfo,
logWarn,
Expand All @@ -21,8 +22,8 @@ import {getRefererInfo} from '../src/refererDetection.js';
import {getStorageManager} from '../src/storageManager.js';
import {uspDataHandler, gppDataHandler} from '../src/adapterManager.js';
import {MODULE_TYPE_UID} from '../src/activities/modules.js';
import { GreedyPromise } from '../src/utils/promise.js';
import { loadExternalScript } from '../src/adloader.js';
import {GreedyPromise} from '../src/utils/promise.js';
import {loadExternalScript} from '../src/adloader.js';

/**
* @typedef {import('../modules/userId/index.js').Submodule} Submodule
Expand All @@ -39,6 +40,7 @@ export const ID5_PRIVACY_STORAGE_NAME = `${ID5_STORAGE_NAME}_privacy`;
const LOCAL_STORAGE = 'html5';
const LOG_PREFIX = 'User ID - ID5 submodule: ';
const ID5_API_CONFIG_URL = 'https://id5-sync.com/api/config/prebid';
const ID5_DOMAIN = 'id5-sync.com';

// order the legacy cookie names in reverse priority order so the last
// cookie in the array is the most preferred to use
Expand Down Expand Up @@ -146,9 +148,17 @@ export const id5IdSubmodule = {
id5id: {
uid: universalUid,
ext: ext
}
},
};

if (isPlainObject(ext.euid)) {
responseObj.euid = {
uid: ext.euid.uids[0].id,
source: ext.euid.source,
ext: {provider: ID5_DOMAIN}
}
}

const abTestingResult = deepAccess(value, 'ab_testing.result');
switch (abTestingResult) {
case 'control':
Expand Down Expand Up @@ -232,14 +242,28 @@ export const id5IdSubmodule = {
getValue: function(data) {
return data.uid
},
source: 'id5-sync.com',
source: ID5_DOMAIN,
atype: 1,
getUidExt: function(data) {
if (data.ext) {
return data.ext;
}
}
},
'euid': {
getValue: function (data) {
return data.uid;
},
getSource: function (data) {
return data.source;
},
atype: 3,
getUidExt: function (data) {
if (data.ext) {
return data.ext;
}
}
}
},
};

Expand Down
62 changes: 60 additions & 2 deletions test/spec/modules/id5IdSystem_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import * as id5System from '../../../modules/id5IdSystem.js';
import {coreStorage, getConsentHash, init, requestBidsHook, setSubmoduleRegistry} from '../../../modules/userId/index.js';
import {
coreStorage,
getConsentHash,
init,
requestBidsHook,
setSubmoduleRegistry
} from '../../../modules/userId/index.js';
import {config} from '../../../src/config.js';
import * as events from '../../../src/events.js';
import CONSTANTS from '../../../src/constants.json';
Expand All @@ -10,7 +16,7 @@ import {hook} from '../../../src/hook.js';
import {mockGdprConsent} from '../../helpers/consentData.js';
import {server} from '../../mocks/xhr.js';
import {expect} from 'chai';
import { GreedyPromise } from '../../../src/utils/promise.js';
import {GreedyPromise} from '../../../src/utils/promise.js';

const IdFetchFlow = id5System.IdFetchFlow;

Expand All @@ -37,6 +43,22 @@ describe('ID5 ID System', function () {
'linkType': ID5_STORED_LINK_TYPE
}
};
const EUID_STORED_ID = 'EUID_1';
const EUID_SOURCE = 'uidapi.com';
const ID5_STORED_OBJ_WITH_EUID = {
'universal_uid': ID5_STORED_ID,
'signature': ID5_STORED_SIGNATURE,
'ext': {
'linkType': ID5_STORED_LINK_TYPE,
'euid': {
'source': EUID_SOURCE,
'uids': [{
'id': EUID_STORED_ID,
'aType': 3
}]
}
}
};
const ID5_RESPONSE_ID = 'newid5id';
const ID5_RESPONSE_SIGNATURE = 'abcdef';
const ID5_RESPONSE_LINK_TYPE = 2;
Expand Down Expand Up @@ -886,6 +908,35 @@ describe('ID5 ID System', function () {
}, {adUnits});
});

it('should add stored EUID from cache to bids', function (done) {
id5System.storeInLocalStorage(id5System.ID5_STORAGE_NAME, JSON.stringify(ID5_STORED_OBJ_WITH_EUID), 1);

init(config);
setSubmoduleRegistry([id5System.id5IdSubmodule]);
config.setConfig(getFetchLocalStorageConfig());

requestBidsHook(function () {
adUnits.forEach(unit => {
unit.bids.forEach(bid => {
expect(bid).to.have.deep.nested.property(`userId.euid`);
expect(bid.userId.euid.uid).is.equal(EUID_STORED_ID);
expect(bid.userIdAsEids[0].uids[0].id).is.equal(ID5_STORED_ID);
expect(bid.userIdAsEids[1]).is.deep.equal({
source: EUID_SOURCE,
uids: [{
id: EUID_STORED_ID,
atype: 3,
ext: {
provider: ID5_SOURCE
}
}]
})
});
});
done();
}, {adUnits});
});

it('should add config value ID to bids', function (done) {
init(config);
setSubmoduleRegistry([id5System.id5IdSubmodule]);
Expand Down Expand Up @@ -984,6 +1035,13 @@ describe('ID5 ID System', function () {
it('should return undefined if passed a string', function () {
expect(id5System.id5IdSubmodule.decode('somestring', getId5FetchConfig())).is.eq(undefined);
});
it('should decode euid from a stored object with EUID', function () {
expect(id5System.id5IdSubmodule.decode(ID5_STORED_OBJ_WITH_EUID, getId5FetchConfig()).euid).is.deep.equal({
'source': EUID_SOURCE,
'uid': EUID_STORED_ID,
'ext': {'provider': ID5_SOURCE}
});
});
});

describe('A/B Testing', function () {
Expand Down