forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrainxBidAdapter.js
117 lines (109 loc) · 3.88 KB
/
brainxBidAdapter.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
114
115
116
117
import { deepAccess, generateUUID, isArray, logWarn } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
// import { config } from 'src/config.js';
import { BANNER } from '../src/mediaTypes.js';
import { ortbConverter } from '../libraries/ortbConverter/converter.js'
// import { config } from '../src/config.js';
const BIDDER_CODE = 'brainx';
const METHOD = 'POST';
const TTL = 200;
const NET_REV = true;
let ENDPOINT = 'https://dsp.brainx.tech/bid'
// let ENDPOINT = 'http://adx-engine-gray.tec-do.cn/bid'
const converter = ortbConverter({
context: {
// `netRevenue` and `ttl` are required properties of bid responses - provide a default for them
netRevenue: NET_REV, // or false if your adapter should set bidResponse.netRevenue = false
ttl: TTL // default bidResponse.ttl (when not specified in ORTB response.seatbid[].bid[].exp)
}
});
export const spec = {
code: BIDDER_CODE,
// gvlid: IAB_GVL_ID,
// aliases: [
// { code: "myalias", gvlid: IAB_GVL_ID_IF_DIFFERENT }
// ],
isBidRequestValid: function (bid) {
if (!(hasBanner(bid) || hasVideo(bid))) {
logWarn('Invalid bid request - missing required mediaTypes');
return false;
}
if (!(bid && bid.params)) {
logWarn('Invalid bid request - missing required bid data');
return false;
}
if (!(bid.params.pubId)) {
logWarn('Invalid bid request - missing required field pubId');
return false;
}
return true;
},
buildRequests(bidRequests, bidderRequest) {
const data = converter.toORTB({ bidRequests, bidderRequest })
ENDPOINT = String(deepAccess(bidRequests[0], 'params.endpoint')) ? deepAccess(bidRequests[0], 'params.endpoint') : ENDPOINT
data.user = {
buyeruid: generateUUID()
}
return {
method: METHOD,
url: `${ENDPOINT}?token=${String(deepAccess(bidRequests[0], 'params.pubId'))}`,
data
}
},
interpretResponse(response, request) {
let bids = [];
if (response.body && response.body.seatbid && isArray(response.body.seatbid)) {
response.body.seatbid.forEach(function (bidder) {
if (isArray(bidder.bid)) {
bidder.bid.map((bid) => {
let serverBody = response.body;
// bidRequest = request.originalBidRequest,
let mediaType = BANNER;
let currency = serverBody.cur || 'USD'
const cpm = (parseFloat(bid.price) || 0).toFixed(2);
const categories = deepAccess(bid, 'cat', []);
const bidRes = {
ad: bid.adm,
width: bid.w,
height: bid.h,
requestId: bid.impid,
cpm: cpm,
currency: currency,
mediaType: mediaType,
ttl: TTL,
creativeId: bid.crid || bid.id,
netRevenue: NET_REV,
nurl: bid.nurl,
lurl: bid.lurl,
meta: {
mediaType: mediaType,
primaryCatId: categories[0],
secondaryCatIds: categories.slice(1),
}
};
if (bid.adomain && isArray(bid.adomain) && bid.adomain.length > 0) {
bidRes.meta.advertiserDomains = bid.adomain;
bidRes.meta.clickUrl = bid.adomain[0];
}
bids.push(bidRes);
})
}
});
}
return bids;
},
// getUserSyncs: function (syncOptions, serverResponses, gdprConsent, uspConsent) { },
// onTimeout: function (timeoutData) { },
// onBidWon: function (bid) { },
// onSetTargeting: function (bid) { },
// onBidderError: function ({ error, bidderRequest }) { },
// onAdRenderSucceeded: function (bid) { },
supportedMediaTypes: [BANNER]
}
function hasBanner(bidRequest) {
return !!deepAccess(bidRequest, 'mediaTypes.banner');
}
function hasVideo(bidRequest) {
return !!deepAccess(bidRequest, 'mediaTypes.video');
}
registerBidder(spec);