forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscatteredBidAdapter.js
72 lines (61 loc) · 1.67 KB
/
scatteredBidAdapter.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
// jshint esversion: 6, es3: false, node: true
'use strict';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER } from '../src/mediaTypes.js';
import { deepAccess, logInfo } from '../src/utils.js';
import { ortbConverter } from '../libraries/ortbConverter/converter.js';
const BIDDER_CODE = 'scattered';
const GVLID = 1179;
export const converter = ortbConverter({
context: {
mediaType: BANNER,
ttl: 360,
netRevenue: true
}
})
export const spec = {
code: BIDDER_CODE,
gvlid: GVLID,
supportedMediaTypes: [BANNER],
// 1.
isBidRequestValid: function (bid) {
const bidderDomain = deepAccess(bid, 'params.bidderDomain')
if (bidderDomain === undefined || bidderDomain === '') {
return false
}
const sizes = deepAccess(bid, 'mediaTypes.banner.sizes')
if (sizes === undefined || sizes.length < 1) {
return false
}
return true
},
// 2.
buildRequests: function (bidRequests, bidderRequest) {
return {
method: 'POST',
url: 'https://' + getKeyOnAny(bidRequests, 'params.bidderDomain'),
data: converter.toORTB({ bidderRequest, bidRequests }),
options: {
contentType: 'application/json'
},
};
},
// 3.
interpretResponse: function (response, request) {
if (!response.body) return;
return converter.fromORTB({ response: response.body, request: request.data }).bids;
},
// 4
onBidWon: function (bid) {
logInfo('onBidWon', bid)
}
}
function getKeyOnAny(collection, key) {
for (let i = 0; i < collection.length; i++) {
const result = deepAccess(collection[i], key);
if (result) {
return result;
}
}
}
registerBidder(spec);