Skip to content

Commit

Permalink
AdtelligentIdSystem : add new ID submodule (#6948)
Browse files Browse the repository at this point in the history
* Adtelligent User Id module

* Adtelligent User Id module

* fix lint

* add unit tests to user id

* Add markdown file
  • Loading branch information
GeneGenie authored Jul 13, 2021
1 parent f81220c commit d517ed8
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 0 deletions.
7 changes: 7 additions & 0 deletions modules/adtelligentBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []

Expand Down
91 changes: 91 additions & 0 deletions modules/adtelligentIdSystem.js
Original file line number Diff line number Diff line change
@@ -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);
33 changes: 33 additions & 0 deletions modules/adtelligentIdSystem.md
Original file line number Diff line number Diff line change
@@ -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 %}
5 changes: 5 additions & 0 deletions modules/userId/eids.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
30 changes: 30 additions & 0 deletions test/spec/modules/adtelligentIdSystem_spec.js
Original file line number Diff line number Diff line change
@@ -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 });
})
})

0 comments on commit d517ed8

Please sign in to comment.