forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
eclickadsBidAdapter.js
80 lines (75 loc) · 2.4 KB
/
eclickadsBidAdapter.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
import { NATIVE } from '../src/mediaTypes.js';
import { convertOrtbRequestToProprietaryNative } from '../src/native.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { getDevice } from '../libraries/fpdUtils/deviceInfo.js';
// ***** ECLICKADS ADAPTER *****
export const BIDDER_CODE = 'eclickads';
const DEFAULT_CURRENCY = ['USD'];
const DEFAULT_TTL = 1000;
export const ENDPOINT = 'https://g.eclick.vn/rtb_hb_request?fosp_uid=';
export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [NATIVE],
isBidRequestValid: (bid) => {
return !!bid && !!bid.params && !!bid.bidder && !!bid.params.zid;
},
buildRequests: (validBidRequests = [], bidderRequest) => {
validBidRequests = convertOrtbRequestToProprietaryNative(validBidRequests);
const ortb2ConfigFPD = bidderRequest.ortb2.site.ext?.data || {};
const ortb2Device = bidderRequest.ortb2.device;
const ortb2Site = bidderRequest.ortb2.site;
const isMobile = getDevice();
const imp = [];
const fENDPOINT = ENDPOINT + (ortb2ConfigFPD.fosp_uid || '');
const request = {
deviceWidth: ortb2Device.w,
deviceHeight: ortb2Device.h,
ua: ortb2Device.ua,
language: ortb2Device.language,
device: isMobile ? 'mobile' : 'desktop',
host: ortb2Site.domain,
page: ortb2Site.page,
imp,
myvne_id: ortb2ConfigFPD.myvne_id || '',
orig_aid: ortb2ConfigFPD.orig_aid,
fosp_aid: ortb2ConfigFPD.fosp_aid,
fosp_uid: ortb2ConfigFPD.fosp_uid,
id: ortb2ConfigFPD.id,
};
validBidRequests.map((bid) => {
imp.push({
requestId: bid.bidId,
adUnitCode: bid.adUnitCode,
zid: bid.params.zid,
});
});
return {
method: 'POST',
url: fENDPOINT,
data: request,
};
},
interpretResponse: (serverResponse) => {
const seatbid = serverResponse.body?.seatbid || [];
return seatbid.reduce((bids, bid) => {
return [
...bids,
{
id: bid.id,
impid: bid.impid,
adUnitCode: bid.adUnitCode,
cpm: bid.cpm,
ttl: bid.ttl || DEFAULT_TTL,
requestId: bid.requestId,
creativeId: bid.creativeId,
netRevenue: bid.netRevenue,
currency: bid.currency || DEFAULT_CURRENCY,
adserverTargeting: {
hb_ad_eclickads: bid.ad,
},
},
];
}, []);
},
};
registerBidder(spec);