Skip to content

Commit

Permalink
ID5 userId submodule (#3798)
Browse files Browse the repository at this point in the history
* Extract GDPRApplies in userId.js to make it available to cookie-sync requiring it

* Adding id5 userId submodule, tests and documentation

* Fixed typo in test name for unifiedid

* Adding test to userId for ID5

* Follow correct naming convention for GDPRApplies: renamed to isGDPRApplicable

* Refactoring of id5 module following refactoring of userId module.

* Moved init of id5 user module at the end of the id5 module itself

* regroup import to avoid a CircleCI Bug
  • Loading branch information
padurgeat authored and Isaac Dettman committed Jun 24, 2019
1 parent bbd73ce commit de8381f
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 29 deletions.
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

0 comments on commit de8381f

Please sign in to comment.