-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
oneplanetonlyBidAdapter.js
76 lines (67 loc) · 1.87 KB
/
oneplanetonlyBidAdapter.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
import * as utils from '../src/utils';
import { registerBidder } from '../src/adapters/bidderFactory';
import { config } from '../src/config';
const BIDDER_CODE = 'oneplanetonly';
const EDNPOINT = '//show.oneplanetonly.com/prebid';
function createEndpoint(siteId) {
return `${EDNPOINT}?siteId=${siteId}`;
}
function isBidRequestValid (bid) {
return !!(bid.params.siteId && bid.params.adUnitId);
}
function buildRequests(bidReqs) {
let firstBid = bidReqs[0] || {}
let siteId = utils.getBidIdParameter('siteId', firstBid.params)
let adUnits = bidReqs.map((bid) => {
return {
id: utils.getBidIdParameter('adUnitId', bid.params),
bidId: bid.bidId,
sizes: utils.parseSizesInput(bid.sizes),
};
});
const bidRequest = {
id: firstBid.auctionId,
ver: 1,
prebidVer: `$prebid.version$`,
transactionId: firstBid.transactionId,
currency: config.getConfig('currency.adServerCurrency'),
timeout: config.getConfig('bidderTimeout'),
siteId,
domain: utils.getTopWindowLocation().hostname,
page: config.getConfig('pageUrl') || utils.getTopWindowUrl(),
referrer: utils.getTopWindowReferrer(),
adUnits,
};
return {
method: 'POST',
url: createEndpoint(siteId),
data: bidRequest,
options: {contentType: 'application/json', withCredentials: true}
};
}
function interpretResponse(serverResponse, request) {
if (!serverResponse.body.bids) {
return [];
}
return serverResponse.body.bids.map((bid) => {
return {
requestId: bid.requestId,
cpm: bid.cpm,
width: bid.width,
height: bid.height,
creativeId: bid.creativeId,
currency: bid.currency,
netRevenue: true,
ad: bid.ad,
ttl: bid.ttl
};
});
}
export const spec = {
code: BIDDER_CODE,
aliases: ['opo'], // short code
isBidRequestValid,
buildRequests,
interpretResponse
}
registerBidder(spec);