-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
connectadBidAdapter.js
259 lines (215 loc) · 7.79 KB
/
connectadBidAdapter.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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
import { deepAccess, deepSetValue, mergeDeep, logWarn, generateUUID } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER } from '../src/mediaTypes.js'
import {config} from '../src/config.js';
import {tryAppendQueryString} from '../libraries/urlUtils/urlUtils.js';
const BIDDER_CODE = 'connectad';
const BIDDER_CODE_ALIAS = 'connectadrealtime';
const ENDPOINT_URL = 'https://i.connectad.io/api/v2';
const SUPPORTED_MEDIA_TYPES = [BANNER];
export const spec = {
code: BIDDER_CODE,
gvlid: 138,
aliases: [ BIDDER_CODE_ALIAS ],
supportedMediaTypes: SUPPORTED_MEDIA_TYPES,
isBidRequestValid: function(bid) {
return !!(bid.params.networkId && bid.params.siteId);
},
buildRequests: function(validBidRequests, bidderRequest) {
let ret = {
method: 'POST',
url: '',
data: '',
bidRequest: []
};
if (validBidRequests.length < 1) {
return ret;
}
const sellerDefinedAudience = deepAccess(bidderRequest, 'ortb2.user.data', config.getAnyConfig('ortb2.user.data'));
const sellerDefinedContext = deepAccess(bidderRequest, 'ortb2.site.content.data', config.getAnyConfig('ortb2.site.content.data'));
const data = Object.assign({
placements: [],
time: Date.now(),
url: bidderRequest.refererInfo?.page,
referrer: bidderRequest.refererInfo?.ref,
screensize: getScreenSize(),
dnt: (navigator.doNotTrack == 'yes' || navigator.doNotTrack == '1' || navigator.msDoNotTrack == '1') ? 1 : 0,
language: navigator.language,
ua: navigator.userAgent,
pversion: '$prebid.version$',
cur: 'USD',
user: {},
regs: {},
source: {},
site: {},
sda: sellerDefinedAudience,
sdc: sellerDefinedContext,
});
const ortb2Params = bidderRequest?.ortb2 || {};
['site', 'user', 'device', 'bcat', 'badv', 'regs'].forEach(entry => {
const ortb2Param = ortb2Params[entry];
if (ortb2Param) {
mergeDeep(data, { [entry]: ortb2Param });
}
});
// coppa compliance
if (config.getConfig('coppa') === true) {
deepSetValue(data, 'regs.coppa', 1);
}
// adding schain object
if (validBidRequests[0].schain) {
deepSetValue(data, 'source.ext.schain', validBidRequests[0].schain);
}
// Attaching GDPR Consent Params
if (bidderRequest.gdprConsent) {
let gdprApplies;
if (typeof bidderRequest.gdprConsent.gdprApplies === 'boolean') {
gdprApplies = bidderRequest.gdprConsent.gdprApplies ? 1 : 0;
}
deepSetValue(data, 'user.ext.gdpr', gdprApplies);
deepSetValue(data, 'user.ext.consent', bidderRequest.gdprConsent.consentString);
}
// CCPA
if (bidderRequest.uspConsent) {
deepSetValue(data, 'user.ext.us_privacy', bidderRequest.uspConsent);
}
// GPP Support
if (bidderRequest?.gppConsent?.gppString) {
deepSetValue(data, 'regs.gpp', bidderRequest.gppConsent.gppString);
deepSetValue(data, 'regs.gpp_sid', bidderRequest.gppConsent.applicableSections);
} else if (bidderRequest?.ortb2?.regs?.gpp) {
deepSetValue(data, 'regs.gpp', bidderRequest.ortb2.regs.gpp);
deepSetValue(data, 'regs.gpp_sid', bidderRequest.ortb2.regs.gpp_sid);
}
// DSA Support
if (bidderRequest?.ortb2?.regs?.ext?.dsa) {
deepSetValue(data, 'regs.ext.dsa', bidderRequest.ortb2.regs.ext.dsa);
}
// EIDS Support
if (validBidRequests[0].userIdAsEids) {
deepSetValue(data, 'user.ext.eids', validBidRequests[0].userIdAsEids);
}
const tid = deepAccess(bidderRequest, 'ortb2.source.tid')
if (tid) {
deepSetValue(data, 'source.tid', tid)
}
data.tmax = bidderRequest.timeout;
validBidRequests.map(bid => {
const placement = Object.assign({
id: generateUUID(),
divName: bid.bidId,
tagId: bid.adUnitCode,
pisze: bid.mediaTypes.banner.sizes[0] || bid.sizes[0],
sizes: bid.mediaTypes.banner.sizes,
bidfloor: getBidFloor(bid),
siteId: bid.params.siteId,
networkId: bid.params.networkId,
tid: bid.ortb2Imp?.ext?.tid
});
const gpid = deepAccess(bid, 'ortb2Imp.ext.gpid') || deepAccess(bid, 'ortb2Imp.ext.data.pbadslot');
if (gpid) {
placement.gpid = gpid;
}
if (placement.networkId && placement.siteId) {
data.placements.push(placement);
}
});
ret.data = JSON.stringify(data);
ret.bidRequest = validBidRequests;
ret.url = ENDPOINT_URL;
return ret;
},
interpretResponse: function(serverResponse, bidRequest, bidderRequest) {
let bid;
let bids;
let bidId;
let bidObj;
let bidResponses = [];
bids = bidRequest.bidRequest;
serverResponse = (serverResponse || {}).body;
for (let i = 0; i < bids.length; i++) {
bid = {};
bidObj = bids[i];
bidId = bidObj.bidId;
if (serverResponse) {
const decision = serverResponse.decisions && serverResponse.decisions[bidId];
const price = decision && decision.pricing && decision.pricing.clearPrice;
if (decision && price) {
bid.requestId = bidId;
bid.cpm = price;
bid.width = decision.width;
bid.height = decision.height;
bid.dealid = decision.dealid || null;
bid.meta = {
advertiserDomains: decision && decision.adomain ? decision.adomain : []
};
bid.ad = retrieveAd(decision);
bid.currency = 'USD';
bid.creativeId = decision.adId;
bid.ttl = 360;
bid.netRevenue = true;
if (decision.dsa) {
bid.meta = Object.assign({}, bid.meta, { dsa: decision.dsa })
}
if (decision.category) {
bid.meta = Object.assign({}, bid.meta, { primaryCatId: decision.category })
}
bidResponses.push(bid);
}
}
}
return bidResponses;
},
getUserSyncs: (syncOptions, responses, gdprConsent, uspConsent, gppConsent) => {
let pixelType = syncOptions.iframeEnabled ? 'iframe' : 'image';
let syncEndpoint;
if (pixelType == 'iframe') {
syncEndpoint = 'https://sync.connectad.io/iFrameSyncer?';
} else {
syncEndpoint = 'https://sync.connectad.io/ImageSyncer?';
}
if (gdprConsent) {
syncEndpoint = tryAppendQueryString(syncEndpoint, 'gdpr', (gdprConsent.gdprApplies ? 1 : 0));
}
if (gdprConsent && typeof gdprConsent.consentString === 'string') {
syncEndpoint = tryAppendQueryString(syncEndpoint, 'gdpr_consent', gdprConsent.consentString);
}
if (uspConsent) {
syncEndpoint = tryAppendQueryString(syncEndpoint, 'us_privacy', uspConsent);
}
if (gppConsent?.gppString && gppConsent?.applicableSections?.length) {
syncEndpoint = tryAppendQueryString(syncEndpoint, 'gpp', gppConsent.gppString);
syncEndpoint = tryAppendQueryString(syncEndpoint, 'gpp_sid', gppConsent?.applicableSections?.join(','));
}
if (config.getConfig('coppa') === true) {
syncEndpoint = tryAppendQueryString(syncEndpoint, 'coppa', 1);
}
if (syncOptions.iframeEnabled || syncOptions.pixelEnabled) {
return [{
type: pixelType,
url: syncEndpoint
}];
} else {
logWarn('Bidder ConnectAd: No User-Matching allowed');
}
}
};
function getBidFloor(bidRequest) {
let floorInfo = {};
if (typeof bidRequest.getFloor === 'function') {
floorInfo = bidRequest.getFloor({
currency: 'USD',
mediaType: 'banner',
size: '*'
});
}
let floor = floorInfo?.floor || bidRequest.params.bidfloor || bidRequest.params.floorprice || 0;
return floor;
}
function retrieveAd(decision) {
return decision.contents && decision.contents[0] && decision.contents[0].body;
}
function getScreenSize() {
return [window.screen.width, window.screen.height].join('x');
}
registerBidder(spec);