forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfluctBidAdapter.js
181 lines (163 loc) · 5.33 KB
/
fluctBidAdapter.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import { _each, deepSetValue, isEmpty } from '../src/utils.js';
import { config } from '../src/config.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
/**
* @typedef {import('../src/adapters/bidderFactory.js').BidRequest} BidRequest
* @typedef {import('../src/adapters/bidderFactory.js').BidderRequest} BidderRequest
* @typedef {import('../src/adapters/bidderFactory.js').validBidRequests} validBidRequests
*/
const BIDDER_CODE = 'fluct';
const END_POINT = 'https://hb.adingo.jp/prebid';
const VERSION = '1.2';
const NET_REVENUE = true;
const TTL = 300;
export const spec = {
code: BIDDER_CODE,
aliases: ['adingo'],
/**
* Determines whether or not the given bid request is valid.
*
* @param {BidRequest} bid The bid params to validate.
* @return boolean True if this is a valid bid, and false otherwise.
*/
isBidRequestValid: (bid) => {
return !!(bid.params.groupId && bid.params.tagId);
},
/**
* Make a server request from the list of BidRequests.
*
* @param {validBidRequests} validBidRequests an array of bids.
* @param {BidderRequest} bidderRequest bidder request object.
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: (validBidRequests, bidderRequest) => {
const serverRequests = [];
const page = bidderRequest.refererInfo.page;
_each(validBidRequests, (request) => {
const impExt = request.ortb2Imp?.ext;
const data = Object();
data.page = page;
data.adUnitCode = request.adUnitCode;
data.bidId = request.bidId;
data.user = {
data: bidderRequest.ortb2?.user?.data ?? [],
eids: [
...(request.userIdAsEids ?? []),
...(bidderRequest.ortb2?.user?.ext?.eids ?? []),
],
};
if (impExt) {
data.transactionId = impExt.tid;
data.gpid = impExt.gpid ?? impExt.data?.pbadslot ?? impExt.data?.adserver?.adslot;
}
if (bidderRequest.gdprConsent) {
deepSetValue(data, 'regs.gdpr', {
consent: bidderRequest.gdprConsent.consentString,
gdprApplies: bidderRequest.gdprConsent.gdprApplies ? 1 : 0,
});
}
if (bidderRequest.uspConsent) {
deepSetValue(data, 'regs.us_privacy', {
consent: bidderRequest.uspConsent,
});
}
if (config.getConfig('coppa') === true) {
deepSetValue(data, 'regs.coppa', 1);
}
data.sizes = [];
_each(request.sizes, (size) => {
data.sizes.push({
w: size[0],
h: size[1]
});
});
data.params = request.params;
if (request.schain) {
data.schain = request.schain;
}
const searchParams = new URLSearchParams({
dfpUnitCode: request.params.dfpUnitCode,
tagId: request.params.tagId,
groupId: request.params.groupId,
});
serverRequests.push({
method: 'POST',
url: END_POINT + '?' + searchParams.toString(),
options: {
contentType: 'application/json',
withCredentials: true,
customHeaders: {
'x-fluct-app': 'prebid/fluctBidAdapter',
'x-fluct-version': VERSION,
'x-openrtb-version': 2.5
}
},
data: data
});
});
return serverRequests;
},
/*
* Unpack the respnse from the server into a list of bids.
*
* @param {serverResponse} serverResponse A successful response from the server.
* @return {bid[]} An array of bids which weer nested inside the server.
*/
interpretResponse: (serverResponse, serverRequest) => {
const bidResponses = [];
const res = serverResponse.body;
if (!isEmpty(res) && !isEmpty(res.seatbid) && !isEmpty(res.seatbid[0].bid)) {
const bid = res.seatbid[0].bid[0];
const dealId = bid.dealid;
const beaconUrl = bid.burl;
const callImpBeacon = `<script type="application/javascript">` +
`(function() { var img = new Image(); img.src = "${beaconUrl}"})()` +
`</script>`;
let data = {
requestId: res.id,
currency: res.cur,
cpm: parseFloat(bid.price) || 0,
netRevenue: NET_REVENUE,
width: bid.w,
height: bid.h,
creativeId: bid.crid,
ttl: TTL,
ad: bid.adm + callImpBeacon,
meta: {
advertiserDomains: bid.adomain || [],
},
};
if (!isEmpty(dealId)) {
data.dealId = dealId;
}
bidResponses.push(data);
}
return bidResponses;
},
/*
* Register the user sync pixels which should be dropped after the auction.
*
* @params {syncOptions} syncOptions which user syncs are allowed?
* @params {ServerResponse[]} serverResponses List of server's responses.
* @return {UserSync[]} The user syncs which should be dropped.
*
*/
getUserSyncs: (syncOptions, serverResponses) => {
// gdpr, us_privacy, and coppa params to be handled on the server end.
const usersyncs = serverResponses.reduce((acc, serverResponse) => [
...acc,
...(serverResponse.body.usersyncs ?? []),
], []);
const syncs = usersyncs.filter(
(sync) => (
(sync['type'] === 'image' && syncOptions.pixelEnabled) ||
(sync['type'] === 'iframe' && syncOptions.iframeEnabled)
)
).map((sync) => ({
type: sync.type,
url: sync.url,
}));
return syncs;
}
};
registerBidder(spec);