forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadponeBidAdapter.js
96 lines (80 loc) · 2.51 KB
/
adponeBidAdapter.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
import {BANNER} from '../src/mediaTypes.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {triggerPixel} from '../src/utils.js';
const ADPONE_CODE = 'adpone';
const ADPONE_ENDPOINT = 'https://rtb.adpone.com/bid-request';
const ADPONE_REQUEST_METHOD = 'POST';
const ADPONE_CURRENCY = 'EUR';
export const spec = {
code: ADPONE_CODE,
supportedMediaTypes: [BANNER],
isBidRequestValid: bid => {
return !!bid.params.placementId && !!bid.bidId && bid.bidder === 'adpone'
},
buildRequests: (bidRequests, bidderRequest) => {
return bidRequests.map(bid => {
let url = ADPONE_ENDPOINT + '?pid=' + bid.params.placementId;
const data = {
at: 1,
id: bid.bidId,
imp: bid.sizes.map((size, index) => (
{
id: bid.bidId + '_' + index,
banner: {
w: size[0],
h: size[1]
}
}))
};
const options = {
withCredentials: true
};
if (bidderRequest && bidderRequest.gdprConsent) {
url += '&gdpr_applies=' + bidderRequest.gdprConsent.gdprApplies;
url += '&consentString=' + bidderRequest.gdprConsent.consentString;
}
return {
method: ADPONE_REQUEST_METHOD,
url,
data,
options,
};
});
},
interpretResponse: (serverResponse, bidRequest) => {
if (!serverResponse || !serverResponse.body) {
return [];
}
let answer = [];
serverResponse.body.seatbid.forEach(seatbid => {
if (seatbid.bid.length) {
answer = [...answer, ...seatbid.bid.filter(bid => bid.price > 0).map(adponeBid => {
const bid = {
id: adponeBid.id,
requestId: bidRequest.data.id,
cpm: adponeBid.price,
ad: adponeBid.adm,
width: adponeBid.w || 0,
height: adponeBid.h || 0,
currency: serverResponse.body.cur || ADPONE_CURRENCY,
netRevenue: true,
ttl: 300,
creativeId: adponeBid.crid || 0
};
if (adponeBid.meta && adponeBid.meta.adomain && adponeBid.meta.adomain.length > 0) {
bid.meta = {};
bid.meta.advertiserDomains = adponeBid.meta.adomain;
}
return bid
})];
}
});
return answer;
},
onBidWon: bid => {
const bidString = JSON.stringify(bid);
const encodedBuf = window.btoa(bidString);
triggerPixel(`https://rtb.adpone.com/prebid/analytics?q=${encodedBuf}`);
},
};
registerBidder(spec);