-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathbeopBidAdapter.js
142 lines (134 loc) · 4.91 KB
/
beopBidAdapter.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
import { deepAccess, isArray, logWarn, triggerPixel, buildUrl, logInfo, getValue, getBidIdParameter } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { config } from '../src/config.js';
const BIDDER_CODE = 'beop';
const ENDPOINT_URL = 'https://hb.beop.io/bid';
const TCF_VENDOR_ID = 666;
const validIdRegExp = /^[0-9a-fA-F]{24}$/
export const spec = {
code: BIDDER_CODE,
gvlid: TCF_VENDOR_ID,
aliases: ['bp'],
/**
* Test if the bid request is valid.
*
* @param {bid} : The Bid params
* @return boolean true if the bid request is valid (aka contains a valid accountId or networkId and is open for BANNER), false otherwise.
*/
isBidRequestValid: function(bid) {
const id = bid.params.accountId || bid.params.networkId;
if (id === null || typeof id === 'undefined') {
return false
}
if (!validIdRegExp.test(id)) {
return false
}
return bid.mediaTypes.banner !== null && typeof bid.mediaTypes.banner !== 'undefined';
},
/**
* Create a BeOp server request from a list of BidRequest
*
* @param {validBidRequests[], ...} : The array of validated bidRequests
* @param {... , bidderRequest} : Common params for each bidRequests
* @return ServerRequest Info describing the request to the BeOp's server
*/
buildRequests: function(validBidRequests, bidderRequest) {
const slots = validBidRequests.map(beOpRequestSlotsMaker);
let pageUrl = deepAccess(bidderRequest, 'refererInfo.canonicalUrl') || config.getConfig('pageUrl') || deepAccess(window, 'location.href');
let fpd = config.getLegacyFpd(config.getConfig('ortb2'));
let gdpr = bidderRequest.gdprConsent;
let firstSlot = slots[0];
let payloadObject = {
at: new Date().toString(),
nid: firstSlot.nid,
nptnid: firstSlot.nptnid,
pid: firstSlot.pid,
url: pageUrl,
lang: (window.navigator.language || window.navigator.languages[0]),
kwds: (fpd && fpd.site && fpd.site.keywords) || [],
dbg: false,
slts: slots,
is_amp: deepAccess(bidderRequest, 'referrerInfo.isAmp'),
tc_string: (gdpr && gdpr.gdprApplies) ? gdpr.consentString : null,
};
const payloadString = JSON.stringify(payloadObject);
return {
method: 'POST',
url: ENDPOINT_URL,
data: payloadString
}
},
interpretResponse: function(serverResponse, request) {
if (serverResponse && serverResponse.body && isArray(serverResponse.body.bids) && serverResponse.body.bids.length > 0) {
return serverResponse.body.bids;
}
return [];
},
onTimeout: function(timeoutData) {
if (timeoutData === null || typeof timeoutData === 'undefined' || Object.keys(timeoutData).length === 0) {
return;
}
let trackingParams = buildTrackingParams(timeoutData, 'timeout', timeoutData.timeout);
logWarn(BIDDER_CODE + ': timed out request');
triggerPixel(buildUrl({
protocol: 'https',
hostname: 't.beop.io',
pathname: '/bid',
search: trackingParams
}));
},
onBidWon: function(bid) {
if (bid === null || typeof bid === 'undefined' || Object.keys(bid).length === 0) {
return;
}
let trackingParams = buildTrackingParams(bid, 'won', bid.cpm);
logInfo(BIDDER_CODE + ': won request');
triggerPixel(buildUrl({
protocol: 'https',
hostname: 't.beop.io',
pathname: '/bid',
search: trackingParams
}));
},
onSetTargeting: function(bid) {}
}
function buildTrackingParams(data, info, value) {
return {
pid: data.params.accountId,
nid: data.params.networkId,
nptnid: data.params.networkPartnerId,
bid: data.bidId,
sl_n: data.adUnitCode,
aid: data.auctionId,
se_ca: 'bid',
se_ac: info,
se_va: value
};
}
function beOpRequestSlotsMaker(bid) {
const bannerSizes = deepAccess(bid, 'mediaTypes.banner.sizes');
const publisherCurrency = config.getConfig('currency.adServerCurrency') || getValue(bid.params, 'currency') || 'EUR';
let floor;
if (typeof bid.getFloor === 'function') {
const floorInfo = bid.getFloor({currency: publisherCurrency, mediaType: 'banner', size: [1, 1]});
if (typeof floorInfo === 'object' && floorInfo.currency === publisherCurrency && !isNaN(parseFloat(floorInfo.floor))) {
floor = parseFloat(floorInfo.floor);
}
}
return {
sizes: isArray(bannerSizes) ? bannerSizes : bid.sizes,
flr: floor,
pid: getValue(bid.params, 'accountId'),
nid: getValue(bid.params, 'networkId'),
nptnid: getValue(bid.params, 'networkPartnerId'),
bid: getBidIdParameter('bidId', bid),
brid: getBidIdParameter('bidderRequestId', bid),
name: getBidIdParameter('adUnitCode', bid),
aid: getBidIdParameter('auctionId', bid),
tid: getBidIdParameter('transactionId', bid),
brc: getBidIdParameter('bidRequestsCount', bid),
bdrc: getBidIdParameter('bidderRequestCount', bid),
bwc: getBidIdParameter('bidderWinsCount', bid),
}
}
registerBidder(spec);