forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkubientBidAdapter.js
177 lines (160 loc) · 5.68 KB
/
kubientBidAdapter.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
import { isArray, deepAccess, isPlainObject } from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER, VIDEO} from '../src/mediaTypes.js';
import { config } from '../src/config.js';
const BIDDER_CODE = 'kubient';
const END_POINT = 'https://kssp.kbntx.ch/kubprebidjs';
const VERSION = '1.1';
const VENDOR_ID = 794;
export const spec = {
code: BIDDER_CODE,
gvlid: VENDOR_ID,
supportedMediaTypes: [ BANNER, VIDEO ],
isBidRequestValid: function (bid) {
return !!(
bid &&
bid.params &&
bid.params.zoneid &&
((!bid.mediaTypes.video) || (bid.mediaTypes.video && bid.mediaTypes.video.playerSize && bid.mediaTypes.video.mimes && bid.mediaTypes.video.protocols))
);
},
buildRequests: function (validBidRequests, bidderRequest) {
if (!validBidRequests || !bidderRequest) {
return;
}
return validBidRequests.map(function (bid) {
let adSlot = {
bidId: bid.bidId,
zoneId: bid.params.zoneid || ''
};
if (typeof bid.getFloor === 'function') {
const mediaType = (Object.keys(bid.mediaTypes).length == 1) ? Object.keys(bid.mediaTypes)[0] : '*';
const sizes = bid.sizes || '*';
const floorInfo = bid.getFloor({currency: 'USD', mediaType: mediaType, size: sizes});
if (isPlainObject(floorInfo) && floorInfo.currency === 'USD') {
let floor = parseFloat(floorInfo.floor)
if (!isNaN(floor) && floor > 0) {
adSlot.floor = parseFloat(floorInfo.floor);
}
}
}
if (bid.mediaTypes.banner) {
adSlot.banner = bid.mediaTypes.banner;
}
if (bid.mediaTypes.video) {
adSlot.video = bid.mediaTypes.video;
}
if (bid.schain) {
adSlot.schain = bid.schain;
}
let data = {
v: VERSION,
requestId: bid.bidderRequestId,
adSlots: [adSlot],
tmax: bidderRequest.timeout,
gdpr: (bidderRequest.gdprConsent && bidderRequest.gdprConsent.gdprApplies) ? 1 : 0,
consentGiven: kubientGetConsentGiven(bidderRequest.gdprConsent),
uspConsent: bidderRequest.uspConsent
}
if (config.getConfig('coppa') === true) {
data.coppa = 1
}
if (bidderRequest?.refererInfo?.page) {
// TODO: is 'page' the right value here?
data.referer = bidderRequest.refererInfo.page
}
if (bidderRequest.gdprConsent && bidderRequest.gdprConsent.consentString) {
data.consent = bidderRequest.gdprConsent.consentString
}
return {
method: 'POST',
url: END_POINT,
data: JSON.stringify(data)
};
});
},
interpretResponse: function interpretResponse(serverResponse, request) {
if (!serverResponse || !serverResponse.body || !serverResponse.body.seatbid) {
return [];
}
let bidResponses = [];
serverResponse.body.seatbid.forEach(seatbid => {
let bids = seatbid.bid || [];
bids.forEach(bid => {
const bidResponse = {
requestId: bid.bidId,
cpm: bid.price,
currency: bid.cur,
width: bid.w,
height: bid.h,
creativeId: bid.creativeId,
netRevenue: bid.netRevenue,
ttl: bid.ttl,
ad: bid.adm,
meta: {}
};
if (bid.meta && bid.meta.adomain && isArray(bid.meta.adomain)) {
bidResponse.meta.advertiserDomains = bid.meta.adomain;
}
if (bid.mediaType === VIDEO) {
bidResponse.mediaType = VIDEO;
bidResponse.vastXml = bid.adm;
}
bidResponses.push(bidResponse);
});
});
return bidResponses;
},
getUserSyncs: function (syncOptions, serverResponses, gdprConsent, uspConsent) {
let kubientSync = kubientGetSyncInclude(config);
if (!syncOptions.pixelEnabled || kubientSync.image === 'exclude') {
return [];
}
let values = {};
if (gdprConsent) {
if (typeof gdprConsent.gdprApplies === 'boolean') {
values['gdpr'] = Number(gdprConsent.gdprApplies);
}
if (typeof gdprConsent.consentString === 'string') {
values['consent'] = gdprConsent.consentString;
}
}
if (uspConsent) {
values['usp'] = uspConsent;
}
return [{
type: 'image',
url: 'https://matching.kubient.net/match/sp?' + encodeQueryData(values)
}];
}
};
function encodeQueryData(data) {
return Object.keys(data).map(function(key) {
return [key, data[key]].map(encodeURIComponent).join('=');
}).join('&');
}
function kubientGetConsentGiven(gdprConsent) {
let consentGiven = 0;
if (typeof gdprConsent !== 'undefined') {
consentGiven = deepAccess(gdprConsent, `vendorData.vendor.consents.${VENDOR_ID}`) ? 1 : 0;
}
return consentGiven;
}
function kubientGetSyncInclude(config) {
try {
let kubientSync = {};
if (config.getConfig('userSync').filterSettings != null && typeof config.getConfig('userSync').filterSettings != 'undefined') {
let filterSettings = config.getConfig('userSync').filterSettings
if (filterSettings.iframe !== null && typeof filterSettings.iframe !== 'undefined') {
kubientSync.iframe = ((isArray(filterSettings.image.bidders) && filterSettings.iframe.bidders.indexOf('kubient') !== -1) || filterSettings.iframe.bidders === '*') ? filterSettings.iframe.filter : 'exclude';
}
if (filterSettings.image !== null && typeof filterSettings.image !== 'undefined') {
kubientSync.image = ((isArray(filterSettings.image.bidders) && filterSettings.image.bidders.indexOf('kubient') !== -1) || filterSettings.image.bidders === '*') ? filterSettings.image.filter : 'exclude';
}
}
return kubientSync;
} catch (e) {
return null;
}
}
registerBidder(spec);