forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathownadxBidAdapter.js
99 lines (89 loc) · 2.83 KB
/
ownadxBidAdapter.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, isEmpty } 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
* @typedef {import('../src/adapters/bidderFactory.js').ServerResponse} ServerResponse
*/
const BIDDER_CODE = 'ownadx';
const CUR = 'USD';
const CREATIVE_TTL = 300;
export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER],
/**
* 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.tokenId && bid.params.sspId && bid.params.seatId);
},
/**
* Make a server request from the list of BidRequests.
*
* @param validBidRequests
* @param bidderRequest
* @return Array Info describing the request to the server.
*/
buildRequests: function (validBidRequests, bidderRequest) {
return validBidRequests.map(bidRequest => {
const sizes = parseSizesInput(bidRequest.params.size || bidRequest.sizes);
let mtype = 0;
if (bidRequest.mediaTypes[BANNER]) {
mtype = 1;
} else {
mtype = 2;
}
let tkn = bidRequest.params.tokenId;
let seatid = bidRequest.params.seatId;
let sspid = bidRequest.params.sspId;
const payload = {
sizes: sizes,
slotBidId: bidRequest.bidId,
PageUrl: bidderRequest.refererInfo.page,
mediaChannel: mtype
};
return {
method: 'POST',
url: `https://pbs-js.prebid-ownadx.com/publisher/prebid/${seatid}/${sspid}?token=${tkn}`,
data: payload
};
});
},
/**
* Unpack the response from the server into a list of bids.
*
* @param {ServerResponse} serverResponse A successful response from the server.
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: function (serverResponse) {
const response = serverResponse.body;
const bids = [];
if (isEmpty(response)) {
return bids;
}
const responseBid = {
width: response.width,
height: response.height,
token: response.tokenId,
ttl: CREATIVE_TTL,
requestId: response.slotBidId,
aType: response.adType || '1',
cpm: response.cpm,
creativeId: response.creativeId || 0,
netRevenue: response.netRevenue || false,
currency: response.currency || CUR,
meta: {
mediaType: response.mediaType || BANNER,
advertiserDomains: response.advertiserDomains || []
},
ad: response.adm
};
bids.push(responseBid);
return bids;
}
};
registerBidder(spec);