forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmixerBidAdapter.js
74 lines (73 loc) · 2.2 KB
/
admixerBidAdapter.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
import * as utils from 'src/utils';
import {registerBidder} from 'src/adapters/bidderFactory';
const BIDDER_CODE = 'admixer';
const ENDPOINT_URL = '//inv-nets.admixer.net/prebid.1.0.aspx';
export const spec = {
code: BIDDER_CODE,
aliases: [],
supportedMediaTypes: ['banner', 'video'],
/**
* 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.zone;
},
/**
* Make a server request from the list of BidRequests.
*
* @param {bidderRequest} - bidderRequest.bids[] is an array of AdUnits and bids
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: function (bidderRequest) {
const payload = {
imps: [],
referrer: encodeURIComponent(utils.getTopWindowUrl()),
};
bidderRequest.forEach((bid) => {
if (bid.bidder === BIDDER_CODE) {
payload.imps.push(bid);
}
});
const payloadString = JSON.stringify(payload);
return {
method: 'GET',
url: ENDPOINT_URL,
data: `data=${payloadString}`,
};
},
/**
* 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, bidRequest) {
const bidResponses = [];
// loop through serverResponses {
try {
serverResponse = serverResponse.body;
serverResponse.forEach((bidResponse) => {
const bidResp = {
requestId: bidResponse.bidId,
cpm: bidResponse.cpm,
width: bidResponse.width,
height: bidResponse.height,
ad: bidResponse.ad,
ttl: bidResponse.ttl,
creativeId: bidResponse.creativeId,
netRevenue: bidResponse.netRevenue,
currency: bidResponse.currency,
vastUrl: bidResponse.vastUrl,
};
bidResponses.push(bidResp);
});
} catch (e) {
utils.logError(e);
}
return bidResponses;
}
};
registerBidder(spec);