forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadnuntiusRtdProvider.js
100 lines (86 loc) · 2.61 KB
/
adnuntiusRtdProvider.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
import { submodule } from '../src/hook.js'
import { logError, logInfo } from '../src/utils.js'
import { ajax } from '../src/ajax.js';
import { config as sourceConfig } from '../src/config.js';
/**
* @typedef {import('../modules/rtdModule/index.js').RtdSubmodule} RtdSubmodule
*/
const GVLID = 855;
function init(config, userConsent) {
if (!config.params || !config.params.providers) return false
logInfo(userConsent)
return true;
}
// Make sure that ajax has a function as callback
function prepProvider(provider) {
// Map parameter to something that adnuntius endpoint understands.
const mappedParameters = {
siteId: 's',
userId: 'browserId',
browserId: 'browserId',
folderId: 'folderId'
}
const tzo = new Date().getTimezoneOffset();
const URL = ['https://data.adnuntius.com/usr?tzo=' + tzo]
Object.keys(provider).forEach(key => {
URL.push(`${mappedParameters[key]}=${provider[key]}`)
})
return new Promise((resolve, reject) => {
ajax(URL.join('&'), {
success: function (res) {
const response = JSON.parse(res)
resolve(response)
},
error: function (err) { reject(err) }
});
});
}
function setGlobalConfig(config, segments) {
const ortbSegments = {
ortb2: {
user: {
data: [{
name: 'adnuntius',
segment: segments
}]
}
}
}
if (config.params && config.params.bidders) {
sourceConfig.mergeBidderConfig({
bidders: config.params.bidders,
config: ortbSegments
})
} else {
sourceConfig.mergeConfig(ortbSegments)
}
}
function alterBidRequests(reqBidsConfigObj, callback, config, userConsent) {
const gdpr = userConsent && userConsent.gdpr;
let allowedToRun = true
if (gdpr) {
if (userConsent.gdpr.gdprApplies) {
if (gdpr.gdprApplies && !gdpr.vendorData.vendorConsents[GVLID]) allowedToRun = false;
}
}
if (allowedToRun) {
const providerRequests = config.params.providers.map(provider => prepProvider(provider))
Promise.allSettled(providerRequests).then((values) => {
const segments = values.reduce((segments, array) => (array.status === 'fulfilled') ? segments.concat(array.value.segments) : [], []).map(segmentId => ({ id: segmentId }))
setGlobalConfig(config, segments)
callback();
})
.catch(err => logError('ADN: err', err));
} else callback();
}
/** @type {RtdSubmodule} */
export const adnuntiusSubmodule = {
name: 'adnuntius',
init: init,
getBidRequestData: alterBidRequests,
setGlobalConfig: setGlobalConfig,
};
export function beforeInit() {
submodule('realTimeData', adnuntiusSubmodule);
}
beforeInit();