From c926c97e6c43d2d7c8585e262014537016977e25 Mon Sep 17 00:00:00 2001 From: annavane Date: Thu, 10 Oct 2024 16:14:47 +0200 Subject: [PATCH 1/2] Bug Fixes: modules/tncIdSystem.js - Optimized User ID Recovery: Replaced the existing user ID recovery function with a faster and more efficient method, improving performance. modules/userId/userId.md - Documentation Correction: Resolved inconsistencies in the documentation, ensuring accurate information for module configuration and usage. --- modules/tncIdSystem.js | 6 +++--- modules/userId/userId.md | 19 +++++++++---------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/modules/tncIdSystem.js b/modules/tncIdSystem.js index 59254a9430f..91187454739 100644 --- a/modules/tncIdSystem.js +++ b/modules/tncIdSystem.js @@ -10,10 +10,10 @@ const waitTNCScript = (tncNS) => { var tnc = window[tncNS]; if (!tnc) reject(new Error('No TNC Object')); if (tnc.tncid) resolve(tnc.tncid); - tnc.ready(() => { + tnc.ready(async () => { tnc = window[tncNS]; - if (tnc.tncid) resolve(tnc.tncid); - else tnc.on('data-sent', () => resolve(tnc.tncid)); + let tncid = await tnc.getTNCID('prebid'); + resolve(tncid); }); }); } diff --git a/modules/userId/userId.md b/modules/userId/userId.md index 9fb53c2c7b3..9aea3e8d533 100644 --- a/modules/userId/userId.md +++ b/modules/userId/userId.md @@ -366,16 +366,15 @@ 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 -} + userSync: { + userIds: [{ + name: 'tncId', + params: { + url: 'https://js.tncid.app/remote.min.js' //Optional + } + }], + syncDelay: 5000 + } }); ``` From 31e02444fcf3ae382f96f8083f409cf94a9b784a Mon Sep 17 00:00:00 2001 From: annavane Date: Fri, 11 Oct 2024 12:36:57 +0200 Subject: [PATCH 2/2] - Tests fixed --- modules/tncIdSystem.js | 2 -- test/spec/modules/tncIdSystem_spec.js | 14 +++++--------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/modules/tncIdSystem.js b/modules/tncIdSystem.js index 91187454739..34b054363f8 100644 --- a/modules/tncIdSystem.js +++ b/modules/tncIdSystem.js @@ -11,7 +11,6 @@ const waitTNCScript = (tncNS) => { if (!tnc) reject(new Error('No TNC Object')); if (tnc.tncid) resolve(tnc.tncid); tnc.ready(async () => { - tnc = window[tncNS]; let tncid = await tnc.getTNCID('prebid'); resolve(tncid); }); @@ -31,7 +30,6 @@ const tncCallback = function (cb) { tncNS = '__tncPbjs'; promiseArray.push(loadRemoteScript()); } - return Promise.all(promiseArray).then(() => waitTNCScript(tncNS)).then(cb).catch(() => cb()); } diff --git a/test/spec/modules/tncIdSystem_spec.js b/test/spec/modules/tncIdSystem_spec.js index 56b97ff0561..4626c940a59 100644 --- a/test/spec/modules/tncIdSystem_spec.js +++ b/test/spec/modules/tncIdSystem_spec.js @@ -53,7 +53,6 @@ describe('TNCID tests', function () { Object.defineProperty(window, '__tnc', { value: { ready: (readyFunc) => { readyFunc() }, - on: (name, cb) => { cb() }, tncid: 'TNCID_TEST_ID_1', providerId: 'TEST_PROVIDER_ID_1', }, @@ -71,8 +70,8 @@ describe('TNCID tests', function () { 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() }, + ready: async (readyFunc) => { await readyFunc() }, + getTNCID: async (name) => { return 'TNCID_TEST_ID_1' }, providerId: 'TEST_PROVIDER_ID_1', }, configurable: true @@ -82,18 +81,15 @@ describe('TNCID tests', function () { const {callback} = tncidSubModule.getId({}, { gdprApplies: false }); return callback(completeCallback).then(() => { - expect(completeCallback.calledOnceWithExactly(undefined)).to.be.true; + expect(completeCallback.calledOnceWithExactly('TNCID_TEST_ID_1')).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) => { - window.__tncPbjs.tncid = 'TNCID_TEST_ID_2'; - cb(); - }, + ready: async (readyFunc) => { await readyFunc() }, + getTNCID: async (name) => { return 'TNCID_TEST_ID_2' }, providerId: 'TEST_PROVIDER_ID_1', options: {}, },