forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdsp_genieeBidAdapter.js
134 lines (123 loc) · 4.47 KB
/
dsp_genieeBidAdapter.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
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER } from '../src/mediaTypes.js';
import { ortbConverter } from '../libraries/ortbConverter/converter.js';
import { deepAccess, deepSetValue } from '../src/utils.js';
import { config } from '../src/config.js';
import { getCurrencyFromBidderRequest } from '../libraries/ortb2Utils/currency.js';
/**
* @typedef {import('../src/adapters/bidderFactory.js').BidRequest} BidRequest
* @typedef {import('../src/adapters/bidderFactory.js').validBidRequests} validBidRequests
* @typedef {import('../src/adapters/bidderFactory.js').BidderRequest} BidderRequest
* @typedef {import('../src/adapters/bidderFactory.js').ServerResponse} ServerResponse
* @typedef {import('../src/adapters/bidderFactory.js').SyncOptions} SyncOptions
* @typedef {import('../src/adapters/bidderFactory.js').UserSync} UserSync
*/
const BIDDER_CODE = 'dsp_geniee';
const ENDPOINT_URL = 'https://rt.gsspat.jp/prebid_auction';
const ENDPOINT_URL_UNCOMFORTABLE = 'https://rt.gsspat.jp/prebid_uncomfortable';
const ENDPOINT_USERSYNC = 'https://rt.gsspat.jp/prebid_cs';
const VALID_CURRENCIES = ['USD', 'JPY'];
const converter = ortbConverter({
context: { ttl: 300, netRevenue: true },
// set optional parameters
imp(buildImp, bidRequest, context) {
const imp = buildImp(bidRequest, context);
deepSetValue(imp, 'ext', bidRequest.params);
return imp;
}
});
function USPConsent(consent) {
return typeof consent === 'string' && consent[0] === '1' && consent.toUpperCase()[2] === 'Y';
}
function invalidCurrency(currency) {
return typeof currency === 'string' && VALID_CURRENCIES.indexOf(currency.toUpperCase()) === -1;
}
function hasTest(imp) {
if (typeof imp !== 'object') {
return false;
}
for (let i = 0; i < imp.length; i++) {
if (deepAccess(imp[i], 'ext.test') === 1) {
return true;
}
}
return false;
}
export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER],
/**
* Determines whether or not the given bid request is valid.
*
* @param {BidRequest} _ The bid params to validate.
* @return boolean True if this is a valid bid, and false otherwise.
*/
isBidRequestValid: function (_) {
return true;
},
/**
* Make a server request from the list of BidRequests.
*
* @param {validBidRequests} validBidRequests - an array of bids
* @param {BidderRequest} bidderRequest - the master bidRequest object
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: function (validBidRequests, bidderRequest) {
if (deepAccess(bidderRequest, 'gdprConsent.gdprApplies') || // gdpr
USPConsent(bidderRequest.uspConsent) || // usp
config.getConfig('coppa') || // coppa
invalidCurrency(getCurrencyFromBidderRequest(bidderRequest)) // currency validation
) {
return {
method: 'GET',
url: ENDPOINT_URL_UNCOMFORTABLE
};
}
const payload = converter.toORTB({ validBidRequests, bidderRequest });
if (hasTest(deepAccess(payload, 'imp'))) {
deepSetValue(payload, 'test', 1);
}
deepSetValue(payload, 'at', 1); // first price auction only
return {
method: 'POST',
url: ENDPOINT_URL,
data: payload
};
},
/**
* Unpack the response from the server into a list of bids.
*
* @param {ServerResponse} serverResponse A successful response from the server.
* @param {BidRequest} bidRequest - the master bidRequest object
* @return {bids} - An array of bids which were nested inside the server.
*/
interpretResponse: function (serverResponse, bidRequest) {
if (!serverResponse.body) { // empty response (no bids)
return [];
}
const bids = converter.fromORTB({ response: serverResponse.body, request: bidRequest.data }).bids;
return bids;
},
/**
* Register the user sync pixels which should be dropped after the auction.
*
* @param {SyncOptions} syncOptions Which user syncs are allowed?
* @param {ServerResponse[]} serverResponses List of server's responses.
* @return {UserSync[]} The user syncs which should be dropped.
*/
getUserSyncs: function (syncOptions, serverResponses, gdprConsent, uspConsent) {
const syncs = [];
// gdpr & usp
if (deepAccess(gdprConsent, 'gdprApplies') || USPConsent(uspConsent)) {
return syncs;
}
if (syncOptions.pixelEnabled) {
syncs.push({
type: 'image',
url: ENDPOINT_USERSYNC
});
}
return syncs;
}
};
registerBidder(spec);