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

UID 2.0 Userid submodule #6443

Merged
merged 14 commits into from
Mar 25, 2021
8 changes: 8 additions & 0 deletions integrationExamples/gpt/userId_example.html
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,14 @@
{
name: "criteo"
},
{
name: "uid20",
storage: {
type: "cookie",
name: "uid",
expires: 28
}
smenzer marked this conversation as resolved.
Show resolved Hide resolved
}
],
syncDelay: 5000,
auctionDelay: 1000
Expand Down
97 changes: 97 additions & 0 deletions modules/uid20IdSystem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/**
* This module adds uid2 ID support to the User ID module
* The {@link module:modules/userId} module is required.
* @module modules/uid2IdSystem
* @requires module:modules/userId
*/

import * as utils from '../src/utils.js'
import {submodule} from '../src/hook.js';
import {getStorageManager} from '../src/storageManager.js';

const storage = getStorageManager();

const MODULE_NAME = 'uid20';
const GVLID = 887;
const LOG_PRE_FIX = 'UID20: ';
const ADVERTISING_COOKIE = '__uid2_advertising_token';

const logInfo = createLogInfo(LOG_PRE_FIX);

function createLogInfo(prefix) {
return function (...strings) {
utils.logInfo(prefix + ' ', ...strings);
}
}

/**
* Encode the id
* @param value
* @returns {string|*}
*/
function encodeId(value) {
const result = {};
if (value) {
const bidIds = {
id: value
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the purpose of setting this const when it's just used once and immediately on the line below?

result.uid20 = bidIds;
logInfo('Decoded value ' + JSON.stringify(result));
return result;
}
return undefined;
}

/** @type {Submodule} */
export const uid20IdSubmodule = {
/**
* used to link submodule with config
* @type {string}
*/
name: MODULE_NAME,

/**
* Vendor id of Prebid
* @type {Number}
*/
gvlid: GVLID,
/**
* decode the stored id value for passing to bid requests
* @function
* @param {string} value
* @returns {{uid20:{ id: string }} or undefined if value doesn't exists
*/
decode(value) {
return (value) ? encodeId(value) : undefined;
},

/**
* performs action to obtain id and return a value.
* @function
* @param {SubmoduleConfig} [config]
* @param {ConsentData|undefined} consentData
* @returns {sharedId}
patmmccann marked this conversation as resolved.
Show resolved Hide resolved
*/
getId(config, consentData) {
logInfo('Creating UID2');
let value = storage.getCookie(ADVERTISING_COOKIE);
patmmccann marked this conversation as resolved.
Show resolved Hide resolved
logInfo('The advertising token: ' + value);
return {id: value}
},

/**
* performs actions even if the id exists and returns a value
* @param config
* @param consentData
* @param storedId
* @returns {{callback: *}}
*/
extendId(config, consentData, storedId) {
logInfo('Existing id ' + storedId);
let value = storage.getCookie(ADVERTISING_COOKIE);
return {id: value}
smenzer marked this conversation as resolved.
Show resolved Hide resolved
}
};

// Register submodule for userId
submodule('userId', uid20IdSubmodule);
32 changes: 32 additions & 0 deletions modules/uid20IdSystem.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
## UID 2.0 User ID Submodule

UID 2.0 ID Module.

### Prebid Params

Individual params may be set for the UID 2.0 Submodule. At least one identifier must be set in the params.

```
pbjs.setConfig({
userSync: {
userIds: [{
name: 'uid20',
storage: {
name: 'uid20id',
type: 'html5'
smenzer marked this conversation as resolved.
Show resolved Hide resolved
}
}]
}
});
```
## Parameter Descriptions for the `usersync` Configuration Section
The below parameters apply only to the UID 2.0 User ID Module integration.

| Param under userSync.userIds[] | Scope | Type | Description | Example |
| --- | --- | --- | --- | --- |
| name | Required | String | ID value for the UID20 module - `"uid20"` | `"uid20"` |
| storage | Required | Object | The publisher must specify the local storage in which to store the results of the call to get the user ID. This can be either cookie or HTML5 storage. | |
| storage.type | Required | String | This is where the results of the user ID will be stored. The recommended method is `localStorage` by specifying `html5`. | `"html5"` |
| storage.name | Required | String | The name of the cookie or html5 local storage where the user ID will be stored. | `"uid20id"` |
| storage.expires | Optional | Integer | How long (in days) the user ID information will be stored. | `365` |
smenzer marked this conversation as resolved.
Show resolved Hide resolved
| value | Optional | Object | Used only if the page has a separate mechanism for storing the Halo 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 | `{"uid20": { "id": "eb33b0cb-8d35-4722-b9c0-1a31d4064888"}}` |
smenzer marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 7 additions & 0 deletions modules/userId/eids.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,13 @@ const USER_IDS_CONFIG = {
},
source: 'novatiq.com',
atype: 1
},
'uid20': {
source: 'uid20.com',
atype: 1,
patmmccann marked this conversation as resolved.
Show resolved Hide resolved
getValue: function(data) {
return data.id;
}
}
};

Expand Down
9 changes: 8 additions & 1 deletion modules/userId/eids.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,13 @@ userIdAsEids = [
id: 'some-random-id-value',
atype: 1
}]
}
},
{
source: 'uid20.com',
uids: [{
id: 'some-random-id-value',
atype: 1
}]
}
]
```
15 changes: 14 additions & 1 deletion modules/userId/userId.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ pbjs.setConfig({
partnerId: 0000,
uid: '12345xyz'
}
}, {
name: 'uid20',
storage: {
type: 'cookie',
name: 'uid20id',
expires: 1
}
}],
syncDelay: 5000,
auctionDelay: 1000
Expand Down Expand Up @@ -161,7 +168,13 @@ pbjs.setConfig({
type: 'html5',
name: '_criteoId',
expires: 1
}
}, {
name: 'uid20',
storage: {
type: 'html5',
name: 'uid20id',
expires: 1
}
}],
syncDelay: 5000
}
Expand Down
14 changes: 14 additions & 0 deletions test/spec/modules/eids_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,20 @@ describe('eids array generation for known sub-modules', function() {
}]
});
});
it('uid2', function() {
const userId = {
uid20: {'id': 'Sample_AD_Token'}
};
const newEids = createEidsArray(userId);
expect(newEids.length).to.equal(1);
expect(newEids[0]).to.deep.equal({
source: 'uid20.com',
uids: [{
id: 'Sample_AD_Token',
atype: 1
}]
});
});
it('pubProvidedId', function() {
const userId = {
pubProvidedId: [{
Expand Down
Loading