-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
idxBidAdapter.js
80 lines (69 loc) · 1.96 KB
/
idxBidAdapter.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
import { registerBidder } from '../src/adapters/bidderFactory.js'
import { BANNER } from '../src/mediaTypes.js'
import { isArray, isNumber } from '../src/utils.js'
const BIDDER_CODE = 'idx'
const ENDPOINT_URL = 'https://dev-event.dxmdp.com/rest/api/v1/bid'
const SUPPORTED_MEDIA_TYPES = [ BANNER ]
export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: SUPPORTED_MEDIA_TYPES,
isBidRequestValid: function (bid) {
return isArray(bid.mediaTypes?.banner?.sizes) && bid.mediaTypes.banner.sizes.every(size => {
return isArray(size) && size.length === 2 && isNumber(size[0]) && isNumber(size[1])
})
},
buildRequests: function (bidRequests, bidderRequest) {
const payload = {
id: bidderRequest.bidderRequestId,
imp: bidRequests.map(request => {
const { bidId, sizes } = request
const item = {
id: bidId,
}
if (request.mediaTypes.banner) {
item.banner = {
format: (request.mediaTypes.banner.sizes || sizes).map(size => {
return { w: size[0], h: size[1] }
}),
}
}
return item
}),
}
const payloadString = JSON.stringify(payload)
return {
method: 'POST',
url: ENDPOINT_URL,
data: payloadString,
bidderRequest,
options: {
withCredentials: false,
contentType: 'application/json'
}
}
},
interpretResponse: function (serverResponse) {
const response = serverResponse.body
const bids = []
response.seatbid.forEach(seat => {
seat.bid.forEach(bid => {
bids.push({
requestId: bid.impid,
cpm: bid.price,
width: bid.w,
height: bid.h,
creativeId: bid.crid,
ad: bid.adm,
currency: 'USD',
netRevenue: true,
ttl: 300,
meta: {
advertiserDomains: bid.adomain || [],
},
})
})
})
return bids
},
}
registerBidder(spec)