forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunifiedIdSystem.js
81 lines (75 loc) · 2.42 KB
/
unifiedIdSystem.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
/**
* This module adds UnifiedId to the User ID module
* The {@link module:modules/userId} module is required
* @module modules/unifiedIdSystem
* @requires module:modules/userId
*/
import { logError } from '../src/utils.js';
import {ajax} from '../src/ajax.js';
import {submodule} from '../src/hook.js'
import {UID1_EIDS} from '../libraries/uid1Eids/uid1Eids.js';
/**
* @typedef {import('../modules/userId/index.js').Submodule} Submodule
* @typedef {import('../modules/userId/index.js').SubmoduleConfig} SubmoduleConfig
* @typedef {import('../modules/userId/index.js').IdResponse} IdResponse
*/
const MODULE_NAME = 'unifiedId';
/** @type {Submodule} */
export const unifiedIdSubmodule = {
/**
* used to link submodule with config
* @type {string}
*/
name: MODULE_NAME,
/**
* required for the gdpr enforcement module
*/
gvlid: 21,
/**
* decode the stored id value for passing to bid requests
* @function
* @param {{TDID:string}} value
* @returns {{tdid:Object}}
*/
decode(value) {
return (value && typeof value['TDID'] === 'string') ? { 'tdid': value['TDID'] } : undefined;
},
/**
* performs action to obtain id and return a value in the callback's response argument
* @function
* @param {SubmoduleConfig} [config]
* @returns {IdResponse|undefined}
*/
getId(config) {
const configParams = (config && config.params) || {};
if (!configParams || (typeof configParams.partner !== 'string' && typeof configParams.url !== 'string')) {
logError('User ID - unifiedId submodule requires either partner or url to be defined');
return;
}
// use protocol relative urls for http or https
const url = configParams.url || `https://match.adsrvr.org/track/rid?ttd_pid=${configParams.partner}&fmt=json`;
const resp = function (callback) {
const callbacks = {
success: response => {
let responseObj;
if (response) {
try {
responseObj = JSON.parse(response);
} catch (error) {
logError(error);
}
}
callback(responseObj);
},
error: error => {
logError(`${MODULE_NAME}: ID fetch encountered an error`, error);
callback();
}
};
ajax(url, callbacks, undefined, {method: 'GET', withCredentials: true});
};
return {callback: resp};
},
eids: {...UID1_EIDS}
};
submodule('userId', unifiedIdSubmodule);