forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptableBidAdapter.js
67 lines (63 loc) · 2.18 KB
/
optableBidAdapter.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
import * as utils from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { config } from '../src/config.js';
import { BANNER } from '../src/mediaTypes.js';
import { ortbConverter } from '../libraries/ortbConverter/converter.js'
const converter = ortbConverter({
context: { netRevenue: true, ttl: 300 },
imp(buildImp, bidRequest, context) {
const imp = buildImp(bidRequest, context);
utils.mergeDeep(imp, {
tagid: bidRequest.params.site,
});
return imp;
}
});
const BIDDER_CODE = 'optable';
const DEFAULT_REGION = 'ca'
const DEFAULT_ORIGIN = 'https://ads.optable.co'
function getOrigin() {
return config.getConfig('optable.origin') ?? DEFAULT_ORIGIN;
}
function getBaseUrl() {
const region = config.getConfig('optable.region') ?? DEFAULT_REGION;
return `${getOrigin()}/${region}`
}
export const spec = {
code: BIDDER_CODE,
isBidRequestValid: function(bid) { return !!bid.params?.site },
buildRequests: function(bidRequests, bidderRequest) {
const requestURL = `${getBaseUrl()}/ortb2/v1/ssp/bid`
const data = converter.toORTB({ bidRequests, bidderRequest, context: { mediaType: BANNER } });
return { method: 'POST', url: requestURL, data }
},
buildPAAPIConfigs: function(bidRequests) {
const origin = getOrigin();
return bidRequests
.filter(req => req.ortb2Imp?.ext?.ae)
.map(bid => ({
bidId: bid.bidId,
config: {
seller: origin,
decisionLogicURL: `${getBaseUrl()}/paapi/v1/ssp/decision-logic.js?origin=${bid.params.site}`,
interestGroupBuyers: [origin],
perBuyerMultiBidLimits: {
[origin]: 100
},
perBuyerCurrencies: {
[origin]: 'USD'
}
}
}))
},
interpretResponse: function(response, request) {
const bids = converter.fromORTB({ response: response.body, request: request.data }).bids
const auctionConfigs = (response.body.ext?.optable?.fledge?.auctionconfigs ?? []).map((cfg) => {
const { impid, ...config } = cfg;
return { bidId: impid, config }
})
return { bids, paapi: auctionConfigs }
},
supportedMediaTypes: [BANNER]
}
registerBidder(spec);