forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkimberliteBidAdapter.js
102 lines (82 loc) · 2.92 KB
/
kimberliteBidAdapter.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
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import { ortbConverter } from '../libraries/ortbConverter/converter.js'
import { deepSetValue, replaceMacros } from '../src/utils.js';
import {ORTB_MTYPES} from '../libraries/ortbConverter/processors/mediaType.js';
const VERSION = '1.1.0';
const BIDDER_CODE = 'kimberlite';
const METHOD = 'POST';
export const ENDPOINT_URL = 'https://kimberlite.io/rtb/bid/pbjs';
const VERSION_INFO = {
ver: '$prebid.version$',
adapterVer: `${VERSION}`
};
const converter = ortbConverter({
context: {
netRevenue: true,
ttl: 300
},
request(buildRequest, imps, bidderRequest, context) {
const bidRequest = buildRequest(imps, bidderRequest, context);
deepSetValue(bidRequest, 'site.publisher.domain', bidderRequest.refererInfo.domain);
deepSetValue(bidRequest, 'site.page', bidderRequest.refererInfo.page);
deepSetValue(bidRequest, 'ext.prebid.ver', VERSION_INFO.ver);
deepSetValue(bidRequest, 'ext.prebid.adapterVer', VERSION_INFO.adapterVer);
bidRequest.at = 1;
return bidRequest;
},
imp (buildImp, bidRequest, context) {
const imp = buildImp(bidRequest, context);
imp.tagid = bidRequest.params.placementId;
return imp;
},
bidResponse: function (buildBidResponse, bid, context) {
if (!bid.price) return;
const [type] = Object.keys(context.bidRequest.mediaTypes);
if (Object.values(ORTB_MTYPES).includes(type)) {
context.mediaType = type;
}
bid.adm = expandAuctionMacros(bid.adm, bid.price, context.ortbResponse.cur);
if (bid.nurl && bid.nurl != '') {
bid.nurl = expandAuctionMacros(bid.nurl, bid.price, context.ortbResponse.cur);
}
const bidResponse = buildBidResponse(bid, context);
return bidResponse;
},
});
export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER, VIDEO],
isBidRequestValid: (bidRequest = {}) => {
const { params, mediaTypes } = bidRequest;
let isValid = Boolean(params && params.placementId);
if (mediaTypes && mediaTypes[BANNER]) {
isValid = isValid && Boolean(mediaTypes[BANNER].sizes);
} else if (mediaTypes && mediaTypes[VIDEO]) {
isValid = isValid && Boolean(mediaTypes[VIDEO].mimes);
} else {
isValid = false;
}
return isValid;
},
buildRequests: function (bidRequests, bidderRequest) {
return {
method: METHOD,
url: ENDPOINT_URL,
data: converter.toORTB({
bidRequests,
bidderRequest
})
}
},
interpretResponse(serverResponse, bidRequest) {
const bids = converter.fromORTB({response: serverResponse.body, request: bidRequest.data}).bids;
return bids;
}
};
export function expandAuctionMacros(str, price, currency) {
if (!str) return;
const defaultCurrency = 'RUB';
return replaceMacros(str, {AUCTION_PRICE: price, AUCTION_CURRENCY: currency || defaultCurrency});
};
registerBidder(spec);