-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy path33acrossIdSystem.js
141 lines (118 loc) · 3.44 KB
/
33acrossIdSystem.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/**
* This module adds 33acrossId to the User ID module
* The {@link module:modules/userId} module is required
* @module modules/33acrossIdSystem
* @requires module:modules/userId
*/
import { logMessage, logError } from '../src/utils.js';
import { ajaxBuilder } from '../src/ajax.js';
import { submodule } from '../src/hook.js';
import { uspDataHandler, coppaDataHandler, gppDataHandler } from '../src/adapterManager.js';
const MODULE_NAME = '33acrossId';
const API_URL = 'https://lexicon.33across.com/v1/envelope';
const AJAX_TIMEOUT = 10000;
const CALLER_NAME = 'pbjs';
function getEnvelope(response) {
if (!response.succeeded) {
if (response.error == 'Cookied User') {
logMessage(`${MODULE_NAME}: Unsuccessful response`.concat(' ', response.error));
} else {
logError(`${MODULE_NAME}: Unsuccessful response`.concat(' ', response.error));
}
return;
}
if (!response.data.envelope) {
logMessage(`${MODULE_NAME}: No envelope was received`);
return;
}
return response.data.envelope;
}
function calculateQueryStringParams(pid, gdprConsentData) {
const uspString = uspDataHandler.getConsentData();
const gdprApplies = Boolean(gdprConsentData?.gdprApplies);
const coppaValue = coppaDataHandler.getCoppa();
const gppConsent = gppDataHandler.getConsentData();
const params = {
pid,
gdpr: Number(gdprApplies),
src: CALLER_NAME,
ver: '$prebid.version$',
coppa: Number(coppaValue)
};
if (uspString) {
params.us_privacy = uspString;
}
if (gppConsent) {
const { gppString = '', applicableSections = [] } = gppConsent;
params.gpp = gppString;
params.gpp_sid = encodeURIComponent(applicableSections.join(','))
}
if (gdprConsentData?.consentString) {
params.gdpr_consent = gdprConsentData.consentString;
}
return params;
}
/** @type {Submodule} */
export const thirthyThreeAcrossIdSubmodule = {
/**
* used to link submodule with config
* @type {string}
*/
name: MODULE_NAME,
gvlid: 58,
/**
* decode the stored id value for passing to bid requests
* @function
* @param {string} id
* @returns {{'33acrossId':{ envelope: string}}}
*/
decode(id) {
return {
[MODULE_NAME]: {
envelope: id
}
};
},
/**
* performs action to obtain id and return a value in the callback's response argument
* @function
* @param {SubmoduleConfig} [config]
* @returns {IdResponse|undefined}
*/
getId({ params = { } }, gdprConsentData) {
if (typeof params.pid !== 'string') {
logError(`${MODULE_NAME}: Submodule requires a partner ID to be defined`);
return;
}
const { pid, apiUrl = API_URL } = params;
return {
callback(cb) {
ajaxBuilder(AJAX_TIMEOUT)(apiUrl, {
success(response) {
let envelope;
try {
envelope = getEnvelope(JSON.parse(response))
} catch (err) {
logError(`${MODULE_NAME}: ID reading error:`, err);
}
cb(envelope);
},
error(err) {
logError(`${MODULE_NAME}: ID error response`, err);
cb();
}
}, calculateQueryStringParams(pid, gdprConsentData), { method: 'GET', withCredentials: true });
}
};
},
eids: {
'33acrossId': {
source: '33across.com',
atype: 1,
getValue: function(data) {
return data.envelope;
}
},
}
};
submodule('userId', thirthyThreeAcrossIdSubmodule);