forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathliveIntentRtdProvider.js
52 lines (45 loc) · 1.57 KB
/
liveIntentRtdProvider.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
/**
* This module adds the LiveIntent provider to the Real Time Data module (rtdModule).
*/
import { submodule } from '../src/hook.js';
import {deepAccess, deepSetValue} from '../src/utils.js'
/**
* @typedef {import('../modules/rtdModule/index.js').RtdSubmodule} RtdSubmodule
* @typedef {import('../modules/rtdModule/index.js').SubmoduleConfig} SubmoduleConfig
* @typedef {import('../modules/rtdModule/index.js').UserConsentData} UserConsentData
*/
const SUBMODULE_NAME = 'liveintent';
const GVLID = 148;
/**
* Init
* @param {Object} config Module configuration
* @param {UserConsentData} userConsent User consent
* @returns true
*/
const init = (config, userConsent) => {
return true;
}
/**
* onBidRequest is called for each bidder during an auction and contains the bids for that bidder.
*
* @param {Object} bidRequest
* @param {SubmoduleConfig} config
* @param {UserConsentData} userConsent
*/
function onBidRequest(bidRequest, config, userConsent) {
bidRequest.bids.forEach(bid => {
const providedSegmentsFromUserId = deepAccess(bid, 'userId.lipb.segments', [])
if (providedSegmentsFromUserId.length > 0) {
const providedSegments = { name: 'liveintent.com', segment: providedSegmentsFromUserId.map(id => ({ id })) }
const existingData = deepAccess(bid, 'ortb2.user.data', [])
deepSetValue(bid, 'ortb2.user.data', existingData.concat(providedSegments))
}
})
}
export const liveIntentRtdSubmodule = {
name: SUBMODULE_NAME,
gvlid: GVLID,
init: init,
onBidRequestEvent: onBidRequest
};
submodule('realTimeData', liveIntentRtdSubmodule);