-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AdtelligentIdSystem : add new ID submodule (#6948)
* Adtelligent User Id module * Adtelligent User Id module * fix lint * add unit tests to user id * Add markdown file
- Loading branch information
Showing
5 changed files
with
166 additions
and
0 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,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); |
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 @@ | ||
### 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 %} |
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,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 }); | ||
}) | ||
}) |