forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbucksenseBidAdapter.js
134 lines (122 loc) · 4.16 KB
/
bucksenseBidAdapter.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
import { logInfo } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER } from '../src/mediaTypes.js';
/**
* @typedef {import('../src/adapters/bidderFactory.js').BidRequest} BidRequest
* @typedef {import('../src/adapters/bidderFactory.js').Bid} Bid
*/
const WHO = 'BKSHBID-005';
const BIDDER_CODE = 'bucksense';
const URL = 'https://directo.prebidserving.com/prebidjs/';
export const spec = {
code: BIDDER_CODE,
gvlid: 235,
supportedMediaTypes: [BANNER],
/**
* Determines whether or not the given bid request is valid.
*
* @param {object} bid The bid to validate.
* @return boolean True if this is a valid bid, and false otherwise.
*/
isBidRequestValid: function (bid) {
logInfo(WHO + ' isBidRequestValid() - INPUT bid:', bid);
if (bid.bidder !== BIDDER_CODE || typeof bid.params === 'undefined') {
return false;
}
if (typeof bid.params.placementId === 'undefined') {
return false;
}
return true;
},
/**
* Make a server request from the list of BidRequests.
*
* @param {BidRequest[]} validBidRequests A non-empty list of valid bid requests that should be sent to the Server.
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: function (validBidRequests, bidderRequest) {
logInfo(WHO + ' buildRequests() - INPUT validBidRequests:', validBidRequests, 'INPUT bidderRequest:', bidderRequest);
let requests = [];
const len = validBidRequests.length;
for (let i = 0; i < len; i++) {
var bid = validBidRequests[i];
var params = {};
for (var key in bid.params) {
if (bid.params.hasOwnProperty(key)) {
params[key] = encodeURI(bid.params[key]);
}
}
delete bid.params;
var sizes = bid.sizes;
delete bid.sizes;
var sendData = {
'pub_id': location.host,
'pl_id': '' + params.placementId,
'secure': (location.protocol === 'https:') ? 1 : 0,
'href': encodeURI(location.href),
'bid_id': bid.bidId,
'params': params,
'sizes': sizes,
'_bid': bidderRequest
};
requests.push({
method: 'POST',
url: URL,
data: sendData
});
}
logInfo(WHO + ' buildRequests() - requests:', requests);
return requests;
},
/**
* Unpack the response from the server into a list of bids.
*
* @param {*} serverResponse A successful response from the server.
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: function (serverResponse, request) {
logInfo(WHO + ' interpretResponse() - INPUT serverResponse:', serverResponse, 'INPUT request:', request);
const bidResponses = [];
if (serverResponse.body) {
var oResponse = serverResponse.body;
var sRequestID = oResponse.requestId || '';
var nCPM = oResponse.cpm || 0;
var nWidth = oResponse.width || 0;
var nHeight = oResponse.height || 0;
var nTTL = oResponse.ttl || 0;
var sCreativeID = oResponse.creativeId || 0;
var sCurrency = oResponse.currency || 'USD';
var bNetRevenue = oResponse.netRevenue || true;
var sAd = oResponse.ad || '';
var sAdomains = oResponse.adomains || [];
if (request && sRequestID.length == 0) {
logInfo(WHO + ' interpretResponse() - use RequestID from Placments');
sRequestID = request.data.bid_id || '';
}
if (request && request.data.params.hasOwnProperty('testcpm')) {
logInfo(WHO + ' interpretResponse() - use Test CPM ');
nCPM = request.data.params.testcpm;
}
let bidResponse = {
requestId: sRequestID,
cpm: nCPM,
width: nWidth,
height: nHeight,
ttl: nTTL,
creativeId: sCreativeID,
currency: sCurrency,
netRevenue: bNetRevenue,
ad: sAd,
meta: {
advertiserDomains: sAdomains
}
};
bidResponses.push(bidResponse);
} else {
logInfo(WHO + ' interpretResponse() - serverResponse not valid');
}
logInfo(WHO + ' interpretResponse() - return', bidResponses);
return bidResponses;
},
};
registerBidder(spec);