From 05cf0d2bceae6ec7d3fbfbe4ca82969cc4764618 Mon Sep 17 00:00:00 2001 From: mamatic <52153441+mamatic@users.noreply.github.com> Date: Tue, 23 Jul 2019 23:00:08 +0200 Subject: [PATCH] Integrate id link system (#3965) * idLink - integrate new submodule idLinkSystem in to userId module * idLink - Fix unit tests * identityLink - Change submodule name from idLink to identityLink * Identity Link - Remove identity link to be default submodule --- integrationExamples/gpt/userId_example.html | 10 ++ modules/identityLinkSystem.js | 58 +++++++++++ modules/userId/index.js | 1 + modules/userId/userId.md | 20 ++++ test/spec/modules/userId_spec.js | 107 ++++++++++++++++---- 5 files changed, 175 insertions(+), 21 deletions(-) create mode 100644 modules/identityLinkSystem.js diff --git a/integrationExamples/gpt/userId_example.html b/integrationExamples/gpt/userId_example.html index febe61628fe..5878d05aecd 100644 --- a/integrationExamples/gpt/userId_example.html +++ b/integrationExamples/gpt/userId_example.html @@ -162,6 +162,16 @@ // foo: '9879878907987', // bar:'93939' // } + }, { + name: 'identityLink', + params: { + pid: '14' // Set your real identityLink placement ID here + }, + storage: { + type: 'cookie', + name: 'idl_env', + expires: 60 + } }], syncDelay: 5000 } diff --git a/modules/identityLinkSystem.js b/modules/identityLinkSystem.js new file mode 100644 index 00000000000..8b8fa491bad --- /dev/null +++ b/modules/identityLinkSystem.js @@ -0,0 +1,58 @@ +/** + * This module adds IdentityLink to the User ID module + * The {@link module:modules/userId} module is required + * @module modules/identityLinkSubmodule + * @requires module:modules/userId + */ + +import * as utils from '../src/utils.js' +import {ajax} from '../src/ajax.js'; +import {submodule} from '../src/hook'; + +/** @type {Submodule} */ +export const identityLinkSubmodule = { + /** + * used to link submodule with config + * @type {string} + */ + name: 'identityLink', + /** + * decode the stored id value for passing to bid requests + * @function + * @param {string} value + * @returns {{idl_env:string}} + */ + decode(value) { + return { 'idl_env': value } + }, + /** + * performs action to obtain id and return a value in the callback's response argument + * @function + * @param {SubmoduleParams} [configParams] + * @returns {function(callback:function)} + */ + getId(configParams) { + if (!configParams || typeof configParams.pid !== 'string') { + utils.logError('identityLink submodule requires partner id to be defined'); + return; + } + // use protocol relative urls for http or https + const url = `https://api.rlcdn.com/api/identity?pid=${configParams.pid}&rt=envelope`; + + return function (callback) { + ajax(url, response => { + let responseObj; + if (response) { + try { + responseObj = JSON.parse(response); + } catch (error) { + utils.logError(error); + } + } + callback(responseObj.envelope); + }, undefined, { method: 'GET' }); + } + } +}; + +submodule('userId', identityLinkSubmodule); diff --git a/modules/userId/index.js b/modules/userId/index.js index 16421e39e20..98d99f7d333 100644 --- a/modules/userId/index.js +++ b/modules/userId/index.js @@ -50,6 +50,7 @@ * @typedef {Object} SubmoduleParams * @property {(string|undefined)} partner - partner url param value * @property {(string|undefined)} url - webservice request url used to load Id data + * @property {(string|undefined)} pid - placement id url param value */ /** diff --git a/modules/userId/userId.md b/modules/userId/userId.md index cd7aaf92d39..04bd34d13b9 100644 --- a/modules/userId/userId.md +++ b/modules/userId/userId.md @@ -32,6 +32,16 @@ pbjs.setConfig({ name: "id5id", expires: 5 } + }, { + name: 'identityLink', + params: { + pid: '999' // Set your real identityLink placement ID here + }, + storage: { + type: 'cookie', + name: 'idl_env', + expires: 60 + } }], syncDelay: 5000 } @@ -60,6 +70,16 @@ pbjs.setConfig({ name: "pubcid", expires: 60 } + }, { + name: 'identityLink', + params: { + pid: '999' // Set your real identityLink placement ID here + }, + storage: { + type: 'html5', + name: 'idl_env', + expires: 60 + } }], syncDelay: 5000 } diff --git a/test/spec/modules/userId_spec.js b/test/spec/modules/userId_spec.js index a158d2e9fed..b581873089a 100644 --- a/test/spec/modules/userId_spec.js +++ b/test/spec/modules/userId_spec.js @@ -10,19 +10,21 @@ import * as utils from 'src/utils'; import {unifiedIdSubmodule} from 'modules/userId/unifiedIdSystem'; import {pubCommonIdSubmodule} from 'modules/userId/pubCommonIdSystem'; import {id5IdSubmodule} from 'modules/id5IdSystem'; +import {identityLinkSubmodule} from 'modules/identityLinkSystem'; let assert = require('chai').assert; let expect = require('chai').expect; const EXPIRED_COOKIE_DATE = 'Thu, 01 Jan 1970 00:00:01 GMT'; describe('User ID', function() { - function getConfigMock(configArr1, configArr2, configArr3) { + function getConfigMock(configArr1, configArr2, configArr3, configArr4) { return { userSync: { syncDelay: 0, userIds: [ (configArr1 && configArr1.length === 3) ? getStorageMock.apply(null, configArr1) : null, (configArr2 && configArr2.length === 3) ? getStorageMock.apply(null, configArr2) : null, - (configArr3 && configArr3.length === 3) ? getStorageMock.apply(null, configArr3) : null + (configArr3 && configArr3.length === 3) ? getStorageMock.apply(null, configArr3) : null, + (configArr4 && configArr4.length === 3) ? getStorageMock.apply(null, configArr4) : null ].filter(i => i)} } } @@ -70,7 +72,7 @@ describe('User ID', function() { let pubcid = utils.getCookie('pubcid'); expect(pubcid).to.be.null; // there should be no cookie initially - setSubmoduleRegistry([pubCommonIdSubmodule, unifiedIdSubmodule, id5IdSubmodule]); + setSubmoduleRegistry([pubCommonIdSubmodule, unifiedIdSubmodule, id5IdSubmodule, identityLinkSubmodule]); init(config); config.setConfig(getConfigMock(['pubCommonId', 'pubcid', 'cookie'])); @@ -96,7 +98,7 @@ describe('User ID', function() { let pubcid1; let pubcid2; - setSubmoduleRegistry([pubCommonIdSubmodule, unifiedIdSubmodule, id5IdSubmodule]); + setSubmoduleRegistry([pubCommonIdSubmodule, unifiedIdSubmodule, id5IdSubmodule, identityLinkSubmodule]); init(config); config.setConfig(getConfigMock(['pubCommonId', 'pubcid', 'cookie'])); requestBidsHook((config) => { innerAdUnits1 = config.adUnits }, {adUnits: adUnits1}); @@ -110,7 +112,7 @@ describe('User ID', function() { }); }); - setSubmoduleRegistry([pubCommonIdSubmodule, unifiedIdSubmodule, id5IdSubmodule]); + setSubmoduleRegistry([pubCommonIdSubmodule, unifiedIdSubmodule, id5IdSubmodule, identityLinkSubmodule]); init(config); config.setConfig(getConfigMock(['pubCommonId', 'pubcid', 'cookie'])); requestBidsHook((config) => { innerAdUnits2 = config.adUnits }, {adUnits: adUnits2}); @@ -131,7 +133,7 @@ describe('User ID', function() { let adUnits = [getAdUnitMock()]; let innerAdUnits; - setSubmoduleRegistry([pubCommonIdSubmodule, unifiedIdSubmodule, id5IdSubmodule]); + setSubmoduleRegistry([pubCommonIdSubmodule, unifiedIdSubmodule, id5IdSubmodule, identityLinkSubmodule]); init(config); config.setConfig(getConfigMock(['pubCommonId', 'pubcid_alt', 'cookie'])); requestBidsHook((config) => { innerAdUnits = config.adUnits }, {adUnits}); @@ -166,14 +168,14 @@ describe('User ID', function() { }); it('fails initialization if opt out cookie exists', function () { - setSubmoduleRegistry([pubCommonIdSubmodule, unifiedIdSubmodule, id5IdSubmodule]); + setSubmoduleRegistry([pubCommonIdSubmodule, unifiedIdSubmodule, id5IdSubmodule, identityLinkSubmodule]); init(config); config.setConfig(getConfigMock(['pubCommonId', 'pubcid', 'cookie'])); expect(utils.logInfo.args[0][0]).to.exist.and.to.equal('User ID - opt-out cookie found, exit module'); }); it('initializes if no opt out cookie exists', function () { - setSubmoduleRegistry([pubCommonIdSubmodule, unifiedIdSubmodule, id5IdSubmodule]); + setSubmoduleRegistry([pubCommonIdSubmodule, unifiedIdSubmodule, id5IdSubmodule, identityLinkSubmodule]); init(config); config.setConfig(getConfigMock(['pubCommonId', 'pubcid', 'cookie'])); expect(utils.logInfo.args[0][0]).to.exist.and.to.equal('User ID - usersync config updated for 1 submodules'); @@ -192,7 +194,7 @@ describe('User ID', function() { }); it('handles config with no usersync object', function () { - setSubmoduleRegistry([pubCommonIdSubmodule, unifiedIdSubmodule, id5IdSubmodule]); + setSubmoduleRegistry([pubCommonIdSubmodule, unifiedIdSubmodule, id5IdSubmodule, identityLinkSubmodule]); init(config); config.setConfig({}); // usersync is undefined, and no logInfo message for 'User ID - usersync config updated' @@ -200,14 +202,14 @@ describe('User ID', function() { }); it('handles config with empty usersync object', function () { - setSubmoduleRegistry([pubCommonIdSubmodule, unifiedIdSubmodule, id5IdSubmodule]); + setSubmoduleRegistry([pubCommonIdSubmodule, unifiedIdSubmodule, id5IdSubmodule, identityLinkSubmodule]); 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]); + setSubmoduleRegistry([pubCommonIdSubmodule, unifiedIdSubmodule, id5IdSubmodule, identityLinkSubmodule]); init(config); config.setConfig({ usersync: { @@ -218,7 +220,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]); + setSubmoduleRegistry([pubCommonIdSubmodule, unifiedIdSubmodule, id5IdSubmodule, identityLinkSubmodule]); init(config); config.setConfig({ usersync: { @@ -235,15 +237,15 @@ describe('User ID', function() { }); it('config with 1 configurations should create 1 submodules', function () { - setSubmoduleRegistry([pubCommonIdSubmodule, unifiedIdSubmodule, id5IdSubmodule]); + setSubmoduleRegistry([pubCommonIdSubmodule, unifiedIdSubmodule, id5IdSubmodule, identityLinkSubmodule]); init(config); config.setConfig(getConfigMock(['unifiedId', 'unifiedid', 'cookie'])); expect(utils.logInfo.args[0][0]).to.exist.and.to.equal('User ID - usersync config updated for 1 submodules'); }); - it('config with 3 configurations should result in 3 submodules add', function () { - setSubmoduleRegistry([pubCommonIdSubmodule, unifiedIdSubmodule, id5IdSubmodule]); + it('config with 4 configurations should result in 4 submodules add', function () { + setSubmoduleRegistry([pubCommonIdSubmodule, unifiedIdSubmodule, id5IdSubmodule, identityLinkSubmodule]); init(config); config.setConfig({ usersync: { @@ -256,14 +258,17 @@ describe('User ID', function() { }, { name: 'id5Id', storage: { name: 'id5id', type: 'cookie' } + }, { + name: 'identityLink', + storage: { name: 'idl_env', type: 'cookie' } }] } }); - expect(utils.logInfo.args[0][0]).to.exist.and.to.equal('User ID - usersync config updated for 3 submodules'); + expect(utils.logInfo.args[0][0]).to.exist.and.to.equal('User ID - usersync config updated for 4 submodules'); }); it('config syncDelay updates module correctly', function () { - setSubmoduleRegistry([pubCommonIdSubmodule, unifiedIdSubmodule, id5IdSubmodule]); + setSubmoduleRegistry([pubCommonIdSubmodule, unifiedIdSubmodule, id5IdSubmodule, identityLinkSubmodule]); init(config); config.setConfig({ usersync: { @@ -349,6 +354,46 @@ describe('User ID', function() { }, {adUnits}); }); + it('test hook from identityLink html5', function(done) { + // simulate existing browser local storage values + localStorage.setItem('idl_env', 'AiGNC8Z5ONyZKSpIPf'); + localStorage.setItem('idl_env_exp', ''); + + setSubmoduleRegistry([identityLinkSubmodule]); + init(config); + config.setConfig(getConfigMock(['identityLink', 'idl_env', 'html5'])); + requestBidsHook(function() { + adUnits.forEach(unit => { + unit.bids.forEach(bid => { + expect(bid).to.have.deep.nested.property('userId.idl_env'); + expect(bid.userId.idl_env).to.equal('AiGNC8Z5ONyZKSpIPf'); + }); + }); + localStorage.removeItem('idl_env'); + localStorage.removeItem('idl_env_exp'); + done(); + }, {adUnits}); + }); + + it('test hook from identityLink cookie', function(done) { + utils.setCookie('idl_env', 'AiGNC8Z5ONyZKSpIPf', (new Date(Date.now() + 100000).toUTCString())); + + setSubmoduleRegistry([identityLinkSubmodule]); + init(config); + config.setConfig(getConfigMock(['identityLink', 'idl_env', 'cookie'])); + + requestBidsHook(function() { + adUnits.forEach(unit => { + unit.bids.forEach(bid => { + expect(bid).to.have.deep.nested.property('userId.idl_env'); + expect(bid.userId.idl_env).to.equal('AiGNC8Z5ONyZKSpIPf'); + }); + }); + utils.setCookie('idl_env', '', EXPIRED_COOKIE_DATE); + done(); + }, {adUnits}); + }); + it('test hook from id5id cookies', function(done) { // simulate existing browser local storage values utils.setCookie('id5id', JSON.stringify({'ID5ID': 'testid5id'}), (new Date(Date.now() + 5000).toUTCString())); @@ -373,12 +418,14 @@ describe('User ID', function() { utils.setCookie('pubcid', 'testpubcid', (new Date(Date.now() + 5000).toUTCString())); utils.setCookie('unifiedid', JSON.stringify({'TDID': 'testunifiedid'}), (new Date(Date.now() + 5000).toUTCString())); utils.setCookie('id5id', JSON.stringify({'ID5ID': 'testid5id'}), (new Date(Date.now() + 5000).toUTCString())); + utils.setCookie('idl_env', 'AiGNC8Z5ONyZKSpIPf', (new Date(Date.now() + 5000).toUTCString())); - setSubmoduleRegistry([pubCommonIdSubmodule, unifiedIdSubmodule, id5IdSubmodule]); + setSubmoduleRegistry([pubCommonIdSubmodule, unifiedIdSubmodule, id5IdSubmodule, identityLinkSubmodule]); init(config); config.setConfig(getConfigMock(['pubCommonId', 'pubcid', 'cookie'], ['unifiedId', 'unifiedid', 'cookie'], - ['id5Id', 'id5id', 'cookie'])); + ['id5Id', 'id5id', 'cookie'], + ['identityLink', 'idl_env', 'cookie'])); requestBidsHook(function() { adUnits.forEach(unit => { @@ -392,11 +439,15 @@ describe('User ID', function() { // also check that Id5Id id data was copied to bid expect(bid).to.have.deep.nested.property('userId.id5id'); expect(bid.userId.id5id).to.equal('testid5id'); + // check that identityLink id data was copied to bid + expect(bid).to.have.deep.nested.property('userId.idl_env'); + expect(bid.userId.idl_env).to.equal('AiGNC8Z5ONyZKSpIPf'); }); }); utils.setCookie('pubcid', '', EXPIRED_COOKIE_DATE); utils.setCookie('unifiedid', '', EXPIRED_COOKIE_DATE); utils.setCookie('id5id', '', EXPIRED_COOKIE_DATE); + utils.setCookie('idl_env', '', EXPIRED_COOKIE_DATE); done(); }, {adUnits}); }); @@ -405,6 +456,7 @@ describe('User ID', function() { utils.setCookie('pubcid', 'testpubcid', (new Date(Date.now() + 5000).toUTCString())); utils.setCookie('unifiedid', JSON.stringify({'TDID': 'cookie-value-add-module-variations'}), new Date(Date.now() + 5000).toUTCString()); utils.setCookie('id5id', JSON.stringify({'ID5ID': 'testid5id'}), (new Date(Date.now() + 5000).toUTCString())); + utils.setCookie('idl_env', 'AiGNC8Z5ONyZKSpIPf', new Date(Date.now() + 5000).toUTCString()); setSubmoduleRegistry([]); @@ -416,10 +468,12 @@ describe('User ID', function() { // attaching after init attachIdSystem(unifiedIdSubmodule); attachIdSystem(id5IdSubmodule); + attachIdSystem(identityLinkSubmodule); config.setConfig(getConfigMock(['pubCommonId', 'pubcid', 'cookie'], ['unifiedId', 'unifiedid', 'cookie'], - ['id5Id', 'id5id', 'cookie'])); + ['id5Id', 'id5id', 'cookie'], + ['identityLink', 'idl_env', 'cookie'])); requestBidsHook(function() { adUnits.forEach(unit => { @@ -433,11 +487,15 @@ describe('User ID', function() { // also check that Id5Id id data was copied to bid expect(bid).to.have.deep.nested.property('userId.id5id'); expect(bid.userId.id5id).to.equal('testid5id'); + // also check that identityLink id data was copied to bid + expect(bid).to.have.deep.nested.property('userId.idl_env'); + expect(bid.userId.idl_env).to.equal('AiGNC8Z5ONyZKSpIPf'); }); }); utils.setCookie('pubcid', '', EXPIRED_COOKIE_DATE); utils.setCookie('unifiedid', '', EXPIRED_COOKIE_DATE); utils.setCookie('id5id', '', EXPIRED_COOKIE_DATE); + utils.setCookie('idl_env', '', EXPIRED_COOKIE_DATE); done(); }, {adUnits}); }); @@ -446,9 +504,10 @@ describe('User ID', function() { utils.setCookie('pubcid', 'testpubcid', (new Date(Date.now() + 5000).toUTCString())); utils.setCookie('unifiedid', JSON.stringify({'TDID': 'cookie-value-add-module-variations'}), new Date(Date.now() + 5000).toUTCString()); utils.setCookie('id5id', JSON.stringify({'ID5ID': 'testid5id'}), (new Date(Date.now() + 5000).toUTCString())); + utils.setCookie('idl_env', 'AiGNC8Z5ONyZKSpIPf', new Date(Date.now() + 5000).toUTCString()); utils.setCookie('MOCKID', JSON.stringify({'MOCKID': '123456778'}), new Date(Date.now() + 5000).toUTCString()); - setSubmoduleRegistry([pubCommonIdSubmodule, unifiedIdSubmodule, id5IdSubmodule]); + setSubmoduleRegistry([pubCommonIdSubmodule, unifiedIdSubmodule, id5IdSubmodule, identityLinkSubmodule]); init(config); config.setConfig({ @@ -460,6 +519,8 @@ describe('User ID', function() { name: 'unifiedId', storage: { name: 'unifiedid', type: 'cookie' } }, { name: 'id5Id', storage: { name: 'id5id', type: 'cookie' } + }, { + name: 'identityLink', storage: { name: 'idl_env', type: 'cookie' } }, { name: 'mockId', storage: { name: 'MOCKID', type: 'cookie' } }] @@ -491,6 +552,9 @@ describe('User ID', function() { // also check that Id5Id id data was copied to bid expect(bid).to.have.deep.nested.property('userId.id5id'); expect(bid.userId.id5id).to.equal('testid5id'); + // also check that identityLink id data was copied to bid + expect(bid).to.have.deep.nested.property('userId.idl_env'); + expect(bid.userId.idl_env).to.equal('AiGNC8Z5ONyZKSpIPf'); // check MockId data was copied to bid expect(bid).to.have.deep.nested.property('userId.mid'); expect(bid.userId.mid).to.equal('123456778'); @@ -499,6 +563,7 @@ describe('User ID', function() { utils.setCookie('pubcid', '', EXPIRED_COOKIE_DATE); utils.setCookie('unifiedid', '', EXPIRED_COOKIE_DATE); utils.setCookie('id5id', '', EXPIRED_COOKIE_DATE); + utils.setCookie('idl_env', '', EXPIRED_COOKIE_DATE); utils.setCookie('MOCKID', '', EXPIRED_COOKIE_DATE); done(); }, {adUnits});