diff --git a/modules/adtelligentBidAdapter.js b/modules/adtelligentBidAdapter.js index d21931a6dcb..e1c6dc1ca35 100644 --- a/modules/adtelligentBidAdapter.js +++ b/modules/adtelligentBidAdapter.js @@ -179,6 +179,13 @@ function bidToTag(bidRequests, adapterRequest) { if (utils.deepAccess(bidRequests[0], 'userId')) { tag.UserIds = utils.deepAccess(bidRequests[0], 'userId'); } + if (utils.deepAccess(bidRequests[0], 'userIdAsEids')) { + tag.UserEids = utils.deepAccess(bidRequests[0], 'userIdAsEids'); + } + if (window.adtDmp && window.adtDmp.ready) { + tag.DMPId = window.adtDmp.getUID(); + } + // end publisher env const bids = [] diff --git a/modules/adtelligentIdSystem.js b/modules/adtelligentIdSystem.js new file mode 100644 index 00000000000..fb3b5f6fe2a --- /dev/null +++ b/modules/adtelligentIdSystem.js @@ -0,0 +1,91 @@ +/** + * This module adds Adtelligent DMP Tokens to the User ID module + * The {@link module:modules/userId} module is required + * @module modules/adtelligentIdSystem + * @requires module:modules/userId + */ + +import * as ajax from '../src/ajax.js'; +import { submodule } from '../src/hook.js'; + +const gvlid = 410; +const moduleName = 'adtelligent'; +const syncUrl = 'https://idrs.adtelligent.com/get'; + +function buildUrl(opts) { + const queryPairs = []; + for (let key in opts) { + queryPairs.push(`${key}=${encodeURIComponent(opts[key])}`); + } + return `${syncUrl}?${queryPairs.join('&')}`; +} + +function requestRemoteIdAsync(url, cb) { + ajax.ajaxBuilder()( + url, + { + success: response => { + const jsonResponse = JSON.parse(response); + const { u: dmpId } = jsonResponse; + cb(dmpId); + }, + error: () => { + cb(); + } + }, + null, + { + method: 'GET', + contentType: 'application/json', + withCredentials: true + } + ); +} + +/** @type {Submodule} */ +export const adtelligentIdModule = { + /** + * used to link submodule with config + * @type {string} + */ + name: moduleName, + gvlid: gvlid, + /** + * decode the stored id value for passing to bid requests + * @function + * @returns {{adtelligentId: string}} + */ + decode(uid) { + return { adtelligentId: uid }; + }, + /** + * get the Adtelligent Id from local storages and initiate a new user sync + * @function + * @param {SubmoduleConfig} [config] + * @param {ConsentData} [consentData] + * @returns {IdResponse} + */ + getId(config, consentData) { + const gdpr = consentData && consentData.gdprApplies ? 1 : 0; + const gdprConsent = gdpr ? consentData.consentString : ''; + const url = buildUrl({ + gdpr, + gdprConsent + }); + + if (window.adtDmp && window.adtDmp.ready) { + return { id: window.adtDmp.getUID() } + } + + return { + callback: (cb) => { + requestRemoteIdAsync(url, (id) => { + cb(id); + }); + } + + } + } +}; + +submodule('userId', adtelligentIdModule); diff --git a/modules/adtelligentIdSystem.md b/modules/adtelligentIdSystem.md new file mode 100644 index 00000000000..291a5e70bde --- /dev/null +++ b/modules/adtelligentIdSystem.md @@ -0,0 +1,33 @@ +### Adtelligent Id Sytem + +The [Adtelligent](https://adtelligent.com) ID system is a uniq per-session user identifier for providing high quality DMP data for advertisers + +#### Adtelligent Id Sytem Configuration Example + +{% highlight javascript %} + pbjs.setConfig({ + userSync: { + userIds: [{ + name: 'adtelligent' + }] + } + }); +{% endhighlight %} + +Example with a short storage for ~10 minutes and refresh in 5 minutes: + +{% highlight javascript %} + pbjs.setConfig({ + userSync: { + userIds: [{ + name: 'adtelligent', + storage: { + type: "html5", + name: "adt_id", + expires:0.003, + refreshInSeconds: 60 * 5 + } + }] + } + }); +{% endhighlight %} diff --git a/modules/userId/eids.js b/modules/userId/eids.js index 32f7c163f3c..e11eb3edb68 100644 --- a/modules/userId/eids.js +++ b/modules/userId/eids.js @@ -213,6 +213,11 @@ const USER_IDS_CONFIG = { source: 'admixer.net', atype: 3 }, + // Adtelligent Id + 'adtelligentId': { + source: 'adtelligent.com', + atype: 3 + }, amxId: { source: 'amxrtb.com', atype: 1, diff --git a/test/spec/modules/adtelligentIdSystem_spec.js b/test/spec/modules/adtelligentIdSystem_spec.js new file mode 100644 index 00000000000..f3c7262c67a --- /dev/null +++ b/test/spec/modules/adtelligentIdSystem_spec.js @@ -0,0 +1,30 @@ +import { adtelligentIdModule } from 'modules/adtelligentIdSystem' +import * as ajaxLib from 'src/ajax.js'; + +const adtUserIdRemoteResponse = { u: 'test1' }; +const adtUserIdLocalResponse = 'test2'; + +describe('AdtelligentId module', function () { + it('gets remote id', function () { + const ajaxBuilderStub = sinon.stub(ajaxLib, 'ajaxBuilder').callsFake(() => { + return (url, cbObj) => { + cbObj.success(JSON.stringify(adtUserIdRemoteResponse)) + } + }); + const moduleIdCallbackResponse = adtelligentIdModule.getId(); + moduleIdCallbackResponse.callback((id) => { + expect(id).to.equal(adtUserIdRemoteResponse.u) + }) + ajaxBuilderStub.restore(); + }) + it('gets id from page context', function () { + window.adtDmp = { + ready: true, + getUID() { + return adtUserIdLocalResponse; + } + } + const moduleIdResponse = adtelligentIdModule.getId(); + assert.deepEqual(moduleIdResponse, { id: adtUserIdLocalResponse }); + }) +})