forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadbutlerBidAdapter.js
113 lines (89 loc) · 2.85 KB
/
adbutlerBidAdapter.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
103
104
105
106
107
108
109
110
111
112
113
import * as utils from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER } from '../src/mediaTypes.js';
const BIDDER_CODE = 'adbutler';
function getTrackingPixelsMarkup(pixelURLs) {
return pixelURLs
.map(pixelURL => `<img height="0" width="0" border="0" style="display:none;" src="${pixelURL}"/>`)
.join();
}
export const spec = {
code: BIDDER_CODE,
pageID: Math.floor(Math.random() * 10e6),
aliases: ['divreach', 'doceree'],
supportedMediaTypes: [BANNER],
isBidRequestValid(bid) {
return !!(bid.params.accountID && bid.params.zoneID);
},
buildRequests(validBidRequests) {
const zoneCounters = {};
return utils._map(validBidRequests, function (bidRequest) {
const zoneID = bidRequest.params?.zoneID;
zoneCounters[zoneID] ??= 0;
const domain = bidRequest.params?.domain ?? 'servedbyadbutler.com';
const adserveBase = `https://${domain}/adserve`;
const params = {
...(bidRequest.params?.extra ?? {}),
ID: bidRequest.params?.accountID,
type: 'hbr',
setID: zoneID,
pid: spec.pageID,
place: zoneCounters[zoneID],
kw: bidRequest.params?.keyword,
};
const paramsString = Object.entries(params).map(([key, value]) => `${key}=${value}`).join(';');
const requestURI = `${adserveBase}/;${paramsString};`;
zoneCounters[zoneID]++;
return {
method: 'GET',
url: requestURI,
data: {},
bidRequest,
};
});
},
interpretResponse(serverResponse, serverRequest) {
const bidObj = serverRequest.bidRequest;
const response = serverResponse.body ?? {};
if (!bidObj || response.status !== 'SUCCESS') {
return [];
}
const width = parseInt(response.width);
const height = parseInt(response.height);
const sizeValid = (bidObj.mediaTypes?.banner?.sizes ?? []).some(([w, h]) => w === width && h === height);
if (!sizeValid) {
return [];
}
const cpm = response.cpm;
const minCPM = bidObj.params?.minCPM ?? null;
const maxCPM = bidObj.params?.maxCPM ?? null;
if (minCPM !== null && cpm < minCPM) {
return [];
}
if (maxCPM !== null && cpm > maxCPM) {
return [];
}
let advertiserDomains = [];
if (response.advertiser?.domain) {
advertiserDomains.push(response.advertiser.domain);
}
const bidResponse = {
requestId: bidObj.bidId,
cpm,
currency: 'USD',
width,
height,
ad: response.ad_code + getTrackingPixelsMarkup(response.tracking_pixels),
ttl: 360,
creativeId: response.placement_id,
netRevenue: true,
meta: {
advertiserId: response.advertiser?.id,
advertiserName: response.advertiser?.name,
advertiserDomains,
},
};
return [bidResponse];
},
};
registerBidder(spec);