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 userId submodule #3798

Merged
merged 10 commits into from
Jun 24, 2019
12 changes: 11 additions & 1 deletion integrationExamples/gpt/userId_example.html
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,17 @@
name: "unifiedid",
expires: 30
},

}, {
name: "id5Id",
params: {
partner: 173 // @TODO: Set your real ID5 partner ID here for production, please ask for one contact@id5.io
},
storage: {
type: "cookie",
name: "id5id",
expires: 90
},

}, {
name: "pubCommonId",
storage: {
Expand Down
60 changes: 60 additions & 0 deletions modules/id5IdSystem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* This module adds ID5 to the User ID module
* The {@link module:modules/userId} module is required
* @module modules/unifiedIdSystem
* @requires module:modules/userId
*/

import * as utils from '../src/utils.js'
import {ajax} from '../src/ajax.js';
import {isGDPRApplicable, attachIdSystem} from './userId.js';

/** @type {Submodule} */
export const id5IdSubmodule = {
/**
* used to link submodule with config
* @type {string}
*/
name: 'id5Id',
/**
* decode the stored id value for passing to bid requests
* @function
* @param {{ID5ID:Object}} value
* @returns {{id5id:String}}
*/
decode(value) {
return (value && typeof value['ID5ID'] === 'string') ? { 'id5id': value['ID5ID'] } : undefined;
},
/**
* performs action to obtain id and return a value in the callback's response argument
* @function
* @param {SubmoduleParams} [configParams]
* @param {ConsentData} [consentData]
* @returns {function(callback:function)}
*/
getId(configParams, consentData) {
if (!configParams || typeof configParams.partner !== 'number') {
utils.logError(`User ID - ID5 submodule requires partner to be defined as a number`);
return;
}
const hasGdpr = isGDPRApplicable(consentData) ? 1 : 0;
const gdprConsentString = hasGdpr ? consentData.consentString : '';
const url = `https://id5-sync.com/g/v1/${configParams.partner}.json?gdpr=${hasGdpr}&gdpr_consent=${gdprConsentString}`;

return function (callback) {
ajax(url, response => {
let responseObj;
if (response) {
try {
responseObj = JSON.parse(response);
} catch (error) {
utils.logError(error);
}
}
callback(responseObj);
}, undefined, { method: 'GET' });
}
}
};

attachIdSystem(id5IdSubmodule);
13 changes: 11 additions & 2 deletions modules/userId.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,22 @@ function getStoredValue(storage) {
return storedValue;
}

/**
* test if consent module is present, and if GDPR applies
* @param {ConsentData} consentData
* @returns {boolean}
*/
export function isGDPRApplicable(consentData) {
return consentData && typeof consentData.gdprApplies === 'boolean' && consentData.gdprApplies;
}

/**
* test if consent module is present, applies, and is valid for local storage or cookies (purpose 1)
* @param {ConsentData} consentData
* @returns {boolean}
*/
function hasGDPRConsent(consentData) {
if (consentData && typeof consentData.gdprApplies === 'boolean' && consentData.gdprApplies) {
export function hasGDPRConsent(consentData) {
if (isGDPRApplicable(consentData)) {
if (!consentData.consentString) {
return false;
}
Expand Down
24 changes: 22 additions & 2 deletions modules/userId.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
Example showing `cookie` storage for user id data for both submodules
```
pbjs.setConfig({
userSync: {
usersync: {
userIds: [{
name: "unifiedId",
params: {
partner: "prebid",
url: "//match.adsrvr.org/track/rid?ttd_pid=prebid&fmt=json"
url: "http://match.adsrvr.org/track/rid?ttd_pid=prebid&fmt=json"
},
storage: {
type: "cookie",
Expand All @@ -28,6 +28,26 @@ pbjs.setConfig({
});
```

Example showing `cookie` storage for user id data for id5 submodule
```
pbjs.setConfig({
usersync: {
userIds: [{
name: "id5Id",
params: {
partner: 173 // @TODO: Set your real ID5 partner ID here for production, please ask for one contact@id5.io
},
storage: {
type: "cookie",
name: "id5id",
expires: 90
}
}],
syncDelay: 5000
}
});
```

Example showing `localStorage` for user id data for both submodules
```
pbjs.setConfig({
Expand Down
Loading