From bfb41d2b6442735cb30c747cc4ce64e0b434f073 Mon Sep 17 00:00:00 2001 From: "AzureAD\\AnnaVane" Date: Thu, 12 May 2022 15:44:18 +0200 Subject: [PATCH 01/22] - TNCID UserID Module --- modules/TNCIDIdSystem.js | 46 ++++++++++++++++++++++++++++++++++++++++ modules/TNCIDIdSystem.md | 23 ++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 modules/TNCIDIdSystem.js create mode 100644 modules/TNCIDIdSystem.md diff --git a/modules/TNCIDIdSystem.js b/modules/TNCIDIdSystem.js new file mode 100644 index 00000000000..beb614bed3e --- /dev/null +++ b/modules/TNCIDIdSystem.js @@ -0,0 +1,46 @@ +import { submodule } from '../src/hook.js'; +import { logInfo } from '../src/utils.js' + +const MODULE_NAME = 'TNCID'; + +const tncCallback = function (cb) { + let tnc = window.__tnc; + + if (tnc) { + tnc.ready(function () { + if (tnc.tncid) { + cb(tnc.tncid); + } else { + tnc.on('data-sent', () => { + cb(tnc.tncid); + }); + } + }); + } else { + cb(); + } +} + +export const tncidSubModule = { + name: MODULE_NAME, + decode(id) { + return { + TNCID: id + }; + }, + gvlid: 750, + getId(config, consentData) { + const gdpr = (consentData && typeof consentData.gdprApplies === 'boolean' && consentData.gdprApplies) ? 1 : 0; + const consentString = gdpr ? consentData.consentString : ''; + if (gdpr && !consentString) { + logInfo('Consent string is required for TNCID module'); + return; + } + + return { + callback: tncCallback + } + } +} + +submodule('userId', tncidSubModule) diff --git a/modules/TNCIDIdSystem.md b/modules/TNCIDIdSystem.md new file mode 100644 index 00000000000..cc224365b7a --- /dev/null +++ b/modules/TNCIDIdSystem.md @@ -0,0 +1,23 @@ +# TNCID UserID Module + +### Prebid Configuration + +First, make sure to add the TNCID submodule to your Prebid.js package with: + +``` +gulp build --modules=TNCIDIdSystem,userId +``` + +You can configure this submodule in your `userSync.userIds[]` configuration: + +```javascript +pbjs.setConfig({ + userSync: { + userIds: [ + { + name: 'TNCID', + }, + ], + }, +}); +``` From d6221b0d3ec2edbe00f39d6bbbb5f5309182b25c Mon Sep 17 00:00:00 2001 From: "AzureAD\\AnnaVane" Date: Thu, 12 May 2022 15:52:44 +0200 Subject: [PATCH 02/22] revert --- modules/TNCIDIdSystem.js | 46 ---------------------------------------- modules/TNCIDIdSystem.md | 23 -------------------- 2 files changed, 69 deletions(-) delete mode 100644 modules/TNCIDIdSystem.js delete mode 100644 modules/TNCIDIdSystem.md diff --git a/modules/TNCIDIdSystem.js b/modules/TNCIDIdSystem.js deleted file mode 100644 index beb614bed3e..00000000000 --- a/modules/TNCIDIdSystem.js +++ /dev/null @@ -1,46 +0,0 @@ -import { submodule } from '../src/hook.js'; -import { logInfo } from '../src/utils.js' - -const MODULE_NAME = 'TNCID'; - -const tncCallback = function (cb) { - let tnc = window.__tnc; - - if (tnc) { - tnc.ready(function () { - if (tnc.tncid) { - cb(tnc.tncid); - } else { - tnc.on('data-sent', () => { - cb(tnc.tncid); - }); - } - }); - } else { - cb(); - } -} - -export const tncidSubModule = { - name: MODULE_NAME, - decode(id) { - return { - TNCID: id - }; - }, - gvlid: 750, - getId(config, consentData) { - const gdpr = (consentData && typeof consentData.gdprApplies === 'boolean' && consentData.gdprApplies) ? 1 : 0; - const consentString = gdpr ? consentData.consentString : ''; - if (gdpr && !consentString) { - logInfo('Consent string is required for TNCID module'); - return; - } - - return { - callback: tncCallback - } - } -} - -submodule('userId', tncidSubModule) diff --git a/modules/TNCIDIdSystem.md b/modules/TNCIDIdSystem.md deleted file mode 100644 index cc224365b7a..00000000000 --- a/modules/TNCIDIdSystem.md +++ /dev/null @@ -1,23 +0,0 @@ -# TNCID UserID Module - -### Prebid Configuration - -First, make sure to add the TNCID submodule to your Prebid.js package with: - -``` -gulp build --modules=TNCIDIdSystem,userId -``` - -You can configure this submodule in your `userSync.userIds[]` configuration: - -```javascript -pbjs.setConfig({ - userSync: { - userIds: [ - { - name: 'TNCID', - }, - ], - }, -}); -``` From a497bc7f435ce928f7ed992c4ea8f748fd813afb Mon Sep 17 00:00:00 2001 From: "AzureAD\\AnnaVane" Date: Thu, 12 May 2022 15:56:24 +0200 Subject: [PATCH 03/22] - TNCID UserID Module --- modules/TNCIDIdSystem.js | 46 ++++++++++++++++++++++++++++++++++++++++ modules/TNCIDIdSystem.md | 23 ++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 modules/TNCIDIdSystem.js create mode 100644 modules/TNCIDIdSystem.md diff --git a/modules/TNCIDIdSystem.js b/modules/TNCIDIdSystem.js new file mode 100644 index 00000000000..beb614bed3e --- /dev/null +++ b/modules/TNCIDIdSystem.js @@ -0,0 +1,46 @@ +import { submodule } from '../src/hook.js'; +import { logInfo } from '../src/utils.js' + +const MODULE_NAME = 'TNCID'; + +const tncCallback = function (cb) { + let tnc = window.__tnc; + + if (tnc) { + tnc.ready(function () { + if (tnc.tncid) { + cb(tnc.tncid); + } else { + tnc.on('data-sent', () => { + cb(tnc.tncid); + }); + } + }); + } else { + cb(); + } +} + +export const tncidSubModule = { + name: MODULE_NAME, + decode(id) { + return { + TNCID: id + }; + }, + gvlid: 750, + getId(config, consentData) { + const gdpr = (consentData && typeof consentData.gdprApplies === 'boolean' && consentData.gdprApplies) ? 1 : 0; + const consentString = gdpr ? consentData.consentString : ''; + if (gdpr && !consentString) { + logInfo('Consent string is required for TNCID module'); + return; + } + + return { + callback: tncCallback + } + } +} + +submodule('userId', tncidSubModule) diff --git a/modules/TNCIDIdSystem.md b/modules/TNCIDIdSystem.md new file mode 100644 index 00000000000..cc224365b7a --- /dev/null +++ b/modules/TNCIDIdSystem.md @@ -0,0 +1,23 @@ +# TNCID UserID Module + +### Prebid Configuration + +First, make sure to add the TNCID submodule to your Prebid.js package with: + +``` +gulp build --modules=TNCIDIdSystem,userId +``` + +You can configure this submodule in your `userSync.userIds[]` configuration: + +```javascript +pbjs.setConfig({ + userSync: { + userIds: [ + { + name: 'TNCID', + }, + ], + }, +}); +``` From d8480610eca4957cfe049214f581216db7e67c9b Mon Sep 17 00:00:00 2001 From: "AzureAD\\AnnaVane" Date: Fri, 13 May 2022 12:29:23 +0200 Subject: [PATCH 04/22] - TNCID UserID Module --- modules/TNCIDIdSystem.js | 38 +++++++++++++++++++++++-- test/spec/modules/TNCIDIdSystem_spec.js | 26 +++++++++++++++++ 2 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 test/spec/modules/TNCIDIdSystem_spec.js diff --git a/modules/TNCIDIdSystem.js b/modules/TNCIDIdSystem.js index beb614bed3e..01bc08aac99 100644 --- a/modules/TNCIDIdSystem.js +++ b/modules/TNCIDIdSystem.js @@ -3,11 +3,41 @@ import { logInfo } from '../src/utils.js' const MODULE_NAME = 'TNCID'; -const tncCallback = function (cb) { - let tnc = window.__tnc; +const loadTNCScript = () => { + let tncOptions = { + autostart: true, + tcf: true, + getFiles: { + options: false, // true + callback: false, // true + prepare: false, // false + scripts: false, // true + } + }; + let t = window + , n = t.document + , c = '__tncPbjs' + , i = 'c8549079-f149-4529-a34b-3fa91ef257d1' + , d = tncOptions; + + try { + t[c] = t[c] || {}; t[c].providerId = i; t[c].options = t[c].options || d; + var f = 'ready'; t[c][f] = t[c][f] || function (z) { + t[c][f].q = t[c][f].q || []; t[c][f].q.push(z); + return t[c]; + }; var s = n.createElement('script'); s.setAttribute('global', c); s.async = !0; + s.defer = !0; s.id = 'tnc_route'; s.src = 'https://js.tncid.app/route.js'; + n.querySelector('head,body').appendChild(s); + } catch (err) { console.log(err); } + + return window.__tncPbjs; +} + +const tncCallback = (cb) => { + let tnc = window.__tnc || loadTNCScript(); if (tnc) { - tnc.ready(function () { + tnc.ready(() => { if (tnc.tncid) { cb(tnc.tncid); } else { @@ -16,9 +46,11 @@ const tncCallback = function (cb) { }); } }); + } else { cb(); } + } export const tncidSubModule = { diff --git a/test/spec/modules/TNCIDIdSystem_spec.js b/test/spec/modules/TNCIDIdSystem_spec.js new file mode 100644 index 00000000000..a59abe14d1d --- /dev/null +++ b/test/spec/modules/TNCIDIdSystem_spec.js @@ -0,0 +1,26 @@ +import { TNCIDIdSystem } from 'modules/TNCIDIdSystem.js'; + +const TNCID_TEST_ID = "TNCID_TEST_ID"; + +const consentData = { + gdprApplies: true, + consentString: 'GDPR_CONSENT_STRING' +}; + +describe('TNCID tests', function () { + + beforeEach(function () { + logErrorStub = sinon.stub(utils, 'logError'); + }); + + it('should NOT give TNCID if gdpr applies but consent string is missing', function () { + let TNCIDCallback = TNCIDIdSystem.getId(null, { gdprApplies: true }); + expect(TNCIDCallback).to.be.undefined; + }); + + it('GDPR is OK and TNCID is returned', function () { + let TNCIDCallback = TNCIDIdSystem.getId(null, consentData); + expect(TNCIDCallback).to.be.eq({TNCID: TNCID_TEST_ID}); + }); + +}); From 37965880c14b1af92a3553626462dc1baa4106ee Mon Sep 17 00:00:00 2001 From: micheletnc Date: Fri, 13 May 2022 15:12:56 +0200 Subject: [PATCH 05/22] Converted loadTNCScript to Promise --- modules/TNCIDIdSystem.js | 76 +++++++++++++++++++++++++++++++++------- 1 file changed, 63 insertions(+), 13 deletions(-) diff --git a/modules/TNCIDIdSystem.js b/modules/TNCIDIdSystem.js index beb614bed3e..e6a3a5f8ef2 100644 --- a/modules/TNCIDIdSystem.js +++ b/modules/TNCIDIdSystem.js @@ -2,24 +2,71 @@ import { submodule } from '../src/hook.js'; import { logInfo } from '../src/utils.js' const MODULE_NAME = 'TNCID'; +const FALLBACK_TNC_INSTANCE = '__tncPbjs'; +const FALLBACK_TNC_PROVIDERID = 'c8549079-f149-4529-a34b-3fa91ef257d1'; +const loadTNCScript = function (tncInstance, providerId) { + try { + let tncOptions = { + autostart: true, + tcf: true, + getFiles: { + cacheid: false, // true + options: false, // true + callback: false, // true + prepare: false, // false + scripts: false // true + } + }; + let t = window; + let n = t.document; + let c = tncInstance; + let i = providerId; + let d = tncOptions; -const tncCallback = function (cb) { - let tnc = window.__tnc; + t[c] = t[c] || {}; t[c].providerId = i; t[c].options = t[c].options || d; + var f = 'ready'; t[c][f] = t[c][f] || function (z) { + t[c][f].q = t[c][f].q || []; t[c][f].q.push(z); + return t[c]; + }; var s = n.createElement('script'); s.setAttribute('global', c); s.async = !0; + s.defer = !0; s.id = 'tnc_route'; s.src = 'https://js.tncid.app/route.js'; + n.querySelector('head,body').appendChild(s); - if (tnc) { - tnc.ready(function () { - if (tnc.tncid) { - cb(tnc.tncid); - } else { - tnc.on('data-sent', () => { - cb(tnc.tncid); + return new Promise((resolve, reject) => { + try { + t[c].ready(() => { + t[c].on('data-sent', () => resolve(t[c])); }); + } catch (err) { + reject(err); } }); - } else { - cb(); + } catch (err) { + return Promise.reject(err); } } +const tncCallback = function (providerId, cb) { + let promise = window.__tnc || window[FALLBACK_TNC_INSTANCE] + ? Promise.resolve(window.__tnc || window[FALLBACK_TNC_INSTANCE]) + : loadTNCScript(FALLBACK_TNC_INSTANCE, providerId); + + promise + .then(tnc => { + if (tnc) { + tnc.ready(function () { + if (tnc.tncid) { + cb(tnc.tncid); + } else { + tnc.on('data-sent', () => { + cb(tnc.tncid); + }); + } + }); + } else { + cb(); + } + }) + .catch(() => cb()); +} export const tncidSubModule = { name: MODULE_NAME, @@ -29,16 +76,19 @@ export const tncidSubModule = { }; }, gvlid: 750, - getId(config, consentData) { + getId(config = {}, consentData) { const gdpr = (consentData && typeof consentData.gdprApplies === 'boolean' && consentData.gdprApplies) ? 1 : 0; const consentString = gdpr ? consentData.consentString : ''; + const { params } = config; + const providerId = (params || {}).providerId || FALLBACK_TNC_PROVIDERID; + if (gdpr && !consentString) { logInfo('Consent string is required for TNCID module'); return; } return { - callback: tncCallback + callback: function (cb) { return tncCallback(providerId, cb); } } } } From 2f754caa5d5025f433f27ec3fbf7cd0d150f3029 Mon Sep 17 00:00:00 2001 From: micheletnc Date: Fri, 13 May 2022 15:33:44 +0200 Subject: [PATCH 06/22] Added CacheID --- modules/TNCIDIdSystem.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/TNCIDIdSystem.js b/modules/TNCIDIdSystem.js index e6a3a5f8ef2..82a3a3e5359 100644 --- a/modules/TNCIDIdSystem.js +++ b/modules/TNCIDIdSystem.js @@ -10,7 +10,7 @@ const loadTNCScript = function (tncInstance, providerId) { autostart: true, tcf: true, getFiles: { - cacheid: false, // true + cacheid: true, // true options: false, // true callback: false, // true prepare: false, // false From 015e0a6b2536aa01d374ea1f2653fc46a23a5fa7 Mon Sep 17 00:00:00 2001 From: "AzureAD\\AnnaVane" Date: Thu, 19 May 2022 14:42:22 +0200 Subject: [PATCH 07/22] - TNCID UserID module --- modules/.submodules.json | 3 +- modules/TNCIDIdSystem.js | 65 ++++++--------- test/spec/modules/TNCIDIdSystem_spec.js | 106 +++++++++++++++++++++--- 3 files changed, 122 insertions(+), 52 deletions(-) diff --git a/modules/.submodules.json b/modules/.submodules.json index 59bae2013d1..f5b867f5f24 100644 --- a/modules/.submodules.json +++ b/modules/.submodules.json @@ -43,7 +43,8 @@ "unifiedIdSystem", "verizonMediaIdSystem", "zeotapIdPlusIdSystem", - "adqueryIdSystem" + "adqueryIdSystem", + "TNCIDIdSystem" ], "adpod": [ "freeWheelAdserverVideo", diff --git a/modules/TNCIDIdSystem.js b/modules/TNCIDIdSystem.js index 1f4daf60da1..78e6a47b54a 100644 --- a/modules/TNCIDIdSystem.js +++ b/modules/TNCIDIdSystem.js @@ -1,10 +1,12 @@ + import { submodule } from '../src/hook.js'; import { logInfo } from '../src/utils.js' const MODULE_NAME = 'TNCID'; -const FALLBACK_TNC_INSTANCE = '__tncPbjs'; const FALLBACK_TNC_PROVIDERID = 'c8549079-f149-4529-a34b-3fa91ef257d1'; -const loadTNCScript = function (tncInstance, providerId) { +const FALLBACK_TNC_INSTANCE = '__tncPbjs'; + +const loadRemoteTNCScript = (providerId) => { try { let tncOptions = { autostart: true, @@ -19,7 +21,7 @@ const loadTNCScript = function (tncInstance, providerId) { }; let t = window; let n = t.document; - let c = tncInstance; + let c = FALLBACK_TNC_INSTANCE; let i = providerId; let d = tncOptions; @@ -30,43 +32,30 @@ const loadTNCScript = function (tncInstance, providerId) { }; var s = n.createElement('script'); s.setAttribute('global', c); s.async = !0; s.defer = !0; s.id = 'tnc_route'; s.src = 'https://js.tncid.app/route.js'; n.querySelector('head,body').appendChild(s); + } catch (error) { } +} - return new Promise((resolve, reject) => { - try { - t[c].ready(() => { - t[c].on('data-sent', () => resolve(t[c])); - }); - } catch (err) { - reject(err); - } +const waitTNCScript = (tncNS) => { + return new Promise((resolve, reject) => { + var tnc = window[tncNS]; + if (!tnc) reject(new Error('No TNC Object')); + if (tnc.tncid) resolve(tnc.tncid); + tnc.ready(() => { + tnc = window[tncNS]; + if (tnc.tncid) resolve(tnc.tncid); + else tnc.on('data-sent', () => resolve(tnc.tncid)); }); - } catch (err) { - return Promise.reject(err); - } - + }); } + const tncCallback = function (providerId, cb) { - let promise = window.__tnc || window[FALLBACK_TNC_INSTANCE] - ? Promise.resolve(window.__tnc || window[FALLBACK_TNC_INSTANCE]) - : loadTNCScript(FALLBACK_TNC_INSTANCE, providerId); + let tncNS = '__tnc'; + if (!window[tncNS]) { + tncNS = FALLBACK_TNC_INSTANCE; + loadRemoteTNCScript(providerId); + } - promise - .then(tnc => { - if (tnc) { - tnc.ready(function () { - if (tnc.tncid) { - cb(tnc.tncid); - } else { - tnc.on('data-sent', () => { - cb(tnc.tncid); - }); - } - }); - } else { - cb(); - } - }) - .catch(() => cb()); + return waitTNCScript(tncNS).then(cb).catch(() => cb()); } export const tncidSubModule = { @@ -77,11 +66,11 @@ export const tncidSubModule = { }; }, gvlid: 750, - getId(config = {}, consentData) { + getId(config, consentData) { const gdpr = (consentData && typeof consentData.gdprApplies === 'boolean' && consentData.gdprApplies) ? 1 : 0; const consentString = gdpr ? consentData.consentString : ''; - const { params } = config; - const providerId = (params || {}).providerId || FALLBACK_TNC_PROVIDERID; + let providerId = FALLBACK_TNC_PROVIDERID; + if (config && config.params && config.params.providerId)providerId = config.params.providerId; if (gdpr && !consentString) { logInfo('Consent string is required for TNCID module'); diff --git a/test/spec/modules/TNCIDIdSystem_spec.js b/test/spec/modules/TNCIDIdSystem_spec.js index a59abe14d1d..cb53982d26b 100644 --- a/test/spec/modules/TNCIDIdSystem_spec.js +++ b/test/spec/modules/TNCIDIdSystem_spec.js @@ -1,26 +1,106 @@ -import { TNCIDIdSystem } from 'modules/TNCIDIdSystem.js'; - -const TNCID_TEST_ID = "TNCID_TEST_ID"; +import { tncidSubModule } from 'modules/TNCIDIdSystem'; const consentData = { gdprApplies: true, consentString: 'GDPR_CONSENT_STRING' -}; +}; describe('TNCID tests', function () { - - beforeEach(function () { - logErrorStub = sinon.stub(utils, 'logError'); + describe('name', () => { + it('should expose the name of the submodule', () => { + expect(tncidSubModule.name).to.equal('TNCID'); + }); }); - it('should NOT give TNCID if gdpr applies but consent string is missing', function () { - let TNCIDCallback = TNCIDIdSystem.getId(null, { gdprApplies: true }); - expect(TNCIDCallback).to.be.undefined; + describe('gvlid', () => { + it('should expose the vendor id', () => { + expect(tncidSubModule.gvlid).to.equal(750); + }); }); - it('GDPR is OK and TNCID is returned', function () { - let TNCIDCallback = TNCIDIdSystem.getId(null, consentData); - expect(TNCIDCallback).to.be.eq({TNCID: TNCID_TEST_ID}); + describe('decode', () => { + it('should wrap the given value inside an object literal', () => { + expect(tncidSubModule.decode('TNCID_TEST_ID')).to.deep.equal({ + TNCID: 'TNCID_TEST_ID' + }); + }); }); + describe('getId', () => { + afterEach(function () { + Object.defineProperty(window, '__tnc', {value: undefined, configurable: true}); + Object.defineProperty(window, '__tncPbjs', {value: undefined, configurable: true}); + }); + + it('Should NOT give TNCID if GDPR applies but consent string is missing', function () { + const res = tncidSubModule.getId(null, { gdprApplies: true }); + expect(res).to.be.undefined; + }); + + it('GDPR is OK and page has no TNC script on page, script goes in error, no TNCID is returned', function () { + const completeCallback = sinon.spy(); + const {callback} = tncidSubModule.getId(null, consentData); + + return callback(completeCallback).then(() => { + expect(completeCallback.calledOnce).to.be.true; + }) + }); + + it('GDPR is OK and page has TNC script with ns: __tnc, present TNCID is returned', function () { + Object.defineProperty(window, '__tnc', { + value: { + ready: (readyFunc) => { readyFunc() }, + on: (name, cb) => { cb() }, + tncid: 'TNCID_TEST_ID_1' + }, + configurable: true + }); + + const completeCallback = sinon.spy(); + const {callback} = tncidSubModule.getId(null, { gdprApplies: false }); + + return callback(completeCallback).then(() => { + expect(completeCallback.calledOnceWithExactly('TNCID_TEST_ID_1')).to.be.true; + }) + }); + + it('GDPR is OK and page has TNC script with ns: __tnc but not loaded, TNCID is assigned and returned', function () { + Object.defineProperty(window, '__tnc', { + value: { + ready: (readyFunc) => { readyFunc() }, + on: (name, cb) => { cb() } + }, + configurable: true + }); + + const completeCallback = sinon.spy(); + const {callback} = tncidSubModule.getId(null, { gdprApplies: false }); + + return callback(completeCallback).then(() => { + expect(completeCallback.calledOnce).to.be.true; + }) + }); + + it('GDPR is OK and page has TNC script with ns: __tncPbjs, TNCID is returned', function () { + Object.defineProperty(window, '__tncPbjs', { + value: { + ready: (readyFunc) => { readyFunc() }, + on: (name, cb) => { cb() }, + providerId: 'TEST_PROVIDER_ID_1', + options: {}, + tncid: 'TNCID_TEST_ID_2' + }, + configurable: true, + writable: true + }); + + const completeCallback = sinon.spy(); + const {callback} = tncidSubModule.getId({params: {providerId: 'TEST_PROVIDER_ID_2'}}, consentData); + + return callback(completeCallback).then(() => { + expect(completeCallback.calledOnceWithExactly('TNCID_TEST_ID_2')).to.be.true; + expect(window.__tncPbjs.providerId).to.be.eq('TEST_PROVIDER_ID_2'); + }) + }); + }); }); From 85d543ea44751d7283334ef2c43a86fc1a89fef7 Mon Sep 17 00:00:00 2001 From: "AzureAD\\AnnaVane" Date: Thu, 19 May 2022 15:05:40 +0200 Subject: [PATCH 08/22] - Documentation updated --- modules/TNCIDIdSystem.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/modules/TNCIDIdSystem.md b/modules/TNCIDIdSystem.md index cc224365b7a..55892b377df 100644 --- a/modules/TNCIDIdSystem.md +++ b/modules/TNCIDIdSystem.md @@ -8,6 +8,8 @@ First, make sure to add the TNCID submodule to your Prebid.js package with: gulp build --modules=TNCIDIdSystem,userId ``` +### TNCIDIdSystem module Configuration + You can configure this submodule in your `userSync.userIds[]` configuration: ```javascript @@ -16,8 +18,18 @@ pbjs.setConfig({ userIds: [ { name: 'TNCID', + params: { + providerId: "c8549079-f149-4529-a34b-3fa91ef257d1" //Optional + } }, ], }, }); ``` +#### Configuration Params + +| Param Name | Required | Type | Description | +| --- | --- | --- | --- | +| name | Required | String | ID value for the TNCID module: `"TNCID"` | +| params.providerId | Optional | String | Provide TNC providerId if possible | + From 71e6314f1ade2ec4dbb30cbe51d87cfab4f62589 Mon Sep 17 00:00:00 2001 From: "AzureAD\\AnnaVane" Date: Fri, 20 May 2022 09:51:51 +0200 Subject: [PATCH 09/22] - File naming fix --- modules/.submodules.json | 2 +- modules/{TNCIDIdSystem.js => tncIdSystem.js} | 4 ++-- modules/{TNCIDIdSystem.md => tncIdSystem.md} | 15 +++++++-------- modules/userId/eids.js | 6 ++++++ ...{TNCIDIdSystem_spec.js => tncIdSystem_spec.js} | 12 +++++++----- 5 files changed, 23 insertions(+), 16 deletions(-) rename modules/{TNCIDIdSystem.js => tncIdSystem.js} (98%) rename modules/{TNCIDIdSystem.md => tncIdSystem.md} (70%) rename test/spec/modules/{TNCIDIdSystem_spec.js => tncIdSystem_spec.js} (91%) diff --git a/modules/.submodules.json b/modules/.submodules.json index f5b867f5f24..bb12d0932bc 100644 --- a/modules/.submodules.json +++ b/modules/.submodules.json @@ -44,7 +44,7 @@ "verizonMediaIdSystem", "zeotapIdPlusIdSystem", "adqueryIdSystem", - "TNCIDIdSystem" + "tncIdSystem" ], "adpod": [ "freeWheelAdserverVideo", diff --git a/modules/TNCIDIdSystem.js b/modules/tncIdSystem.js similarity index 98% rename from modules/TNCIDIdSystem.js rename to modules/tncIdSystem.js index 78e6a47b54a..c666e275787 100644 --- a/modules/TNCIDIdSystem.js +++ b/modules/tncIdSystem.js @@ -2,7 +2,7 @@ import { submodule } from '../src/hook.js'; import { logInfo } from '../src/utils.js' -const MODULE_NAME = 'TNCID'; +const MODULE_NAME = 'tncId'; const FALLBACK_TNC_PROVIDERID = 'c8549079-f149-4529-a34b-3fa91ef257d1'; const FALLBACK_TNC_INSTANCE = '__tncPbjs'; @@ -62,7 +62,7 @@ export const tncidSubModule = { name: MODULE_NAME, decode(id) { return { - TNCID: id + tncid: id }; }, gvlid: 750, diff --git a/modules/TNCIDIdSystem.md b/modules/tncIdSystem.md similarity index 70% rename from modules/TNCIDIdSystem.md rename to modules/tncIdSystem.md index 55892b377df..d4393469476 100644 --- a/modules/TNCIDIdSystem.md +++ b/modules/tncIdSystem.md @@ -5,7 +5,7 @@ First, make sure to add the TNCID submodule to your Prebid.js package with: ``` -gulp build --modules=TNCIDIdSystem,userId +gulp build --modules=tncIdSystem,userId ``` ### TNCIDIdSystem module Configuration @@ -17,19 +17,18 @@ pbjs.setConfig({ userSync: { userIds: [ { - name: 'TNCID', + name: 'tncId', params: { - providerId: "c8549079-f149-4529-a34b-3fa91ef257d1" //Optional + providerId: "c8549079-f149-4529-a34b-3fa91ef257d1" // Optional } - }, - ], - }, + } + ] + } }); ``` #### Configuration Params | Param Name | Required | Type | Description | | --- | --- | --- | --- | -| name | Required | String | ID value for the TNCID module: `"TNCID"` | +| name | Required | String | ID value for the TNCID module: `"tncId"` | | params.providerId | Optional | String | Provide TNC providerId if possible | - diff --git a/modules/userId/eids.js b/modules/userId/eids.js index 9c995a52fe3..c886aa34b68 100644 --- a/modules/userId/eids.js +++ b/modules/userId/eids.js @@ -314,6 +314,12 @@ export const USER_IDS_CONFIG = { return data.envelope; } }, + + // tncId + 'tncId': { + source: 'thenewco.it', + atype: 1 + }, }; // this function will create an eid object for the given UserId sub-module diff --git a/test/spec/modules/TNCIDIdSystem_spec.js b/test/spec/modules/tncIdSystem_spec.js similarity index 91% rename from test/spec/modules/TNCIDIdSystem_spec.js rename to test/spec/modules/tncIdSystem_spec.js index cb53982d26b..2a4697d98fc 100644 --- a/test/spec/modules/TNCIDIdSystem_spec.js +++ b/test/spec/modules/tncIdSystem_spec.js @@ -1,4 +1,4 @@ -import { tncidSubModule } from 'modules/TNCIDIdSystem'; +import { tncidSubModule } from 'modules/tncIdSystem'; const consentData = { gdprApplies: true, @@ -8,7 +8,7 @@ const consentData = { describe('TNCID tests', function () { describe('name', () => { it('should expose the name of the submodule', () => { - expect(tncidSubModule.name).to.equal('TNCID'); + expect(tncidSubModule.name).to.equal('tncId'); }); }); @@ -21,7 +21,7 @@ describe('TNCID tests', function () { describe('decode', () => { it('should wrap the given value inside an object literal', () => { expect(tncidSubModule.decode('TNCID_TEST_ID')).to.deep.equal({ - TNCID: 'TNCID_TEST_ID' + tncid: 'TNCID_TEST_ID' }); }); }); @@ -51,7 +51,8 @@ describe('TNCID tests', function () { value: { ready: (readyFunc) => { readyFunc() }, on: (name, cb) => { cb() }, - tncid: 'TNCID_TEST_ID_1' + tncid: 'TNCID_TEST_ID_1', + providerId: 'TEST_PROVIDER_ID_1', }, configurable: true }); @@ -68,7 +69,8 @@ describe('TNCID tests', function () { Object.defineProperty(window, '__tnc', { value: { ready: (readyFunc) => { readyFunc() }, - on: (name, cb) => { cb() } + on: (name, cb) => { cb() }, + providerId: 'TEST_PROVIDER_ID_1', }, configurable: true }); From 850dc779dd00500a3b301712ab0cf9a191935591 Mon Sep 17 00:00:00 2001 From: "AzureAD\\AnnaVane" Date: Fri, 20 May 2022 10:41:28 +0200 Subject: [PATCH 10/22] - type fix --- modules/userId/eids.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/userId/eids.js b/modules/userId/eids.js index c886aa34b68..e99308f657c 100644 --- a/modules/userId/eids.js +++ b/modules/userId/eids.js @@ -318,7 +318,7 @@ export const USER_IDS_CONFIG = { // tncId 'tncId': { source: 'thenewco.it', - atype: 1 + atype: 3 }, }; From 3ff4377380d87f838fe3b6ff154704d5b44b897a Mon Sep 17 00:00:00 2001 From: "AzureAD\\AnnaVane" Date: Mon, 23 May 2022 12:43:37 +0200 Subject: [PATCH 11/22] -no change --- test/spec/modules/tncIdSystem_spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/spec/modules/tncIdSystem_spec.js b/test/spec/modules/tncIdSystem_spec.js index 2a4697d98fc..2c84e25100b 100644 --- a/test/spec/modules/tncIdSystem_spec.js +++ b/test/spec/modules/tncIdSystem_spec.js @@ -92,7 +92,7 @@ describe('TNCID tests', function () { options: {}, tncid: 'TNCID_TEST_ID_2' }, - configurable: true, + configurable: true, writable: true }); From 1f5daadd8cde6e1db47acac4051648bbeb0292f4 Mon Sep 17 00:00:00 2001 From: "AzureAD\\AnnaVane" Date: Mon, 23 May 2022 13:28:35 +0200 Subject: [PATCH 12/22] - space removed --- test/spec/modules/tncIdSystem_spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/spec/modules/tncIdSystem_spec.js b/test/spec/modules/tncIdSystem_spec.js index 2c84e25100b..2a4697d98fc 100644 --- a/test/spec/modules/tncIdSystem_spec.js +++ b/test/spec/modules/tncIdSystem_spec.js @@ -92,7 +92,7 @@ describe('TNCID tests', function () { options: {}, tncid: 'TNCID_TEST_ID_2' }, - configurable: true, + configurable: true, writable: true }); From 950469baed0bb958b7ffc7dea107de959f005eea Mon Sep 17 00:00:00 2001 From: "AzureAD\\AnnaVane" Date: Mon, 23 May 2022 18:03:41 +0200 Subject: [PATCH 13/22] new line removed --- modules/tncIdSystem.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/tncIdSystem.js b/modules/tncIdSystem.js index c666e275787..0fdb2c84fc1 100644 --- a/modules/tncIdSystem.js +++ b/modules/tncIdSystem.js @@ -1,6 +1,5 @@ - import { submodule } from '../src/hook.js'; -import { logInfo } from '../src/utils.js' +import { logInfo } from '../src/utils.js'; const MODULE_NAME = 'tncId'; const FALLBACK_TNC_PROVIDERID = 'c8549079-f149-4529-a34b-3fa91ef257d1'; From 34505bfaef3dac5efb8882649f354e084776bd03 Mon Sep 17 00:00:00 2001 From: "AzureAD\\AnnaVane" Date: Tue, 24 May 2022 10:37:23 +0200 Subject: [PATCH 14/22] - lint fix --- modules/userId/eids.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/userId/eids.js b/modules/userId/eids.js index f15fc7b51ed..31620871659 100644 --- a/modules/userId/eids.js +++ b/modules/userId/eids.js @@ -314,19 +314,19 @@ export const USER_IDS_CONFIG = { return data.envelope; } }, - + // tncId 'tncId': { source: 'thenewco.it', atype: 3 }, - + // Gravito MP ID 'gravitompId': { source: 'gravito.net', atype: 1 }, - + }; // this function will create an eid object for the given UserId sub-module From bd60ddc5b02dd9f987e5b0ce32293b1652eb5a8e Mon Sep 17 00:00:00 2001 From: "AzureAD\\AnnaVane" Date: Tue, 24 May 2022 15:11:50 +0200 Subject: [PATCH 15/22] - eids fix --- modules/userId/eids.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/userId/eids.js b/modules/userId/eids.js index 31620871659..dda5ee5cfce 100644 --- a/modules/userId/eids.js +++ b/modules/userId/eids.js @@ -316,7 +316,7 @@ export const USER_IDS_CONFIG = { }, // tncId - 'tncId': { + 'tncid': { source: 'thenewco.it', atype: 3 }, From 799f6c17caffcd983d0fb01c8208b4a14d3a3b62 Mon Sep 17 00:00:00 2001 From: "AzureAD\\AnnaVane" Date: Mon, 30 May 2022 15:28:07 +0200 Subject: [PATCH 16/22] - .submodules.json: module name moved in alphabetical order - modules/tncIdSystem.md: spacing fix - added eids.md, user id spec and eids spec --- modules/.submodules.json | 2 +- modules/tncIdSystem.md | 21 ++++++++++----------- modules/userId/eids.md | 7 +++++++ modules/userId/userId.md | 17 +++++++++++++++++ 4 files changed, 35 insertions(+), 12 deletions(-) diff --git a/modules/.submodules.json b/modules/.submodules.json index 2709e95418d..0c7f49551ab 100644 --- a/modules/.submodules.json +++ b/modules/.submodules.json @@ -38,12 +38,12 @@ "quantcastIdSystem", "sharedIdSystem", "tapadIdSystem", + "tncIdSystem", "trustpidSystem", "uid2IdSystem", "unifiedIdSystem", "verizonMediaIdSystem", "zeotapIdPlusIdSystem", - "tncIdSystem", "adqueryIdSystem", "gravitoIdSystem" ], diff --git a/modules/tncIdSystem.md b/modules/tncIdSystem.md index d4393469476..dec5e53ddad 100644 --- a/modules/tncIdSystem.md +++ b/modules/tncIdSystem.md @@ -2,7 +2,7 @@ ### Prebid Configuration -First, make sure to add the TNCID submodule to your Prebid.js package with: +First, make sure to add the TNCID submodule to your Prebid.js package with: ``` gulp build --modules=tncIdSystem,userId @@ -14,16 +14,15 @@ You can configure this submodule in your `userSync.userIds[]` configuration: ```javascript pbjs.setConfig({ - userSync: { - userIds: [ - { - name: 'tncId', - params: { - providerId: "c8549079-f149-4529-a34b-3fa91ef257d1" // Optional - } - } - ] - } + userSync: { + userIds: [{ + name: 'tncId', + params: { + providerId: "c8549079-f149-4529-a34b-3fa91ef257d1" // Optional + } + }], + syncDelay: 5000 + } }); ``` #### Configuration Params diff --git a/modules/userId/eids.md b/modules/userId/eids.md index 45237ac5f26..1abd5325fc6 100644 --- a/modules/userId/eids.md +++ b/modules/userId/eids.md @@ -247,6 +247,13 @@ userIdAsEids = [ id: 'some-random-id-value', atype: 3 }] + }, + { + source: 'thenewco.it', + uids: [{ + id: 'some-random-id-value', + atype: 3 + }] } ] ``` diff --git a/modules/userId/userId.md b/modules/userId/userId.md index 4b2338fa3eb..2c46d635dd8 100644 --- a/modules/userId/userId.md +++ b/modules/userId/userId.md @@ -388,3 +388,20 @@ pbjs.setConfig({ } }); ``` +``` + +Example showing how to configure a `params` object to pass directly to bid adapters + +``` +pbjs.setConfig({ + userSync: { + userIds: [{ + name: 'tncId', + params: { + providerId: "c8549079-f149-4529-a34b-3fa91ef257d1" + } + }], + syncDelay: 5000 + } +}); +``` From e185380fd80ba195cd03953c8b9bdc33a7267e11 Mon Sep 17 00:00:00 2001 From: "AzureAD\\AnnaVane" Date: Tue, 7 Jun 2022 18:04:18 +0200 Subject: [PATCH 17/22] - tnc script loaded by loadExternalScript util function --- modules/tncIdSystem.js | 41 +++++++-------------------- src/adloader.js | 3 +- test/spec/modules/tncIdSystem_spec.js | 2 +- 3 files changed, 13 insertions(+), 33 deletions(-) diff --git a/modules/tncIdSystem.js b/modules/tncIdSystem.js index 0fdb2c84fc1..54b8a5d93fb 100644 --- a/modules/tncIdSystem.js +++ b/modules/tncIdSystem.js @@ -1,39 +1,11 @@ import { submodule } from '../src/hook.js'; import { logInfo } from '../src/utils.js'; +import { loadExternalScript } from '../src/adloader.js'; const MODULE_NAME = 'tncId'; const FALLBACK_TNC_PROVIDERID = 'c8549079-f149-4529-a34b-3fa91ef257d1'; const FALLBACK_TNC_INSTANCE = '__tncPbjs'; -const loadRemoteTNCScript = (providerId) => { - try { - let tncOptions = { - autostart: true, - tcf: true, - getFiles: { - cacheid: true, // true - options: false, // true - callback: false, // true - prepare: false, // false - scripts: false // true - } - }; - let t = window; - let n = t.document; - let c = FALLBACK_TNC_INSTANCE; - let i = providerId; - let d = tncOptions; - - t[c] = t[c] || {}; t[c].providerId = i; t[c].options = t[c].options || d; - var f = 'ready'; t[c][f] = t[c][f] || function (z) { - t[c][f].q = t[c][f].q || []; t[c][f].q.push(z); - return t[c]; - }; var s = n.createElement('script'); s.setAttribute('global', c); s.async = !0; - s.defer = !0; s.id = 'tnc_route'; s.src = 'https://js.tncid.app/route.js'; - n.querySelector('head,body').appendChild(s); - } catch (error) { } -} - const waitTNCScript = (tncNS) => { return new Promise((resolve, reject) => { var tnc = window[tncNS]; @@ -47,14 +19,21 @@ const waitTNCScript = (tncNS) => { }); } +const loadRemoteScript = (providerId) => { + return new Promise((resolve) => { + loadExternalScript('https://js.tncid.app/remote.js?ns=' + FALLBACK_TNC_INSTANCE + '&providerId=' + providerId, 'tncid', resolve); + }) +} + const tncCallback = function (providerId, cb) { let tncNS = '__tnc'; + let promiseArray = []; if (!window[tncNS]) { tncNS = FALLBACK_TNC_INSTANCE; - loadRemoteTNCScript(providerId); + promiseArray.push(loadRemoteScript(providerId)); } - return waitTNCScript(tncNS).then(cb).catch(() => cb()); + return Promise.all(promiseArray).then(()=>waitTNCScript(tncNS)).then(cb).catch(() => cb()); } export const tncidSubModule = { diff --git a/src/adloader.js b/src/adloader.js index db128c6d7ba..5975bdc834a 100644 --- a/src/adloader.js +++ b/src/adloader.js @@ -10,7 +10,8 @@ const _approvedLoadExternalJSList = [ 'adagio', 'browsi', 'brandmetrics', - 'justtag' + 'justtag', + 'tncid' ] /** diff --git a/test/spec/modules/tncIdSystem_spec.js b/test/spec/modules/tncIdSystem_spec.js index 2a4697d98fc..92f89e91433 100644 --- a/test/spec/modules/tncIdSystem_spec.js +++ b/test/spec/modules/tncIdSystem_spec.js @@ -101,8 +101,8 @@ describe('TNCID tests', function () { return callback(completeCallback).then(() => { expect(completeCallback.calledOnceWithExactly('TNCID_TEST_ID_2')).to.be.true; - expect(window.__tncPbjs.providerId).to.be.eq('TEST_PROVIDER_ID_2'); }) }); + }); }); From 58d7b23ec2dae21670f9aa9890077ff01597e6cd Mon Sep 17 00:00:00 2001 From: "AzureAD\\AnnaVane" Date: Tue, 7 Jun 2022 18:18:25 +0200 Subject: [PATCH 18/22] -resolved lint errors --- modules/tncIdSystem.js | 4 ++-- test/spec/modules/tncIdSystem_spec.js | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/modules/tncIdSystem.js b/modules/tncIdSystem.js index 54b8a5d93fb..2c5b1af9f2a 100644 --- a/modules/tncIdSystem.js +++ b/modules/tncIdSystem.js @@ -21,7 +21,7 @@ const waitTNCScript = (tncNS) => { const loadRemoteScript = (providerId) => { return new Promise((resolve) => { - loadExternalScript('https://js.tncid.app/remote.js?ns=' + FALLBACK_TNC_INSTANCE + '&providerId=' + providerId, 'tncid', resolve); + loadExternalScript('https://js.tncid.app/remote.js?ns=' + FALLBACK_TNC_INSTANCE + '&providerId=' + providerId, 'tncid', resolve); }) } @@ -33,7 +33,7 @@ const tncCallback = function (providerId, cb) { promiseArray.push(loadRemoteScript(providerId)); } - return Promise.all(promiseArray).then(()=>waitTNCScript(tncNS)).then(cb).catch(() => cb()); + return Promise.all(promiseArray).then(() => waitTNCScript(tncNS)).then(cb).catch(() => cb()); } export const tncidSubModule = { diff --git a/test/spec/modules/tncIdSystem_spec.js b/test/spec/modules/tncIdSystem_spec.js index 92f89e91433..222ca6a3fd5 100644 --- a/test/spec/modules/tncIdSystem_spec.js +++ b/test/spec/modules/tncIdSystem_spec.js @@ -103,6 +103,5 @@ describe('TNCID tests', function () { expect(completeCallback.calledOnceWithExactly('TNCID_TEST_ID_2')).to.be.true; }) }); - }); }); From 95c1c5cc96c9b67b914996741c59ea5c443dc77a Mon Sep 17 00:00:00 2001 From: "AzureAD\\AnnaVane" Date: Thu, 9 Jun 2022 09:29:25 +0200 Subject: [PATCH 19/22] - module name refactoring --- modules/tncIdSystem.js | 2 +- src/adloader.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/tncIdSystem.js b/modules/tncIdSystem.js index 2c5b1af9f2a..9d0ab23652f 100644 --- a/modules/tncIdSystem.js +++ b/modules/tncIdSystem.js @@ -21,7 +21,7 @@ const waitTNCScript = (tncNS) => { const loadRemoteScript = (providerId) => { return new Promise((resolve) => { - loadExternalScript('https://js.tncid.app/remote.js?ns=' + FALLBACK_TNC_INSTANCE + '&providerId=' + providerId, 'tncid', resolve); + loadExternalScript('https://js.tncid.app/remote.js?ns=' + FALLBACK_TNC_INSTANCE + '&providerId=' + providerId, MODULE_NAME, resolve); }) } diff --git a/src/adloader.js b/src/adloader.js index eb2cbc7bd3f..d156bcaf9be 100644 --- a/src/adloader.js +++ b/src/adloader.js @@ -11,7 +11,7 @@ const _approvedLoadExternalJSList = [ 'browsi', 'brandmetrics', 'justtag', - 'tncid', + 'tncId', 'akamaidap', 'ftrackId', 'inskin', From 038ccdb6625c93db0f4e9788ac1a4a32e20056a1 Mon Sep 17 00:00:00 2001 From: "AzureAD\\AnnaVane" Date: Thu, 9 Jun 2022 11:17:58 +0200 Subject: [PATCH 20/22] - input parameter added to disable load of fallback script --- modules/tncIdSystem.js | 9 +++++++-- modules/tncIdSystem.md | 1 + test/spec/modules/tncIdSystem_spec.js | 20 ++++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/modules/tncIdSystem.js b/modules/tncIdSystem.js index 9d0ab23652f..b0e113c41c8 100644 --- a/modules/tncIdSystem.js +++ b/modules/tncIdSystem.js @@ -3,9 +3,12 @@ import { logInfo } from '../src/utils.js'; import { loadExternalScript } from '../src/adloader.js'; const MODULE_NAME = 'tncId'; + const FALLBACK_TNC_PROVIDERID = 'c8549079-f149-4529-a34b-3fa91ef257d1'; const FALLBACK_TNC_INSTANCE = '__tncPbjs'; +let disableFallbackScript = false; + const waitTNCScript = (tncNS) => { return new Promise((resolve, reject) => { var tnc = window[tncNS]; @@ -28,12 +31,12 @@ const loadRemoteScript = (providerId) => { const tncCallback = function (providerId, cb) { let tncNS = '__tnc'; let promiseArray = []; - if (!window[tncNS]) { + if (!window[tncNS] && !disableFallbackScript) { tncNS = FALLBACK_TNC_INSTANCE; promiseArray.push(loadRemoteScript(providerId)); } - return Promise.all(promiseArray).then(() => waitTNCScript(tncNS)).then(cb).catch(() => cb()); + return Promise.all(promiseArray).then(() => waitTNCScript(tncNS)).then(cb).catch(() => cb(null)); } export const tncidSubModule = { @@ -48,7 +51,9 @@ export const tncidSubModule = { const gdpr = (consentData && typeof consentData.gdprApplies === 'boolean' && consentData.gdprApplies) ? 1 : 0; const consentString = gdpr ? consentData.consentString : ''; let providerId = FALLBACK_TNC_PROVIDERID; + if (config && config.params && config.params.providerId)providerId = config.params.providerId; + disableFallbackScript = (config && config.params && config.params.disableFallbackScript); if (gdpr && !consentString) { logInfo('Consent string is required for TNCID module'); diff --git a/modules/tncIdSystem.md b/modules/tncIdSystem.md index dec5e53ddad..0e1a43ee649 100644 --- a/modules/tncIdSystem.md +++ b/modules/tncIdSystem.md @@ -31,3 +31,4 @@ pbjs.setConfig({ | --- | --- | --- | --- | | name | Required | String | ID value for the TNCID module: `"tncId"` | | params.providerId | Optional | String | Provide TNC providerId if possible | +| params.disableFallbackScript | Optional | Boolean | Never load fallback script | diff --git a/test/spec/modules/tncIdSystem_spec.js b/test/spec/modules/tncIdSystem_spec.js index 222ca6a3fd5..9feae927e25 100644 --- a/test/spec/modules/tncIdSystem_spec.js +++ b/test/spec/modules/tncIdSystem_spec.js @@ -103,5 +103,25 @@ describe('TNCID tests', function () { expect(completeCallback.calledOnceWithExactly('TNCID_TEST_ID_2')).to.be.true; }) }); + + it('If there is no TNC script on page and disableFallbackScript is set to "true", no TNCID is returned', function () { + Object.defineProperty(window, '__tncPbjs', { + value: { + ready: (readyFunc) => { readyFunc() }, + on: (name, cb) => { cb() }, + providerId: 'TEST_PROVIDER_ID_1', + options: {}, + tncid: 'TNCID_TEST_ID_2' + }, + configurable: true, + writable: true + }); + const completeCallback = sinon.spy(); + const {callback} = tncidSubModule.getId({params: {disableFallbackScript: true}}, consentData); + + return callback(completeCallback).then(() => { + expect(completeCallback.calledOnceWithExactly(null)).to.be.true; + }) + }); }); }); From 05409945d766b28920c735d758c0f4c5848d35cb Mon Sep 17 00:00:00 2001 From: "AzureAD\\AnnaVane" Date: Wed, 15 Jun 2022 13:24:58 +0200 Subject: [PATCH 21/22] - TNC fallback script is now input param --- modules/tncIdSystem.js | 28 ++++++++------------ modules/tncIdSystem.md | 5 ++-- test/spec/modules/tncIdSystem_spec.js | 38 +++++++-------------------- 3 files changed, 23 insertions(+), 48 deletions(-) diff --git a/modules/tncIdSystem.js b/modules/tncIdSystem.js index b0e113c41c8..24e3c79d4df 100644 --- a/modules/tncIdSystem.js +++ b/modules/tncIdSystem.js @@ -3,11 +3,7 @@ import { logInfo } from '../src/utils.js'; import { loadExternalScript } from '../src/adloader.js'; const MODULE_NAME = 'tncId'; - -const FALLBACK_TNC_PROVIDERID = 'c8549079-f149-4529-a34b-3fa91ef257d1'; -const FALLBACK_TNC_INSTANCE = '__tncPbjs'; - -let disableFallbackScript = false; +let url = null; const waitTNCScript = (tncNS) => { return new Promise((resolve, reject) => { @@ -22,21 +18,21 @@ const waitTNCScript = (tncNS) => { }); } -const loadRemoteScript = (providerId) => { +const loadRemoteScript = () => { return new Promise((resolve) => { - loadExternalScript('https://js.tncid.app/remote.js?ns=' + FALLBACK_TNC_INSTANCE + '&providerId=' + providerId, MODULE_NAME, resolve); + loadExternalScript(url, MODULE_NAME, resolve); }) } -const tncCallback = function (providerId, cb) { +const tncCallback = function (cb) { let tncNS = '__tnc'; let promiseArray = []; - if (!window[tncNS] && !disableFallbackScript) { - tncNS = FALLBACK_TNC_INSTANCE; - promiseArray.push(loadRemoteScript(providerId)); + if (!window[tncNS]) { + tncNS = '__tncPbjs'; + promiseArray.push(loadRemoteScript()); } - return Promise.all(promiseArray).then(() => waitTNCScript(tncNS)).then(cb).catch(() => cb(null)); + return Promise.all(promiseArray).then(() => waitTNCScript(tncNS)).then(cb).catch(() => cb()); } export const tncidSubModule = { @@ -50,18 +46,16 @@ export const tncidSubModule = { getId(config, consentData) { const gdpr = (consentData && typeof consentData.gdprApplies === 'boolean' && consentData.gdprApplies) ? 1 : 0; const consentString = gdpr ? consentData.consentString : ''; - let providerId = FALLBACK_TNC_PROVIDERID; - - if (config && config.params && config.params.providerId)providerId = config.params.providerId; - disableFallbackScript = (config && config.params && config.params.disableFallbackScript); if (gdpr && !consentString) { logInfo('Consent string is required for TNCID module'); return; } + if (config.params && config.params.url) { url = config.params.url; } + return { - callback: function (cb) { return tncCallback(providerId, cb); } + callback: function (cb) { return tncCallback(cb); } } } } diff --git a/modules/tncIdSystem.md b/modules/tncIdSystem.md index 0e1a43ee649..f0f98e9098f 100644 --- a/modules/tncIdSystem.md +++ b/modules/tncIdSystem.md @@ -18,7 +18,7 @@ pbjs.setConfig({ userIds: [{ name: 'tncId', params: { - providerId: "c8549079-f149-4529-a34b-3fa91ef257d1" // Optional + url: 'https://js.tncid.app/remote.min.js' //Optional } }], syncDelay: 5000 @@ -30,5 +30,4 @@ pbjs.setConfig({ | Param Name | Required | Type | Description | | --- | --- | --- | --- | | name | Required | String | ID value for the TNCID module: `"tncId"` | -| params.providerId | Optional | String | Provide TNC providerId if possible | -| params.disableFallbackScript | Optional | Boolean | Never load fallback script | +| params.url | Optional | String | Provide TNC fallback script URL, this script is loaded if there is no TNC script on page | diff --git a/test/spec/modules/tncIdSystem_spec.js b/test/spec/modules/tncIdSystem_spec.js index 9feae927e25..57c5fa63645 100644 --- a/test/spec/modules/tncIdSystem_spec.js +++ b/test/spec/modules/tncIdSystem_spec.js @@ -33,13 +33,13 @@ describe('TNCID tests', function () { }); it('Should NOT give TNCID if GDPR applies but consent string is missing', function () { - const res = tncidSubModule.getId(null, { gdprApplies: true }); + const res = tncidSubModule.getId({}, { gdprApplies: true }); expect(res).to.be.undefined; }); it('GDPR is OK and page has no TNC script on page, script goes in error, no TNCID is returned', function () { const completeCallback = sinon.spy(); - const {callback} = tncidSubModule.getId(null, consentData); + const {callback} = tncidSubModule.getId({}, consentData); return callback(completeCallback).then(() => { expect(completeCallback.calledOnce).to.be.true; @@ -58,7 +58,7 @@ describe('TNCID tests', function () { }); const completeCallback = sinon.spy(); - const {callback} = tncidSubModule.getId(null, { gdprApplies: false }); + const {callback} = tncidSubModule.getId({}, { gdprApplies: false }); return callback(completeCallback).then(() => { expect(completeCallback.calledOnceWithExactly('TNCID_TEST_ID_1')).to.be.true; @@ -76,10 +76,10 @@ describe('TNCID tests', function () { }); const completeCallback = sinon.spy(); - const {callback} = tncidSubModule.getId(null, { gdprApplies: false }); + const {callback} = tncidSubModule.getId({}, { gdprApplies: false }); return callback(completeCallback).then(() => { - expect(completeCallback.calledOnce).to.be.true; + expect(completeCallback.calledOnceWithExactly(undefined)).to.be.true; }) }); @@ -87,41 +87,23 @@ describe('TNCID tests', function () { Object.defineProperty(window, '__tncPbjs', { value: { ready: (readyFunc) => { readyFunc() }, - on: (name, cb) => { cb() }, + on: (name, cb) => { + window.__tncPbjs.tncid = 'TNCID_TEST_ID_2'; + cb(); + }, providerId: 'TEST_PROVIDER_ID_1', options: {}, - tncid: 'TNCID_TEST_ID_2' }, configurable: true, writable: true }); const completeCallback = sinon.spy(); - const {callback} = tncidSubModule.getId({params: {providerId: 'TEST_PROVIDER_ID_2'}}, consentData); + const {callback} = tncidSubModule.getId({params: {url: 'TEST_URL'}}, consentData); return callback(completeCallback).then(() => { expect(completeCallback.calledOnceWithExactly('TNCID_TEST_ID_2')).to.be.true; }) }); - - it('If there is no TNC script on page and disableFallbackScript is set to "true", no TNCID is returned', function () { - Object.defineProperty(window, '__tncPbjs', { - value: { - ready: (readyFunc) => { readyFunc() }, - on: (name, cb) => { cb() }, - providerId: 'TEST_PROVIDER_ID_1', - options: {}, - tncid: 'TNCID_TEST_ID_2' - }, - configurable: true, - writable: true - }); - const completeCallback = sinon.spy(); - const {callback} = tncidSubModule.getId({params: {disableFallbackScript: true}}, consentData); - - return callback(completeCallback).then(() => { - expect(completeCallback.calledOnceWithExactly(null)).to.be.true; - }) - }); }); }); From 6f0e847911df574ff6dc402c8aa4143e94c9f0df Mon Sep 17 00:00:00 2001 From: "AzureAD\\AnnaVane" Date: Wed, 15 Jun 2022 16:37:59 +0200 Subject: [PATCH 22/22] - Added missing tests --- test/spec/modules/eids_spec.js | 14 ++++++++++++++ test/spec/modules/userId_spec.js | 9 ++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/test/spec/modules/eids_spec.js b/test/spec/modules/eids_spec.js index ca971c37832..614e32f1296 100644 --- a/test/spec/modules/eids_spec.js +++ b/test/spec/modules/eids_spec.js @@ -330,6 +330,20 @@ describe('eids array generation for known sub-modules', function() { }] }); }); + it('tncid', function() { + const userId = { + tncid: 'TEST_TNCID' + }; + const newEids = createEidsArray(userId); + expect(newEids.length).to.equal(1); + expect(newEids[0]).to.deep.equal({ + source: 'thenewco.it', + uids: [{ + id: 'TEST_TNCID', + atype: 3 + }] + }); + }); it('pubProvidedId', function() { const userId = { pubProvidedId: [{ diff --git a/test/spec/modules/userId_spec.js b/test/spec/modules/userId_spec.js index 035c86a3cc1..49c07bb1334 100644 --- a/test/spec/modules/userId_spec.js +++ b/test/spec/modules/userId_spec.js @@ -38,6 +38,7 @@ import {pubProvidedIdSubmodule} from 'modules/pubProvidedIdSystem.js'; import {criteoIdSubmodule} from 'modules/criteoIdSystem.js'; import {mwOpenLinkIdSubModule} from 'modules/mwOpenLinkIdSystem.js'; import {tapadIdSubmodule} from 'modules/tapadIdSystem.js'; +import {tncidSubModule} from 'modules/tncIdSystem.js'; import {getPrebidInternal} from 'src/utils.js'; import {uid2IdSubmodule} from 'modules/uid2IdSystem.js'; import {admixerIdSubmodule} from 'modules/admixerIdSystem.js'; @@ -784,9 +785,9 @@ describe('User ID', function () { expect(utils.logInfo.args[0][0]).to.exist.and.to.contain('User ID - usersync config updated for 1 submodules'); }); - it('config with 21 configurations should result in 21 submodules add', function () { + it('config with 22 configurations should result in 22 submodules add', function () { init(config); - setSubmoduleRegistry([sharedIdSystemSubmodule, unifiedIdSubmodule, id5IdSubmodule, identityLinkSubmodule, liveIntentIdSubmodule, britepoolIdSubmodule, netIdSubmodule, intentIqIdSubmodule, zeotapIdPlusSubmodule, hadronIdSubmodule, pubProvidedIdSubmodule, criteoIdSubmodule, mwOpenLinkIdSubModule, tapadIdSubmodule, uid2IdSubmodule, admixerIdSubmodule, deepintentDpesSubmodule, dmdIdSubmodule, amxIdSubmodule, kinessoIdSubmodule, adqueryIdSubmodule]); + setSubmoduleRegistry([sharedIdSystemSubmodule, unifiedIdSubmodule, id5IdSubmodule, identityLinkSubmodule, liveIntentIdSubmodule, britepoolIdSubmodule, netIdSubmodule, intentIqIdSubmodule, zeotapIdPlusSubmodule, hadronIdSubmodule, pubProvidedIdSubmodule, criteoIdSubmodule, mwOpenLinkIdSubModule, tapadIdSubmodule, uid2IdSubmodule, admixerIdSubmodule, deepintentDpesSubmodule, dmdIdSubmodule, amxIdSubmodule, kinessoIdSubmodule, adqueryIdSubmodule, tncidSubModule]); config.setConfig({ userSync: { syncDelay: 0, @@ -847,10 +848,12 @@ describe('User ID', function () { }, { name: 'qid', storage: {name: 'qid', type: 'html5'} + }, { + name: 'tncId' }] } }); - expect(utils.logInfo.args[0][0]).to.exist.and.to.contain('User ID - usersync config updated for 21 submodules'); + expect(utils.logInfo.args[0][0]).to.exist.and.to.contain('User ID - usersync config updated for 22 submodules'); }); it('config syncDelay updates module correctly', function () {