forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproxistoreBidAdapter.js
185 lines (165 loc) · 4.96 KB
/
proxistoreBidAdapter.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import { isFn, isPlainObject } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
const BIDDER_CODE = 'proxistore';
const PROXISTORE_VENDOR_ID = 418;
const COOKIE_BASE_URL = 'https://api.proxistore.com/v3/rtb/prebid/multi';
const COOKIE_LESS_URL =
'https://api.cookieless-proxistore.com/v3/rtb/prebid/multi';
function _createServerRequest(bidRequests, bidderRequest) {
var sizeIds = [];
bidRequests.forEach(function (bid) {
var sizeId = {
id: bid.bidId,
sizes: bid.sizes.map(function (size) {
return {
width: size[0],
height: size[1],
};
}),
floor: _assignFloor(bid),
segments: _assignSegments(bid),
};
sizeIds.push(sizeId);
});
var payload = {
// TODO: fix auctionId leak: https://github.com/prebid/Prebid.js/issues/9781
auctionId: bidRequests[0].auctionId,
transactionId: bidRequests[0].ortb2Imp?.ext?.tid,
bids: sizeIds,
website: bidRequests[0].params.website,
language: bidRequests[0].params.language,
gdpr: {
applies: false,
consentGiven: false,
},
};
if (bidderRequest && bidderRequest.gdprConsent) {
var gdprConsent = bidderRequest.gdprConsent;
if (
typeof gdprConsent.gdprApplies === 'boolean' &&
gdprConsent.gdprApplies
) {
payload.gdpr.applies = true;
}
if (
typeof gdprConsent.consentString === 'string' &&
gdprConsent.consentString
) {
payload.gdpr.consentString = bidderRequest.gdprConsent.consentString;
}
if (gdprConsent.vendorData) {
var vendorData = gdprConsent.vendorData;
if (
vendorData.vendor &&
vendorData.vendor.consents &&
typeof vendorData.vendor.consents[PROXISTORE_VENDOR_ID.toString(10)] !==
'undefined'
) {
payload.gdpr.consentGiven =
!!vendorData.vendor.consents[PROXISTORE_VENDOR_ID.toString(10)];
}
}
}
var options = {
contentType: 'application/json',
withCredentials: payload.gdpr.consentGiven,
customHeaders: {
version: '1.0.4',
},
};
var endPointUri =
payload.gdpr.consentGiven || !payload.gdpr.applies
? COOKIE_BASE_URL
: COOKIE_LESS_URL;
return {
method: 'POST',
url: endPointUri,
data: JSON.stringify(payload),
options: options,
};
}
function _assignSegments(bid) {
var segs = (bid.ortb2 && bid.ortb2.user && bid.ortb2.user.ext && bid.ortb2.user.ext.data && bid.ortb2.user.ext.data.sd_rtd && bid.ortb2.user.ext.data.sd_rtd.segments ? bid.ortb2.user.ext.data.sd_rtd.segments : []);
var cats = {};
if (bid.ortb2 && bid.ortb2.site && bid.ortb2.site.ext && bid.ortb2.site.ext.data && bid.ortb2.site.ext.data.sd_rtd) {
if (bid.ortb2.site.ext.data.sd_rtd.categories) {
segs = segs.concat(bid.ortb2.site.ext.data.sd_rtd.categories);
}
if (bid.ortb2.site.ext.data.sd_rtd.categories_score) {
cats = bid.ortb2.site.ext.data.sd_rtd.categories_score;
}
}
return {
segments: segs,
contextual_categories: cats
};
}
function _createBidResponse(response) {
return {
requestId: response.requestId,
cpm: response.cpm,
width: response.width,
height: response.height,
ad: response.ad,
ttl: response.ttl,
creativeId: response.creativeId,
currency: response.currency,
netRevenue: response.netRevenue,
vastUrl: response.vastUrl,
vastXml: response.vastXml,
dealId: response.dealId,
meta: response.meta,
};
}
/**
* Determines whether or not the given bid request is valid.
*
* @param bid The bid params to validate.
* @return boolean True if this is a valid bid, and false otherwise.
*/
function isBidRequestValid(bid) {
return !!(bid.params.website && bid.params.language);
}
/**
* Make a server request from the list of BidRequests.
*
* @param bidRequests - an array of bids
* @param bidderRequest
* @return ServerRequest Info describing the request to the server.
*/
function buildRequests(bidRequests, bidderRequest) {
var request = _createServerRequest(bidRequests, bidderRequest);
return request;
}
/**
* Unpack the response from the server into a list of bids.
*
* @param serverResponse A successful response from the server.
* @param bidRequest Request original server request
* @return An array of bids which were nested inside the server.
*/
function interpretResponse(serverResponse, bidRequest) {
return serverResponse.body.map(_createBidResponse);
}
function _assignFloor(bid) {
if (!isFn(bid.getFloor)) {
return bid.params.bidFloor ? bid.params.bidFloor : null;
}
const floor = bid.getFloor({
currency: 'EUR',
mediaType: 'banner',
size: '*',
});
if (isPlainObject(floor) && !isNaN(floor.floor) && floor.currency === 'EUR') {
return floor.floor;
}
return null;
}
export const spec = {
code: BIDDER_CODE,
isBidRequestValid: isBidRequestValid,
buildRequests: buildRequests,
interpretResponse: interpretResponse,
gvlid: PROXISTORE_VENDOR_ID,
};
registerBidder(spec);