forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadtelligentIdSystem.js
104 lines (94 loc) · 2.4 KB
/
adtelligentIdSystem.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/**
* 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';
/**
* @typedef {import('../modules/userId/index.js').Submodule} Submodule
* @typedef {import('../modules/userId/index.js').SubmoduleConfig} SubmoduleConfig
* @typedef {import('../modules/userId/index.js').ConsentData} ConsentData
* @typedef {import('../modules/userId/index.js').IdResponse} IdResponse
*/
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);
});
}
}
},
eids: {
'adtelligentId': {
source: 'adtelligent.com',
atype: 3
},
}
};
submodule('userId', adtelligentIdModule);