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

Merkle User ID Module: updates to user id submodule #6503

Merged
merged 3 commits into from
Apr 3, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 9 additions & 6 deletions integrationExamples/gpt/userId_example.html
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,16 @@
}, {
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
},
vendor:'sdfg',
sv_cid:'dfg',
sv_pubid:'xcv',
sv_domain:'zxv'
}
,
storage: {
type: "html5",
name: "merkleId",
expires: 30
type: "html5",
name: "merkleId",
expires: 30
},

},{
Expand Down
58 changes: 51 additions & 7 deletions modules/merkleIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,41 @@
import * as utils from '../src/utils.js'
import {ajax} from '../src/ajax.js';
import {submodule} from '../src/hook.js'
import { getStorageManager } from '../src/storageManager.js';

const MODULE_NAME = 'merkleId';
const SESSION_COOKIE_NAME = '_svsid';
const ID_URL = 'https://id2.sv.rkdms.com/identity/';

export const storage = getStorageManager();

function getSession(configParams) {
let session = null;
if (typeof configParams.sv_session !== 'string') {
session = configParams.sv_session;
} else {
session = readCookie() || readFromLocalStorage();
}
return session;
}

function readCookie() {
return storage.cookiesAreEnabled() ? storage.getCookie(SESSION_COOKIE_NAME) : null;
}

function readFromLocalStorage() {
return storage.localStorageIsEnabled() ? storage.getDataFromLocalStorage(SESSION_COOKIE_NAME) : null;
}

function constructUrl(configParams) {
const session = getSession(configParams);
let url = ID_URL + `?vendor=${configParams.vendor}&sv_cid=${configParams.sv_cid}&sv_domain=${configParams.sv_domain}&sv_pubid=${configParams.sv_pubid}`;
if (session) {
url.append(`&sv_session=${session}`);
}
utils.logInfo('Merkle url :' + url);
return url;
}

/** @type {Submodule} */
export const merkleIdSubmodule = {
Expand All @@ -25,7 +58,8 @@ export const merkleIdSubmodule = {
* @returns {{merkleId:string}}
*/
decode(value) {
const id = (value && value.ppid && typeof value.ppid.id === 'string') ? value.ppid.id : undefined;
const id = (value && value.pam_id && typeof value.pam_id.id === 'string') ? value.pam_id : undefined;
utils.logInfo('Merkle id ' + JSON.stringify(id));
return id ? { 'merkleId': id } : undefined;
},
/**
Expand All @@ -37,22 +71,31 @@ export const merkleIdSubmodule = {
*/
getId(config, consentData) {
const configParams = (config && config.params) || {};
if (!configParams || typeof configParams.pubid !== 'string') {
utils.logError('User ID - merkleId submodule requires a valid pubid to be defined');
if (!configParams || typeof configParams.vendor !== 'string') {
utils.logError('User ID - merkleId submodule requires a valid vendor to be defined');
return;
}

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

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

if (typeof configParams.sv_domain !== 'string') {
utils.logError('User ID - merkleId submodule requires a valid sv_domain 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 url = constructUrl(configParams);

const resp = function (callback) {
const callbacks = {
Expand All @@ -61,6 +104,7 @@ export const merkleIdSubmodule = {
if (response) {
try {
responseObj = JSON.parse(response);
utils.logInfo('Merkle responseObj ' + JSON.stringify(responseObj));
} catch (error) {
utils.logError(error);
}
Expand Down
10 changes: 9 additions & 1 deletion modules/userId/eids.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,15 @@ const USER_IDS_CONFIG = {
// merkleId
'merkleId': {
source: 'merkleinc.com',
atype: 3
atype: 3,
getValue: function(data) {
return data.id;
},
getUidExt: function(data) {
return (data && data.keyID) ? {
keyID: data.keyID
} : undefined;
}
},

// NetId
Expand Down
28 changes: 27 additions & 1 deletion modules/userId/userId.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,20 @@ pbjs.setConfig({
partnerId: 0000,
uid: '12345xyz'
}
}, {
},{
name: "merkleId",
params: {
vendor:'sdfg',
sv_cid:'dfg',
sv_pubid:'xcv',
sv_domain:'zxv'
},
storage: {
type: "cookie",
name: "merkleId",
expires: 30
}
},{
name: 'uid2'
}
}],
Expand Down Expand Up @@ -165,6 +178,19 @@ pbjs.setConfig({
name: '_criteoId',
expires: 1
}
},{
name: "merkleId",
params: {
vendor:'sdfg',
sv_cid:'dfg',
sv_pubid:'xcv',
sv_domain:'zxv'
},
storage: {
type: "html5",
name: "merkleId",
expires: 30
}
}],
syncDelay: 5000
}
Expand Down
9 changes: 7 additions & 2 deletions test/spec/modules/eids_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,18 @@ describe('eids array generation for known sub-modules', function() {

it('merkleId', function() {
const userId = {
merkleId: 'some-random-id-value'
merkleId: {
id: 'some-random-id-value', keyID: 1
}
};
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: 3}]
uids: [{id: 'some-random-id-value',
atype: 3,
ext: { keyID: 1
}}]
});
});

Expand Down
6 changes: 3 additions & 3 deletions test/spec/modules/userId_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1582,7 +1582,7 @@ describe('User ID', function () {

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()));
coreStorage.setCookie('merkleId', JSON.stringify({'pam_id': {'id': 'testmerkleId', 'keyID': 1}}), (new Date(Date.now() + 5000).toUTCString()));

setSubmoduleRegistry([merkleIdSubmodule]);
init(config);
Expand All @@ -1592,10 +1592,10 @@ describe('User ID', 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.userId.merkleId).to.deep.equal({'id': 'testmerkleId', 'keyID': 1});
expect(bid.userIdAsEids[0]).to.deep.equal({
source: 'merkleinc.com',
uids: [{id: 'testmerkleId', atype: 3}]
uids: [{id: 'testmerkleId', atype: 3, ext: {keyID: 1}}]
});
});
});
Expand Down