Skip to content

Commit

Permalink
tnc Id System : fixes for docs and performance improvements (#12315)
Browse files Browse the repository at this point in the history
* 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.

* - Tests fixed
  • Loading branch information
annavane authored Oct 20, 2024
1 parent c84b201 commit f1b4705
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 24 deletions.
8 changes: 3 additions & 5 deletions modules/tncIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ const waitTNCScript = (tncNS) => {
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));
tnc.ready(async () => {
let tncid = await tnc.getTNCID('prebid');
resolve(tncid);
});
});
}
Expand All @@ -32,7 +31,6 @@ const tncCallback = function (cb) {
tncNS = '__tncPbjs';
promiseArray.push(loadRemoteScript());
}

return Promise.all(promiseArray).then(() => waitTNCScript(tncNS)).then(cb).catch(() => cb());
}

Expand Down
19 changes: 9 additions & 10 deletions modules/userId/userId.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
});
```
14 changes: 5 additions & 9 deletions test/spec/modules/tncIdSystem_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
Expand All @@ -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
Expand All @@ -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: {},
},
Expand Down

0 comments on commit f1b4705

Please sign in to comment.