Skip to content

UID 2.0 Userid submodule #6443

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

Merged
merged 14 commits into from
Mar 25, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
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
}
}
],
syncDelay: 5000,
auctionDelay: 1000
Expand Down
97 changes: 97 additions & 0 deletions modules/uid2IdSystem.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
}
result.uid20 = bidIds;
logInfo('Decoded value ' + JSON.stringify(result));
return result;
}
return undefined;
}

/** @type {Submodule} */
export const uid2IdSubmodule = {
/**
* 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 {{sharedid:{ id: string, third:string}} or undefined if value doesn't exists
Copy link
Collaborator

Choose a reason for hiding this comment

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

refs: sharedid, is this on purpose?

*/
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}
*/
getId(config, consentData) {
logInfo('Creating UID2');
let value = storage.getCookie(ADVERTISING_COOKIE);
Copy link
Collaborator

@patmmccann patmmccann Mar 18, 2021

Choose a reason for hiding this comment

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

does this not work with local storage? or is storage.getCookie smart enough to check there if config says this should be in local storage?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

UID 2.0 submodule relies on cookie '__uid2_advertising_token' which is set by UID 2.0 SSO

logInfo('The advestising token: ' + value);
Copy link
Collaborator

Choose a reason for hiding this comment

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

spelling

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}
}
};

// Register submodule for userId
submodule('userId', uid2IdSubmodule);
32 changes: 32 additions & 0 deletions modules/uid2IdSystem.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'
}
}]
}
});
```
## 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` |
| 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"}}` |
7 changes: 7 additions & 0 deletions modules/userId/eids.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,13 @@ const USER_IDS_CONFIG = {
},
source: 'novatiq.com',
atype: 1
},
'uid20': {
source: 'uid20.com',
atype: 1,
getValue: function(data) {
return data.id;
}
}
};

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