Skip to content

Commit

Permalink
merkleId Identity submodule submission (#5577)
Browse files Browse the repository at this point in the history
* Create merkleIdSystem.js

* Update userId_example.html

* Update eids.md

* Update userId_spec.js

* Update eids.md

fix to merkleinc.com

* fix string break in gdpr applies warning

* Update merkleIdSystem.js

add consentData as param to getId

* Update merkleIdSystem.js

remove useless conditional part

* Update userId_spec.js

fix test strings to match

* Update merkleIdSystem.js

fixes decode function

* Update merkleIdSystem.js

change back decode

* Update userId_spec.js

fix set cookie format

* Update userId_spec.js

fix space before value

* Update eids_spec.js

* Update eids_spec.js

fix spacing issue

* Update merkleIdSystem.js

fix decode again

* Update merkleIdSystem.js

typo

* Update merkleIdSystem.js

* Update merkleIdSystem.js

* Update merkleIdSystem.js

* Update .submodules.json

* Update eids.js

* Update eids_spec.js

* Update eids.js
  • Loading branch information
angelamerkelprebid authored Aug 28, 2020
1 parent 2b05803 commit 3d4e25d
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 8 deletions.
16 changes: 14 additions & 2 deletions integrationExamples/gpt/userId_example.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
consentManagement: {
cmpApi: 'iab',
timeout: 1000,
allowAuctionWithoutConsent: true
defaultGdprScope: true
},
// consentManagement: {
// cmpApi: 'static',
Expand All @@ -128,7 +128,7 @@
// }
// }
// },
usersync: {
userSync: {
userIds: [{
name: "unifiedId",
params: {
Expand Down Expand Up @@ -164,6 +164,18 @@
},

}, {
name: "merkleId",
params: {
ptk: '12345678-aaaa-bbbb-cccc-123456789abc', //Set your real merkle partner key here
pubid: 'EXAMPLE' //Set your real merkle publisher id here
},
storage: {
type: "html5",
name: "merkleId",
expires: 30
},

},{
name: "parrableId",
params: {
// change to Parrable Partner Client ID(s) you received from the Parrable Partners you are using
Expand Down
1 change: 1 addition & 0 deletions modules/.submodules.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"britepoolIdSystem",
"liveIntentIdSystem",
"lotamePanoramaId",
"merkleIdSystem",
"criteoIdSystem",
"netIdSystem",
"identityLinkIdSystem",
Expand Down
80 changes: 80 additions & 0 deletions modules/merkleIdSystem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
* This module adds merkleId to the User ID module
* The {@link module:modules/userId} module is required
* @module modules/merkleIdSystem
* @requires module:modules/userId
*/

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

const MODULE_NAME = 'merkleId';

/** @type {Submodule} */
export const merkleIdSubmodule = {
/**
* used to link submodule with config
* @type {string}
*/
name: MODULE_NAME,
/**
* decode the stored id value for passing to bid requests
* @function
* @param {string} value
* @returns {{merkleId:string}}
*/
decode(value) {
const id = (value && value.ppid && typeof value.ppid.id === 'string') ? value.ppid.id : undefined;
return id ? { 'merkleId': id } : undefined;
},
/**
* performs action to obtain id and return a value in the callback's response argument
* @function
* @param {SubmoduleParams} [configParams]
* @param {ConsentData} [consentData]
* @returns {IdResponse|undefined}
*/
getId(configParams, consentData) {
if (!configParams || typeof configParams.pubid !== 'string') {
utils.logError('User ID - merkleId submodule requires a valid pubid to be defined');
return;
}

if (typeof configParams.ptk !== 'string') {
utils.logError('User ID - merkleId submodule requires a valid ptk string to be defined');
return;
}

if (consentData && typeof consentData.gdprApplies === 'boolean' && consentData.gdprApplies) {
utils.logError('User ID - merkleId submodule does not currently handle consent strings');
return;
}

const url = `https://mid.rkdms.com/idsv2?ptk=${configParams.ptk}&pubid=${configParams.pubid}`;

const resp = function (callback) {
const callbacks = {
success: response => {
let responseObj;
if (response) {
try {
responseObj = JSON.parse(response);
} catch (error) {
utils.logError(error);
}
}
callback(responseObj);
},
error: error => {
utils.logError(`${MODULE_NAME}: merkleId fetch encountered an error`, error);
callback();
}
};
ajax(url, callbacks, undefined, {method: 'GET', withCredentials: true});
};
return {callback: resp};
}
};

submodule('userId', merkleIdSubmodule);
6 changes: 6 additions & 0 deletions modules/userId/eids.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ const USER_IDS_CONFIG = {
atype: 1
},

// merkleId
'merkleId': {
source: 'merkleinc.com',
atype: 1
},

// NetId
'netId': {
source: 'netid.de',
Expand Down
8 changes: 8 additions & 0 deletions modules/userId/eids.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ userIdAsEids = [
}
},
{
source: 'merkleinc.com',
uids: [{
id: 'some-random-id-value',
atype: 1
}]
},
{
source: 'britepool.com',
uids: [{
Expand Down
12 changes: 12 additions & 0 deletions test/spec/modules/eids_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ describe('eids array generation for known sub-modules', function() {
});
});

it('merkleId', function() {
const userId = {
merkleId: 'some-random-id-value'
};
const newEids = createEidsArray(userId);
expect(newEids.length).to.equal(1);
expect(newEids[0]).to.deep.equal({
source: 'merkleinc.com',
uids: [{id: 'some-random-id-value', atype: 1}]
});
});

it('identityLink', function() {
const userId = {
idl_env: 'some-random-id-value'
Expand Down
38 changes: 32 additions & 6 deletions test/spec/modules/userId_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {britepoolIdSubmodule} from 'modules/britepoolIdSystem.js';
import {id5IdSubmodule} from 'modules/id5IdSystem.js';
import {identityLinkSubmodule} from 'modules/identityLinkIdSystem.js';
import {liveIntentIdSubmodule} from 'modules/liveIntentIdSystem.js';
import {merkleIdSubmodule} from 'modules/merkleIdSystem.js';
import {netIdSubmodule} from 'modules/netIdSystem.js';
import {intentIqIdSubmodule} from 'modules/intentIqIdSystem.js';
import {sharedIdSubmodule} from 'modules/sharedIdSystem.js';
Expand All @@ -34,7 +35,7 @@ const EXPIRED_COOKIE_DATE = 'Thu, 01 Jan 1970 00:00:01 GMT';
const CONSENT_LOCAL_STORAGE_NAME = '_pbjs_userid_consent_data';

describe('User ID', function() {
function getConfigMock(configArr1, configArr2, configArr3, configArr4, configArr5, configArr6, configArr7, configArr8) {
function getConfigMock(configArr1, configArr2, configArr3, configArr4, configArr5, configArr6, configArr7, configArr8, configArr9) {
return {
userSync: {
syncDelay: 0,
Expand All @@ -46,7 +47,8 @@ describe('User ID', function() {
(configArr5 && configArr5.length >= 3) ? getStorageMock.apply(null, configArr5) : null,
(configArr6 && configArr6.length >= 3) ? getStorageMock.apply(null, configArr6) : null,
(configArr7 && configArr7.length >= 3) ? getStorageMock.apply(null, configArr7) : null,
(configArr8 && configArr8.length >= 3) ? getStorageMock.apply(null, configArr8) : null
(configArr8 && configArr8.length >= 3) ? getStorageMock.apply(null, configArr8) : null,
(configArr9 && configArr9.length >= 3) ? getStorageMock.apply(null, configArr9) : null
].filter(i => i)
}
}
Expand Down Expand Up @@ -352,22 +354,22 @@ describe('User ID', function() {
});

it('handles config with no usersync object', function() {
setSubmoduleRegistry([pubCommonIdSubmodule, unifiedIdSubmodule, id5IdSubmodule, identityLinkSubmodule, netIdSubmodule, sharedIdSubmodule, intentIqIdSubmodule]);
setSubmoduleRegistry([pubCommonIdSubmodule, unifiedIdSubmodule, id5IdSubmodule, identityLinkSubmodule, merkleIdSubmodule, netIdSubmodule, sharedIdSubmodule, intentIqIdSubmodule]);
init(config);
config.setConfig({});
// usersync is undefined, and no logInfo message for 'User ID - usersync config updated'
expect(typeof utils.logInfo.args[0]).to.equal('undefined');
});

it('handles config with empty usersync object', function () {
setSubmoduleRegistry([pubCommonIdSubmodule, unifiedIdSubmodule, id5IdSubmodule, identityLinkSubmodule, netIdSubmodule, sharedIdSubmodule, intentIqIdSubmodule]);
setSubmoduleRegistry([pubCommonIdSubmodule, unifiedIdSubmodule, id5IdSubmodule, identityLinkSubmodule, merkleIdSubmodule, netIdSubmodule, sharedIdSubmodule, intentIqIdSubmodule]);
init(config);
config.setConfig({userSync: {}});
expect(typeof utils.logInfo.args[0]).to.equal('undefined');
});

it('handles config with usersync and userIds that are empty objs', function () {
setSubmoduleRegistry([pubCommonIdSubmodule, unifiedIdSubmodule, id5IdSubmodule, identityLinkSubmodule, netIdSubmodule, sharedIdSubmodule, intentIqIdSubmodule]);
setSubmoduleRegistry([pubCommonIdSubmodule, unifiedIdSubmodule, id5IdSubmodule, identityLinkSubmodule, merkleIdSubmodule, netIdSubmodule, sharedIdSubmodule, intentIqIdSubmodule]);
init(config);
config.setConfig({
userSync: {
Expand All @@ -378,7 +380,7 @@ describe('User ID', function() {
});

it('handles config with usersync and userIds with empty names or that dont match a submodule.name', function () {
setSubmoduleRegistry([pubCommonIdSubmodule, unifiedIdSubmodule, id5IdSubmodule, identityLinkSubmodule, netIdSubmodule, sharedIdSubmodule, intentIqIdSubmodule]);
setSubmoduleRegistry([pubCommonIdSubmodule, unifiedIdSubmodule, id5IdSubmodule, identityLinkSubmodule, merkleIdSubmodule, netIdSubmodule, sharedIdSubmodule, intentIqIdSubmodule]);
init(config);
config.setConfig({
userSync: {
Expand Down Expand Up @@ -1116,6 +1118,30 @@ describe('User ID', function() {
}, {adUnits});
});

it('test hook from merkleId cookies', function(done) {
// simulate existing browser local storage values
coreStorage.setCookie('merkleId', JSON.stringify({'ppid': {'id': 'testmerkleId'}}), (new Date(Date.now() + 5000).toUTCString()));

setSubmoduleRegistry([merkleIdSubmodule]);
init(config);
config.setConfig(getConfigMock(['merkleId', 'merkleId', 'cookie']));

requestBidsHook(function() {
adUnits.forEach(unit => {
unit.bids.forEach(bid => {
expect(bid).to.have.deep.nested.property('userId.merkleId');
expect(bid.userId.merkleId).to.equal('testmerkleId');
expect(bid.userIdAsEids[0]).to.deep.equal({
source: 'merkleinc.com',
uids: [{id: 'testmerkleId', atype: 1}]
});
});
});
coreStorage.setCookie('merkleId', '', EXPIRED_COOKIE_DATE);
done();
}, {adUnits});
});

it('test hook when pubCommonId, unifiedId, id5Id, identityLink, britepoolId, intentIqId, sharedId and netId have data to pass', function(done) {
coreStorage.setCookie('pubcid', 'testpubcid', (new Date(Date.now() + 5000).toUTCString()));
coreStorage.setCookie('unifiedid', JSON.stringify({'TDID': 'testunifiedid'}), (new Date(Date.now() + 5000).toUTCString()));
Expand Down

0 comments on commit 3d4e25d

Please sign in to comment.