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

merkleId Identity submodule submission #5577

Merged
merged 27 commits into from
Aug 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
f54ba0e
Create merkleIdSystem.js
angelamerkelprebid Aug 6, 2020
926a1e3
Update userId_example.html
angelamerkelprebid Aug 6, 2020
c0b439e
Update eids.md
angelamerkelprebid Aug 6, 2020
07c7f80
Update userId_spec.js
angelamerkelprebid Aug 6, 2020
c2fae2a
Merge pull request #1 from angelamerkelprebid/angelamerkelprebid-merk…
angelamerkelprebid Aug 6, 2020
c4200e7
Update eids.md
angelamerkelprebid Aug 6, 2020
3442c40
fix string break in gdpr applies warning
angelamerkelprebid Aug 6, 2020
d52d905
Update merkleIdSystem.js
angelamerkelprebid Aug 6, 2020
c4ca3fd
Update merkleIdSystem.js
angelamerkelprebid Aug 6, 2020
97612d4
Update userId_spec.js
angelamerkelprebid Aug 6, 2020
52bbc3f
Update merkleIdSystem.js
angelamerkelprebid Aug 6, 2020
ad4a3c3
Update merkleIdSystem.js
angelamerkelprebid Aug 6, 2020
bd28075
Update userId_spec.js
angelamerkelprebid Aug 6, 2020
ee4799e
Update userId_spec.js
angelamerkelprebid Aug 6, 2020
650585f
Update eids_spec.js
angelamerkelprebid Aug 6, 2020
6cae0ae
Update eids_spec.js
angelamerkelprebid Aug 6, 2020
c40bc70
Update merkleIdSystem.js
angelamerkelprebid Aug 6, 2020
1e21a66
Update merkleIdSystem.js
angelamerkelprebid Aug 6, 2020
a5603cb
Update merkleIdSystem.js
angelamerkelprebid Aug 6, 2020
b9c9062
Merge pull request #2 from prebid/master
angelamerkelprebid Aug 23, 2020
c35e984
Update merkleIdSystem.js
angelamerkelprebid Aug 23, 2020
7d22cd4
Update merkleIdSystem.js
angelamerkelprebid Aug 23, 2020
06167c7
Update .submodules.json
angelamerkelprebid Aug 23, 2020
c29aa86
Update eids.js
angelamerkelprebid Aug 24, 2020
2844014
Update eids_spec.js
angelamerkelprebid Aug 24, 2020
0d523d8
Update eids.js
angelamerkelprebid Aug 24, 2020
d6f1527
Merge pull request #3 from prebid/master
angelamerkelprebid Aug 24, 2020
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
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