-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
a1MediaBidAdapter.js
89 lines (79 loc) · 2.41 KB
/
a1MediaBidAdapter.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
import { ortbConverter } from '../libraries/ortbConverter/converter.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, VIDEO, NATIVE } from '../src/mediaTypes.js';
const BIDDER_CODE = 'a1media';
const END_POINT = 'https://d11.contentsfeed.com/dsp/breq/a1';
const DEFAULT_CURRENCY = 'JPY';
const converter = ortbConverter({
context: {
netRevenue: true,
ttl: 30,
},
imp(buildImp, bidRequest, context) {
const imp = buildImp(bidRequest, context);
if (!imp.bidfloor) {
imp.bidfloor = bidRequest.params.bidfloor || 0;
imp.bidfloorcur = bidRequest.params.currency || DEFAULT_CURRENCY;
}
if (bidRequest.params.battr) {
Object.keys(bidRequest.mediaTypes).forEach(mType => {
imp[mType].battr = bidRequest.params.battr;
})
}
return imp;
},
request(buildRequest, imps, bidderRequest, context) {
const request = buildRequest(imps, bidderRequest, context);
const bid = context.bidRequests[0];
if (!request.cur) {
request.cur = [bid.params.currency || DEFAULT_CURRENCY];
}
if (bid.params.bcat) {
request.bcat = bid.params.bcat;
}
return request;
},
bidResponse(buildBidResponse, bid, context) {
const { bidRequest } = context;
let resMediaType;
const reqMediaTypes = Object.keys(bidRequest.mediaTypes);
if (reqMediaTypes.length === 1) {
resMediaType = reqMediaTypes[0];
} else {
if (bid.adm.search(/^(<\?xml|<vast)/i) !== -1) {
resMediaType = VIDEO;
} else if (bid.adm[0] === '{') {
resMediaType = NATIVE;
} else {
resMediaType = BANNER;
}
}
context.mediaType = resMediaType;
context.cpm = bid.price;
const bidResponse = buildBidResponse(bid, context);
return bidResponse;
}
});
export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER, VIDEO, NATIVE],
isBidRequestValid: function (bid) {
return true;
},
buildRequests: function (validBidRequests, bidderRequest) {
const data = converter.toORTB({ validBidRequests, bidderRequest });
return {
method: 'POST',
url: END_POINT,
data: data,
options: {
withCredentials: false,
}
};
},
interpretResponse: function (serverResponse, bidRequest) {
const bids = converter.fromORTB({response: serverResponse.body, request: bidRequest.data}).bids;
return bids;
},
};
registerBidder(spec);