Skip to content

Commit ccfeee9

Browse files
SKOCHERIskocheri
authored and
idettman
committed
UID 2.0 Userid submodule (#6443)
* UID 2.0 User id submodule * UID 2.0 User id submodule * UID 2.0 User id submodule * UID 2.0 User id submodule * Resolving merge conflicts and review comments * Updating documentation * Renaming module * Fixing review comments * Fixing review comments * Fixing review comments * Fixing review comments * Fixing review comments * Updating source uid2.com to uidapi.com Co-authored-by: skocheri <[email protected]>
1 parent 51f1cf7 commit ccfeee9

File tree

8 files changed

+228
-24
lines changed

8 files changed

+228
-24
lines changed

integrationExamples/gpt/userId_example.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@
277277
{
278278
name: "criteo"
279279
},
280+
{
281+
name: "uid2"
282+
}
280283
],
281284
syncDelay: 5000,
282285
auctionDelay: 1000

modules/uid2IdSystem.js

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/**
2+
* This module adds uid2 ID support to the User ID module
3+
* The {@link module:modules/userId} module is required.
4+
* @module modules/uid2IdSystem
5+
* @requires module:modules/userId
6+
*/
7+
8+
import * as utils from '../src/utils.js'
9+
import {submodule} from '../src/hook.js';
10+
import { getStorageManager } from '../src/storageManager.js';
11+
12+
const MODULE_NAME = 'uid2';
13+
const GVLID = 887;
14+
const LOG_PRE_FIX = 'UID2: ';
15+
const ADVERTISING_COOKIE = '__uid2_advertising_token';
16+
17+
function readCookie() {
18+
return storage.cookiesAreEnabled() ? storage.getCookie(ADVERTISING_COOKIE) : null;
19+
}
20+
21+
function readFromLocalStorage() {
22+
return storage.localStorageIsEnabled() ? storage.getDataFromLocalStorage(ADVERTISING_COOKIE) : null;
23+
}
24+
25+
function getStorage() {
26+
return getStorageManager(GVLID, MODULE_NAME);
27+
}
28+
29+
const storage = getStorage();
30+
31+
const logInfo = createLogInfo(LOG_PRE_FIX);
32+
33+
function createLogInfo(prefix) {
34+
return function (...strings) {
35+
utils.logInfo(prefix + ' ', ...strings);
36+
}
37+
}
38+
39+
/**
40+
* Encode the id
41+
* @param value
42+
* @returns {string|*}
43+
*/
44+
function encodeId(value) {
45+
const result = {};
46+
if (value) {
47+
const bidIds = {
48+
id: value
49+
}
50+
result.uid2 = bidIds;
51+
logInfo('Decoded value ' + JSON.stringify(result));
52+
return result;
53+
}
54+
return undefined;
55+
}
56+
57+
/** @type {Submodule} */
58+
export const uid2IdSubmodule = {
59+
/**
60+
* used to link submodule with config
61+
* @type {string}
62+
*/
63+
name: MODULE_NAME,
64+
65+
/**
66+
* Vendor id of Prebid
67+
* @type {Number}
68+
*/
69+
gvlid: GVLID,
70+
/**
71+
* decode the stored id value for passing to bid requests
72+
* @function
73+
* @param {string} value
74+
* @returns {{uid2:{ id: string }} or undefined if value doesn't exists
75+
*/
76+
decode(value) {
77+
return (value) ? encodeId(value) : undefined;
78+
},
79+
80+
/**
81+
* performs action to obtain id and return a value.
82+
* @function
83+
* @param {SubmoduleConfig} [config]
84+
* @param {ConsentData|undefined} consentData
85+
* @returns {uid2Id}
86+
*/
87+
getId(config, consentData) {
88+
logInfo('Creating UID 2.0');
89+
let value = readCookie() || readFromLocalStorage();
90+
logInfo('The advertising token: ' + value);
91+
return {id: value}
92+
},
93+
94+
};
95+
96+
// Register submodule for userId
97+
submodule('userId', uid2IdSubmodule);

modules/uid2IdSystem.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
## UID 2.0 User ID Submodule
2+
3+
UID 2.0 ID Module.
4+
5+
### Prebid Params
6+
7+
Individual params may be set for the UID 2.0 Submodule. At least one identifier must be set in the params.
8+
9+
```
10+
pbjs.setConfig({
11+
userSync: {
12+
userIds: [{
13+
name: 'uid2'
14+
}]
15+
}
16+
});
17+
```
18+
## Parameter Descriptions for the `usersync` Configuration Section
19+
The below parameters apply only to the UID 2.0 User ID Module integration.
20+
21+
| Param under userSync.userIds[] | Scope | Type | Description | Example |
22+
| --- | --- | --- | --- | --- |
23+
| name | Required | String | ID value for the UID20 module - `"uid2"` | `"uid2"` |
24+
| value | Optional | Object | Used only if the page has a separate mechanism for storing the UID 2.O ID. The value is an object containing the values to be sent to the adapters. In this scenario, no URL is called and nothing is added to local storage | `{"uid2": { "id": "eb33b0cb-8d35-4722-b9c0-1a31d4064888"}}` |

modules/userId/eids.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,13 @@ const USER_IDS_CONFIG = {
185185
},
186186
source: 'novatiq.com',
187187
atype: 1
188+
},
189+
'uid2': {
190+
source: 'uidapi.com',
191+
atype: 3,
192+
getValue: function(data) {
193+
return data.id;
194+
}
188195
}
189196
};
190197

modules/userId/eids.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,13 @@ userIdAsEids = [
162162
id: 'some-random-id-value',
163163
atype: 1
164164
}]
165-
}
165+
},
166+
{
167+
source: 'uidapi.com',
168+
uids: [{
169+
id: 'some-random-id-value',
170+
atype: 3
171+
}]
172+
}
166173
]
167174
```

modules/userId/userId.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ pbjs.setConfig({
8484
partnerId: 0000,
8585
uid: '12345xyz'
8686
}
87+
}, {
88+
name: 'uid2'
89+
}
8790
}],
8891
syncDelay: 5000,
8992
auctionDelay: 1000
@@ -161,7 +164,7 @@ pbjs.setConfig({
161164
type: 'html5',
162165
name: '_criteoId',
163166
expires: 1
164-
}
167+
}
165168
}],
166169
syncDelay: 5000
167170
}

test/spec/modules/eids_spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,20 @@ describe('eids array generation for known sub-modules', function() {
276276
}]
277277
});
278278
});
279+
it('uid2', function() {
280+
const userId = {
281+
uid2: {'id': 'Sample_AD_Token'}
282+
};
283+
const newEids = createEidsArray(userId);
284+
expect(newEids.length).to.equal(1);
285+
expect(newEids[0]).to.deep.equal({
286+
source: 'uidapi.com',
287+
uids: [{
288+
id: 'Sample_AD_Token',
289+
atype: 3
290+
}]
291+
});
292+
});
279293
it('pubProvidedId', function() {
280294
const userId = {
281295
pubProvidedId: [{

0 commit comments

Comments
 (0)