forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlkqdBidAdapter.js
232 lines (207 loc) · 7.07 KB
/
lkqdBidAdapter.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
import { logError, _each, generateUUID, buildUrl } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { config } from '../src/config.js';
import { VIDEO } from '../src/mediaTypes.js';
const BIDDER_CODE = 'lkqd';
const BID_TTL_DEFAULT = 300;
const MIMES_TYPES = ['application/x-mpegURL', 'video/mp4', 'video/H264'];
const PROTOCOLS = [1, 2, 3, 4, 5, 6, 7, 8];
const PARAM_VOLUME_DEFAULT = '100';
const DEFAULT_SIZES = [[640, 480]];
function calculateSizes(VIDEO_BID, bid) {
const userProvided = bid.sizes && Array.isArray(bid.sizes) ? (Array.isArray(bid.sizes[0]) ? bid.sizes : [bid.sizes]) : DEFAULT_SIZES;
const preBidProvided = VIDEO_BID.playerSize && Array.isArray(VIDEO_BID.playerSize) ? (Array.isArray(VIDEO_BID.playerSize[0]) ? VIDEO_BID.playerSize : [VIDEO_BID.playerSize]) : null;
return preBidProvided || userProvided;
}
function isSet(value) {
return value != null;
}
export const spec = {
code: BIDDER_CODE,
aliases: [],
supportedMediaTypes: [VIDEO],
isBidRequestValid: function(bid) {
return bid.bidder === BIDDER_CODE && bid.params && Object.keys(bid.params).length > 0 &&
((isSet(bid.params.publisherId) && parseInt(bid.params.publisherId) > 0) || (isSet(bid.params.placementId) && parseInt(bid.params.placementId) > 0)) &&
bid.params.siteId != null;
},
buildRequests: function(validBidRequests, bidderRequest) {
const BIDDER_REQUEST = bidderRequest || {};
const serverRequestObjects = [];
const UTC_OFFSET = new Date().getTimezoneOffset();
const UA = navigator.userAgent;
const USP = BIDDER_REQUEST.uspConsent || null;
// TODO: does the fallback make sense here?
const REFERER = BIDDER_REQUEST?.refererInfo?.domain || window.location.host;
const BIDDER_GDPR = BIDDER_REQUEST.gdprConsent && BIDDER_REQUEST.gdprConsent.gdprApplies ? 1 : null;
const BIDDER_GDPRS = BIDDER_REQUEST.gdprConsent && BIDDER_REQUEST.gdprConsent.consentString ? BIDDER_REQUEST.gdprConsent.consentString : null;
_each(validBidRequests, (bid) => {
const DOMAIN = bid.params.pageurl || REFERER;
const GDPR = BIDDER_GDPR || bid.params.gdpr || null;
const GDPRS = BIDDER_GDPRS || bid.params.gdprs || null;
const DNT = bid.params.dnt || null;
const BID_FLOOR = 0;
const VIDEO_BID = bid.video ? bid.video : {};
const requestData = {
id: generateUUID(),
imp: [],
site: {
domain: DOMAIN
},
device: {
ua: UA,
geo: {
utcoffset: UTC_OFFSET
}
},
user: {
ext: {}
},
test: 0,
at: 2,
tmax: bidderRequest.timeout,
cur: ['USD'],
regs: {
ext: {
us_privacy: USP
}
}
};
if (isSet(DNT)) {
requestData.device.dnt = DNT;
}
if (isSet(config.getConfig('coppa'))) {
requestData.regs.coppa = config.getConfig('coppa') === true ? 1 : 0;
}
if (isSet(GDPR)) {
requestData.regs.ext.gdpr = GDPR;
requestData.regs.ext.gdprs = GDPRS;
}
if (isSet(bid.params.aid) || isSet(bid.params.appname) || isSet(bid.params.bundleid)) {
requestData.app = {
id: bid.params.aid,
name: bid.params.appname,
bundle: bid.params.bundleid
};
if (bid.params.contentId) {
requestData.app.content = {
id: bid.params.contentId,
title: bid.params.contentTitle,
len: bid.params.contentLength,
url: bid.params.contentUrl
};
}
}
if (isSet(bid.params.idfa) || isSet(bid.params.aid)) {
requestData.device.ifa = bid.params.idfa || bid.params.aid;
}
if (bid.schain) {
requestData.source = {
ext: {
schain: bid.schain
}
};
} else if (bid.params.schain) {
const section = bid.params.schain.split('!');
const verComplete = section[0].split(',');
const node = section[1].split(',');
requestData.source = {
ext: {
schain: {
validation: 'strict',
config: {
ver: verComplete[0],
complete: parseInt(verComplete[1]),
nodes: [
{
asi: decodeURIComponent(node[0]),
sid: decodeURIComponent(node[1]),
hp: parseInt(node[2]),
rid: decodeURIComponent(node[3]),
name: decodeURIComponent(node[4]),
domain: decodeURIComponent(node[5])
}
]
}
}
}
};
}
_each(calculateSizes(VIDEO_BID, bid), (sizes) => {
const impObj = {
id: generateUUID(),
displaymanager: bid.bidder,
bidfloor: BID_FLOOR,
video: {
mimes: VIDEO_BID.mimes || MIMES_TYPES,
protocols: VIDEO_BID.protocols || PROTOCOLS,
nvol: bid.params.volume || PARAM_VOLUME_DEFAULT,
w: sizes[0],
h: sizes[1],
skip: VIDEO_BID.skip || 0,
playbackmethod: VIDEO_BID.playbackmethod || [1],
ext: {
lkqdcustomparameters: {}
},
},
bidfloorcur: 'USD',
secure: 1
};
for (let k = 1; k <= 40; k++) {
if (bid.params.hasOwnProperty(`c${k}`) && bid.params[`c${k}`]) {
impObj.video.ext.lkqdcustomparameters[`c${k}`] = bid.params[`c${k}`];
}
}
requestData.imp.push(impObj);
});
serverRequestObjects.push({
method: 'POST',
url: buildUrl({
protocol: 'https',
hostname: 'rtb.lkqd.net',
pathname: '/ad',
search: {
pid: bid.params.publisherId || bid.params.placementId,
sid: bid.params.siteId,
output: 'rtb',
prebid: true
}
}),
data: requestData
});
});
return serverRequestObjects;
},
interpretResponse: function(serverResponse, bidRequest) {
const serverBody = serverResponse.body;
const bidResponses = [];
if (serverBody && serverBody.seatbid) {
_each(serverBody.seatbid, (seatbid) => {
_each(seatbid.bid, (bid) => {
if (bid.price > 0) {
const bidResponse = {
requestId: bidRequest.id,
creativeId: bid.crid,
cpm: bid.price,
width: bid.w,
height: bid.h,
currency: serverBody.cur,
netRevenue: true,
ttl: BID_TTL_DEFAULT,
ad: bid.adm,
meta: {
advertiserDomains: bid.adomain && Array.isArray(bid.adomain) ? bid.adomain : [],
mediaType: VIDEO
}
};
bidResponses.push(bidResponse);
}
});
});
} else {
logError('Error: No server response or server response was empty for the requested URL');
}
return bidResponses;
}
}
registerBidder(spec);