forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tnc id module: initial release (prebid#8435)
* - TNCID UserID Module * revert * - TNCID UserID Module * - TNCID UserID Module * Converted loadTNCScript to Promise * Added CacheID * - TNCID UserID module * - Documentation updated * - File naming fix * - type fix * -no change * - space removed * new line removed * - lint fix * - eids fix * - .submodules.json: module name moved in alphabetical order - modules/tncIdSystem.md: spacing fix - added eids.md, user id spec and eids spec * - tnc script loaded by loadExternalScript util function * -resolved lint errors * - module name refactoring * - input parameter added to disable load of fallback script * - TNC fallback script is now input param * - Added missing tests Co-authored-by: AzureAD\AnnaVane <[email protected]> Co-authored-by: micheletnc <[email protected]>
- Loading branch information
Showing
10 changed files
with
258 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { submodule } from '../src/hook.js'; | ||
import { logInfo } from '../src/utils.js'; | ||
import { loadExternalScript } from '../src/adloader.js'; | ||
|
||
const MODULE_NAME = 'tncId'; | ||
let url = null; | ||
|
||
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)); | ||
}); | ||
}); | ||
} | ||
|
||
const loadRemoteScript = () => { | ||
return new Promise((resolve) => { | ||
loadExternalScript(url, MODULE_NAME, resolve); | ||
}) | ||
} | ||
|
||
const tncCallback = function (cb) { | ||
let tncNS = '__tnc'; | ||
let promiseArray = []; | ||
if (!window[tncNS]) { | ||
tncNS = '__tncPbjs'; | ||
promiseArray.push(loadRemoteScript()); | ||
} | ||
|
||
return Promise.all(promiseArray).then(() => waitTNCScript(tncNS)).then(cb).catch(() => 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; | ||
} | ||
|
||
if (config.params && config.params.url) { url = config.params.url; } | ||
|
||
return { | ||
callback: function (cb) { return tncCallback(cb); } | ||
} | ||
} | ||
} | ||
|
||
submodule('userId', tncidSubModule) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# TNCID UserID Module | ||
|
||
### Prebid Configuration | ||
|
||
First, make sure to add the TNCID submodule to your Prebid.js package with: | ||
|
||
``` | ||
gulp build --modules=tncIdSystem,userId | ||
``` | ||
|
||
### TNCIDIdSystem module Configuration | ||
|
||
You can configure this submodule in your `userSync.userIds[]` configuration: | ||
|
||
```javascript | ||
pbjs.setConfig({ | ||
userSync: { | ||
userIds: [{ | ||
name: 'tncId', | ||
params: { | ||
url: 'https://js.tncid.app/remote.min.js' //Optional | ||
} | ||
}], | ||
syncDelay: 5000 | ||
} | ||
}); | ||
``` | ||
#### Configuration Params | ||
|
||
| Param Name | Required | Type | Description | | ||
| --- | --- | --- | --- | | ||
| name | Required | String | ID value for the TNCID module: `"tncId"` | | ||
| params.url | Optional | String | Provide TNC fallback script URL, this script is loaded if there is no TNC script on page | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import { tncidSubModule } from 'modules/tncIdSystem'; | ||
|
||
const consentData = { | ||
gdprApplies: true, | ||
consentString: 'GDPR_CONSENT_STRING' | ||
}; | ||
|
||
describe('TNCID tests', function () { | ||
describe('name', () => { | ||
it('should expose the name of the submodule', () => { | ||
expect(tncidSubModule.name).to.equal('tncId'); | ||
}); | ||
}); | ||
|
||
describe('gvlid', () => { | ||
it('should expose the vendor id', () => { | ||
expect(tncidSubModule.gvlid).to.equal(750); | ||
}); | ||
}); | ||
|
||
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({}, { 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({}, 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', | ||
providerId: 'TEST_PROVIDER_ID_1', | ||
}, | ||
configurable: true | ||
}); | ||
|
||
const completeCallback = sinon.spy(); | ||
const {callback} = tncidSubModule.getId({}, { 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() }, | ||
providerId: 'TEST_PROVIDER_ID_1', | ||
}, | ||
configurable: true | ||
}); | ||
|
||
const completeCallback = sinon.spy(); | ||
const {callback} = tncidSubModule.getId({}, { gdprApplies: false }); | ||
|
||
return callback(completeCallback).then(() => { | ||
expect(completeCallback.calledOnceWithExactly(undefined)).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(); | ||
}, | ||
providerId: 'TEST_PROVIDER_ID_1', | ||
options: {}, | ||
}, | ||
configurable: true, | ||
writable: true | ||
}); | ||
|
||
const completeCallback = sinon.spy(); | ||
const {callback} = tncidSubModule.getId({params: {url: 'TEST_URL'}}, consentData); | ||
|
||
return callback(completeCallback).then(() => { | ||
expect(completeCallback.calledOnceWithExactly('TNCID_TEST_ID_2')).to.be.true; | ||
}) | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters