forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathholidBidAdapter.js
184 lines (152 loc) · 4.25 KB
/
holidBidAdapter.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import {
deepAccess,
deepSetValue, getBidIdParameter,
isStr,
logMessage,
triggerPixel,
} from '../src/utils.js';
import {BANNER} from '../src/mediaTypes.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
const BIDDER_CODE = 'holid'
const GVLID = 1177
const ENDPOINT = 'https://helloworld.holid.io/openrtb2/auction'
const COOKIE_SYNC_ENDPOINT = 'https://null.holid.io/sync.html'
const TIME_TO_LIVE = 300
const TMAX = 500
let wurlMap = {}
export const spec = {
code: BIDDER_CODE,
gvlid: GVLID,
supportedMediaTypes: [BANNER],
isBidRequestValid: function (bid) {
return !!bid.params.adUnitID
},
buildRequests: function (validBidRequests, bidderRequest) {
return validBidRequests.map((bid) => {
const requestData = {
...bid.ortb2,
source: {schain: bid.schain},
id: bidderRequest.bidderRequestId,
imp: [getImp(bid)],
tmax: TMAX,
...buildStoredRequest(bid)
}
if (bid.userIdAsEids) {
deepSetValue(requestData, 'user.ext.eids', bid.userIdAsEids)
}
return {
method: 'POST',
url: ENDPOINT,
data: JSON.stringify(requestData),
bidId: bid.bidId,
}
})
},
interpretResponse: function (serverResponse, bidRequest) {
const bidResponses = []
if (!serverResponse.body.seatbid) {
return []
}
serverResponse.body.seatbid.map((response) => {
response.bid.map((bid) => {
const requestId = bidRequest.bidId
const wurl = deepAccess(bid, 'ext.prebid.events.win')
const bidResponse = {
requestId,
cpm: bid.price,
width: bid.w,
height: bid.h,
ad: bid.adm,
creativeId: bid.crid,
currency: serverResponse.body.cur,
netRevenue: true,
ttl: TIME_TO_LIVE,
}
addWurl(requestId, wurl)
bidResponses.push(bidResponse)
})
})
return bidResponses
},
getUserSyncs(optionsType, serverResponse, gdprConsent, uspConsent) {
const syncs = [{
type: 'image',
url: 'https://track.adform.net/Serving/TrackPoint/?pm=2992097&lid=132720821'
}]
if (!serverResponse || serverResponse.length === 0) {
return syncs
}
const bidders = getBidders(serverResponse)
// note this only does the iframe sync when gdpr consent object exists to match previous behavior (generate error on gdprconsent not existing)
if (optionsType.iframeEnabled && bidders && gdprConsent) {
const queryParams = []
queryParams.push('bidders=' + bidders)
queryParams.push('gdpr=' + +gdprConsent?.gdprApplies)
queryParams.push('gdpr_consent=' + gdprConsent?.consentString)
queryParams.push('usp_consent=' + (uspConsent || ''))
let strQueryParams = queryParams.join('&')
if (strQueryParams.length > 0) {
strQueryParams = '?' + strQueryParams
}
syncs.push({
type: 'iframe',
url: COOKIE_SYNC_ENDPOINT + strQueryParams + '&type=iframe',
})
}
return syncs
},
onBidWon(bid) {
const wurl = getWurl(bid.requestId)
if (wurl) {
logMessage(`Invoking image pixel for wurl on BID_WIN: "${wurl}"`)
triggerPixel(wurl)
removeWurl(bid.requestId)
}
}
}
function getImp(bid) {
const imp = buildStoredRequest(bid)
const sizes =
bid.sizes && !Array.isArray(bid.sizes[0]) ? [bid.sizes] : bid.sizes
if (deepAccess(bid, 'mediaTypes.banner')) {
imp.banner = {
format: sizes.map((size) => {
return { w: size[0], h: size[1] }
}),
}
}
return imp
}
function buildStoredRequest(bid) {
return {
ext: {
prebid: {
storedrequest: {
id: getBidIdParameter('adUnitID', bid.params),
},
},
},
}
}
function getBidders(serverResponse) {
const bidders = serverResponse
.map((res) => Object.keys(res.body.ext.responsetimemillis || []))
.flat(1)
if (bidders.length) {
return encodeURIComponent(JSON.stringify([...new Set(bidders)]))
}
}
function addWurl(requestId, wurl) {
if (isStr(requestId)) {
wurlMap[requestId] = wurl
}
}
function removeWurl(requestId) {
delete wurlMap[requestId]
}
function getWurl(requestId) {
if (isStr(requestId)) {
return wurlMap[requestId]
}
}
registerBidder(spec)