forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqwarryBidAdapter.js
102 lines (84 loc) · 2.5 KB
/
qwarryBidAdapter.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
100
101
102
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { deepClone } from '../src/utils.js';
import { ajax } from '../src/ajax.js';
import { VIDEO } from '../src/mediaTypes.js';
const BIDDER_CODE = 'qwarry';
export const ENDPOINT = 'https://bidder.qwarry.co/bid/adtag?prebid=true'
export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: ['banner', 'video'],
isBidRequestValid: function (bid) {
return !!(bid.params && bid.params.zoneToken);
},
buildRequests: function (validBidRequests, bidderRequest) {
let bids = [];
validBidRequests.forEach(bidRequest => {
bids.push({
bidId: bidRequest.bidId,
zoneToken: bidRequest.params.zoneToken,
pos: bidRequest.params.pos,
sizes: prepareSizes(bidRequest.sizes)
})
})
let payload = {
requestId: bidderRequest.bidderRequestId,
bids,
referer: bidderRequest.refererInfo.page,
schain: validBidRequests[0].schain
}
if (bidderRequest && bidderRequest.gdprConsent) {
payload.gdprConsent = {
consentRequired: (typeof bidderRequest.gdprConsent.gdprApplies === 'boolean') ? bidderRequest.gdprConsent.gdprApplies : false,
consentString: bidderRequest.gdprConsent.consentString
}
}
const options = {
contentType: 'application/json',
customHeaders: {
'Rtb-Direct': true
}
}
return {
method: 'POST',
url: ENDPOINT,
data: payload,
options
};
},
interpretResponse: function (serverResponse, request) {
const serverBody = serverResponse.body;
if (!serverBody || typeof serverBody !== 'object') {
return [];
}
const { prebidResponse } = serverBody;
if (!prebidResponse || typeof prebidResponse !== 'object') {
return [];
}
let bids = [];
prebidResponse.forEach(bidResponse => {
let bid = deepClone(bidResponse);
bid.cpm = parseFloat(bidResponse.cpm);
// banner or video
if (VIDEO === bid.format) {
bid.vastXml = bid.ad;
}
bid.meta = {};
bid.meta.advertiserDomains = bid.adomain || [];
bids.push(bid);
})
return bids;
},
onBidWon: function (bid) {
if (bid.winUrl) {
const cpm = bid.cpm;
const winUrl = bid.winUrl.replace(/\$\{AUCTION_PRICE\}/, cpm);
ajax(winUrl, null);
return true;
}
return false;
}
}
function prepareSizes(sizes) {
return sizes && sizes.map(size => ({ width: size[0], height: size[1] }));
}
registerBidder(spec);