-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
coinzillaBidAdapter.js
99 lines (93 loc) · 3.11 KB
/
coinzillaBidAdapter.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
import { parseSizesInput } from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
/**
* @typedef {import('../src/adapters/bidderFactory.js').BidRequest} BidRequest
* @typedef {import('../src/adapters/bidderFactory.js').Bid} Bid
* @typedef {import('../src/adapters/bidderFactory.js').ServerResponse} ServerResponse
*/
const BIDDER_CODE = 'coinzilla';
const ENDPOINT_URL = 'https://request.czilladx.com/serve/request.php';
export const spec = {
code: BIDDER_CODE,
aliases: ['czlla'], // short code
/**
* Determines whether or not the given bid request is valid.
*
* @param {BidRequest} bid The bid params to validate.
* @return boolean True if this is a valid bid, and false otherwise.
*/
isBidRequestValid: function (bid) {
return !!(bid.params.placementId);
},
/**
* Make a server request from the list of BidRequests.
*
* @return Array Info describing the request to the server.
* @param validBidRequests
* @param bidderRequest
*/
buildRequests: function (validBidRequests, bidderRequest) {
if (validBidRequests.length === 0) {
return [];
}
return validBidRequests.map(bidRequest => {
const sizes = parseSizesInput(bidRequest.params.size || bidRequest.sizes)[0];
const width = sizes.split('x')[0];
const height = sizes.split('x')[1];
const payload = {
placementId: bidRequest.params.placementId,
width: width,
height: height,
bidId: bidRequest.bidId,
// TODO: is 'page' the right value here?
referer: bidderRequest.refererInfo.page,
};
return {
method: 'POST',
url: ENDPOINT_URL,
data: payload
};
});
},
/**
* Unpack the response from the server into a list of bids.
*
* @param {ServerResponse} serverResponse A successful response from the server.
* @param bidRequest
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: function (serverResponse, bidRequest) {
const bidResponses = [];
const response = serverResponse.body;
const creativeId = response.creativeId || 0;
const width = response.width || 0;
const height = response.height || 0;
const cpm = response.cpm || 0;
if (width !== 0 && height !== 0 && cpm !== 0 && creativeId !== 0) {
const dealId = response.dealid || '';
const currency = response.currency || 'EUR';
const netRevenue = (response.netRevenue === undefined) ? true : response.netRevenue;
const referrer = bidRequest.data.referer;
const bidResponse = {
requestId: response.requestId,
cpm: cpm,
width: response.width,
height: response.height,
creativeId: creativeId,
dealId: dealId,
currency: currency,
netRevenue: netRevenue,
ttl: response.timeout,
referrer: referrer,
ad: response.ad,
mediaType: response.mediaType,
meta: {
advertiserDomains: response.advertiserDomain || []
}
};
bidResponses.push(bidResponse);
}
return bidResponses;
},
};
registerBidder(spec);