forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresetdigitalBidAdapter.js
214 lines (192 loc) · 6.54 KB
/
resetdigitalBidAdapter.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
import { timestamp, deepAccess, isStr, deepClone, isPlainObject } from '../src/utils.js';
import { getOrigin } from '../libraries/getOrigin/index.js';
import { config } from '../src/config.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER } from '../src/mediaTypes.js';
const BIDDER_CODE = 'resetdigital';
const CURRENCY = 'USD';
export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: ['banner', 'video'],
isBidRequestValid: function (bid) {
return !!(bid.params.pubId || bid.params.zoneId);
},
buildRequests: function (validBidRequests, bidderRequest) {
let stack =
bidderRequest.refererInfo && bidderRequest.refererInfo.stack
? bidderRequest.refererInfo.stack
: [];
let spb =
config.getConfig('userSync') &&
config.getConfig('userSync').syncsPerBidder
? config.getConfig('userSync').syncsPerBidder
: 5;
const payload = {
start_time: timestamp(),
language: window.navigator.userLanguage || window.navigator.language,
site: {
domain: getOrigin(),
iframe: !bidderRequest.refererInfo.reachedTop,
// TODO: the last element in refererInfo.stack is window.location.href, that's unlikely to have been the intent here
url: stack && stack.length > 0 ? [stack.length - 1] : null,
https: window.location.protocol === 'https:',
// TODO: is 'page' the right value here?
referrer: bidderRequest.refererInfo.page,
},
imps: [],
user_ids: validBidRequests[0].userId,
sync_limit: spb,
};
if (bidderRequest && bidderRequest.gdprConsent) {
payload.gdpr = {
applies: bidderRequest.gdprConsent.gdprApplies,
consent: bidderRequest.gdprConsent.consentString,
};
}
if (bidderRequest && bidderRequest.uspConsent) {
payload.ccpa = bidderRequest.uspConsent;
}
function getOrtb2Keywords(ortb2Obj) {
const fields = [
'site.keywords',
'site.content.keywords',
'user.keywords',
'app.keywords',
'app.content.keywords',
];
let result = [];
fields.forEach((path) => {
let keyStr = deepAccess(ortb2Obj, path);
if (isStr(keyStr)) result.push(keyStr);
});
return result;
}
// get the ortb2 keywords data (if it exists)
let ortb2 = deepClone(bidderRequest && bidderRequest.ortb2);
let ortb2KeywordsList = getOrtb2Keywords(ortb2);
// get meta keywords data (if it exists)
let metaKeywords = document.getElementsByTagName('meta')['keywords'];
if (metaKeywords && metaKeywords.content) {
metaKeywords = metaKeywords.content.split(',');
}
for (let x = 0; x < validBidRequests.length; x++) {
let req = validBidRequests[x];
let bidFloor = req.params.bidFloor ? req.params.bidFloor : null;
let bidFloorCur = req.params.bidFloor ? req.params.bidFloorCur : null;
if (typeof req.getFloor === 'function') {
const floorInfo = req.getFloor({
currency: CURRENCY,
mediaType: BANNER,
size: '*',
});
if (
isPlainObject(floorInfo) &&
floorInfo.currency === CURRENCY &&
!isNaN(parseFloat(floorInfo.floor))
) {
bidFloor = parseFloat(floorInfo.floor);
bidFloorCur = CURRENCY;
}
}
// get param kewords (if it exists)
let paramsKeywords = req.params.keywords
? req.params.keywords.split(',')
: [];
// merge all keywords
let keywords = ortb2KeywordsList
.concat(paramsKeywords)
.concat(metaKeywords);
payload.imps.push({
pub_id: req.params.pubId,
site_id: req.params.siteID ? req.params.siteID : null,
placement_id: req.params.placement ? req.params.placement : null,
position: req.params.position ? req.params.position : null,
bid_floor: bidFloor,
bid_floor_cur: bidFloorCur,
lat_long: req.params.latLong ? req.params.latLong : null,
inventory: req.params.inventory ? req.params.inventory : null,
visitor: req.params.visitor ? req.params.visitor : null,
keywords: keywords.join(','),
zone_id: req.params.zoneId,
bid_id: req.bidId,
// TODO: fix transactionId leak: https://github.com/prebid/Prebid.js/issues/9781
imp_id: req.transactionId,
sizes: req.sizes,
force_bid: req.params.forceBid,
coppa: config.getConfig('coppa') === true ? 1 : 0,
media_types: deepAccess(req, 'mediaTypes'),
});
}
let params = validBidRequests[0].params;
let url = params.endpoint ? params.endpoint : '//ads.resetsrv.com';
return {
method: 'POST',
url: url,
data: JSON.stringify(payload),
bids: validBidRequests,
};
},
interpretResponse: function (serverResponse, bidRequest) {
const bidResponses = [];
if (!serverResponse || !serverResponse.body) {
return bidResponses;
}
let res = serverResponse.body;
if (!res.bids || !res.bids.length) {
return [];
}
for (let x = 0; x < serverResponse.body.bids.length; x++) {
let bid = serverResponse.body.bids[x];
bidResponses.push({
requestId: bid.bid_id,
cpm: bid.cpm,
width: bid.w,
height: bid.h,
ad: bid.html,
vastUrl: bid.vast_url,
vastXml: bid.vast_xml,
mediaType: bid.html ? 'banner' : 'video',
ttl: 120,
creativeId: bid.crid,
dealId: bid.deal_id,
netRevenue: true,
currency: 'USD',
meta: {
advertiserDomains: bid.adomain,
},
});
}
return bidResponses;
},
getUserSyncs: function (syncOptions, serverResponses, gdprConsent) {
let syncs = [];
if (!serverResponses.length || !serverResponses[0].body) {
return syncs;
}
let gdprParams = '';
if (gdprConsent) {
if (typeof gdprConsent.gdprApplies === 'boolean') {
gdprParams = `gdpr=${Number(gdprConsent.gdprApplies)}&gdpr_consent=${
gdprConsent.consentString
}`;
} else {
gdprParams = `gdpr_consent=${gdprConsent.consentString}`;
}
}
if (syncOptions.iframeEnabled) {
syncs.push({
type: 'iframe',
url: `https://async.resetdigital.co/async_usersync.html?${gdprParams}`,
});
} else if (syncOptions.pixelEnabled) {
syncs.push({
type: 'image',
url: `https://meta.resetdigital.co/pchain${
gdprParams ? `?${gdprParams}` : ''
}`,
});
}
return syncs;
},
};
registerBidder(spec);