forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmissenaBidAdapter.js
211 lines (184 loc) · 6.53 KB
/
missenaBidAdapter.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
import {
buildUrl,
formatQS,
generateUUID,
isFn,
logInfo,
safeJSONParse,
triggerPixel,
} from '../src/utils.js';
import { BANNER } from '../src/mediaTypes.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { getStorageManager } from '../src/storageManager.js';
import { getCurrencyFromBidderRequest } from '../libraries/ortb2Utils/currency.js';
import { isAutoplayEnabled } from '../libraries/autoplayDetection/autoplay.js';
/**
* @typedef {import('../src/adapters/bidderFactory.js').BidRequest} BidRequest
* @typedef {import('../src/adapters/bidderFactory.js').BidderRequest} BidderRequest
* @typedef {import('../src/adapters/bidderFactory.js').Bid} Bid
* @typedef {import('../src/adapters/bidderFactory.js').ServerResponse} ServerResponse
* @typedef {import('../src/adapters/bidderFactory.js').validBidRequests} validBidRequests
* @typedef {import('../src/adapters/bidderFactory.js').TimedOutBid} TimedOutBid
*/
const BIDDER_CODE = 'missena';
const ENDPOINT_URL = 'https://bid.missena.io/';
const EVENTS_DOMAIN = 'events.missena.io';
const EVENTS_DOMAIN_DEV = 'events.staging.missena.xyz';
export const storage = getStorageManager({ bidderCode: BIDDER_CODE });
window.msna_ik = window.msna_ik || generateUUID();
/* Get Floor price information */
function getFloor(bidRequest) {
if (!isFn(bidRequest.getFloor)) {
return {};
}
const bidFloors = bidRequest.getFloor({
currency: 'USD',
mediaType: BANNER,
});
if (!isNaN(bidFloors?.floor)) {
return bidFloors;
}
}
/* Helper function that converts the prebid data to the payload expected by our servers */
function toPayload(bidRequest, bidderRequest) {
const payload = {
adunit: bidRequest.adUnitCode,
ik: window.msna_ik,
request_id: bidRequest.bidId,
timeout: bidderRequest.timeout,
};
if (bidderRequest && bidderRequest.refererInfo) {
// TODO: is 'topmostLocation' the right value here?
payload.referer = bidderRequest.refererInfo.topmostLocation;
payload.referer_canonical = bidderRequest.refererInfo.canonicalUrl;
}
if (bidderRequest && bidderRequest.gdprConsent) {
payload.consent_string = bidderRequest.gdprConsent.consentString;
payload.consent_required = bidderRequest.gdprConsent.gdprApplies;
}
if (bidderRequest && bidderRequest.uspConsent) {
payload.us_privacy = bidderRequest.uspConsent;
}
const baseUrl = bidRequest.params.baseUrl || ENDPOINT_URL;
payload.params = bidRequest.params;
if (bidRequest.ortb2?.device?.ext?.cdep) {
payload.cdep = bidRequest.ortb2?.device?.ext?.cdep;
}
payload.userEids = bidRequest.userIdAsEids || [];
payload.version = '$prebid.version$';
const bidFloor = getFloor(bidRequest);
payload.floor = bidFloor?.floor;
payload.floor_currency = bidFloor?.currency;
payload.currency = getCurrencyFromBidderRequest(bidderRequest);
payload.schain = bidRequest.schain;
payload.coppa = bidderRequest?.ortb2?.regs?.coppa ? 1 : 0;
payload.autoplay = isAutoplayEnabled() === true ? 1 : 0;
payload.screen = { height: screen.height, width: screen.width };
return {
method: 'POST',
url: baseUrl + '?' + formatQS({ t: bidRequest.params.apiKey }),
data: JSON.stringify(payload),
};
}
export const spec = {
aliases: ['msna'],
code: BIDDER_CODE,
gvlid: 687,
supportedMediaTypes: [BANNER],
/**
* Determines whether or not the given bid request is valid.
*
* @param {BidRequest} bid The bid params to validate.
* @return boolean True if this is a valid bid, and false otherwise.
*/
isBidRequestValid: function (bid) {
return typeof bid == 'object' && !!bid.params.apiKey;
},
/**
* Make a server request from the list of BidRequests.
*
* @param {Array<BidRequest>} validBidRequests
* @param {BidderRequest} bidderRequest
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: function (validBidRequests, bidderRequest) {
const capKey = `missena.missena.capper.remove-bubble.${validBidRequests[0]?.params.apiKey}`;
const capping = safeJSONParse(storage.getDataFromLocalStorage(capKey));
const referer = bidderRequest?.refererInfo?.topmostLocation;
if (
typeof capping?.expiry === 'number' &&
new Date().getTime() < capping?.expiry &&
(!capping?.referer || capping?.referer == referer)
) {
logInfo('Missena - Capped');
return [];
}
this.msnaApiKey = validBidRequests[0]?.params.apiKey;
return validBidRequests.map((bidRequest) =>
toPayload(bidRequest, bidderRequest),
);
},
/**
* Unpack the response from the server into a list of bids.
*
* @param {ServerResponse} serverResponse A successful response from the server.
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: function (serverResponse, bidRequest) {
const bidResponses = [];
const response = serverResponse.body;
if (response && !response.timeout && !!response.ad) {
bidResponses.push(response);
}
return bidResponses;
},
getUserSyncs: function (
syncOptions,
serverResponses,
gdprConsent = {},
uspConsent,
) {
if (!syncOptions.iframeEnabled || !this.msnaApiKey) {
return [];
}
const url = new URL('https://sync.missena.io/iframe');
url.searchParams.append('t', this.msnaApiKey);
if (typeof gdprConsent.gdprApplies === 'boolean') {
url.searchParams.append('gdpr', Number(gdprConsent.gdprApplies));
url.searchParams.append('gdpr_consent', gdprConsent.consentString);
}
if (uspConsent) {
url.searchParams.append('us_privacy', uspConsent);
}
return [{ type: 'iframe', url: url.href }];
},
/**
* Register bidder specific code, which will execute if bidder timed out after an auction
* @param {TimedOutBid} timeoutData - Containing timeout specific data
*/
onTimeout: function onTimeout(timeoutData) {
logInfo('Missena - Timeout from adapter', timeoutData);
},
/**
* Register bidder specific code, which@ will execute if a bid from this bidder won the auction
* @param {Bid} bid - The bid that won the auction
*/
onBidWon: function (bid) {
const hostname = bid.params[0].baseUrl ? EVENTS_DOMAIN_DEV : EVENTS_DOMAIN;
triggerPixel(
buildUrl({
protocol: 'https',
hostname,
pathname: '/v1/bidsuccess',
search: {
t: bid.params[0].apiKey,
provider: bid.meta?.networkName,
cpm: bid.originalCpm,
currency: bid.originalCurrency,
},
}),
);
logInfo('Missena - Bid won', bid);
},
};
registerBidder(spec);