-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
zetaBidAdapter.js
190 lines (176 loc) · 5.73 KB
/
zetaBidAdapter.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
182
183
184
185
186
187
188
189
190
import { logWarn, deepAccess } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import {BANNER} from '../src/mediaTypes.js';
const BIDDER_CODE = 'zeta_global';
const PREBID_DEFINER_ID = '44253'
const ENDPOINT_URL = 'https://prebid.rfihub.com/prebid';
const USER_SYNC_URL = 'https://p.rfihub.com/cm?in=1&pub=';
const DEFAULT_CUR = 'USD';
const TTL = 200;
const NET_REV = true;
export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER],
/**
* 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: function(bid) {
// check for all required bid fields
if (!(bid &&
bid.bidId &&
bid.params)) {
logWarn('Invalid bid request - missing required bid data');
return false;
}
if (!(bid.params.user &&
bid.params.user.buyeruid)) {
logWarn('Invalid bid request - missing required user data');
return false;
}
if (!(bid.params.device &&
bid.params.device.ip)) {
logWarn('Invalid bid request - missing required device data');
return false;
}
if (!(bid.params.device.geo &&
bid.params.device.geo.country)) {
logWarn('Invalid bid request - missing required geo data');
return false;
}
if (!bid.params.definerId) {
logWarn('Invalid bid request - missing required definer data');
return false;
}
return true;
},
/**
* Make a server request from the list of BidRequests.
*
* @param {Bids[]} validBidRequests - an array of bidRequest objects
* @param {BidderRequest} bidderRequest - master bidRequest object
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: function(validBidRequests, bidderRequest) {
const secure = 1; // treat all requests as secure
const request = validBidRequests[0];
const params = request.params;
let impData = {
id: request.bidId,
secure: secure,
banner: buildBanner(request)
};
let payload = {
id: bidderRequest.auctionId,
imp: [impData],
site: params.site ? params.site : {},
app: params.app ? params.app : {},
device: params.device ? params.device : {},
user: params.user ? params.user : {},
at: params.at,
tmax: params.tmax,
wseat: params.wseat,
bseat: params.bseat,
allimps: params.allimps,
cur: [DEFAULT_CUR],
wlang: params.wlang,
bcat: deepAccess(bidderRequest.ortb2Imp, 'bcat') || params.bcat,
badv: params.badv,
bapp: params.bapp,
source: params.source ? params.source : {},
regs: params.regs ? params.regs : {},
ext: params.ext ? params.ext : {}
};
payload.device.ua = navigator.userAgent;
payload.device.ip = navigator.ip;
payload.site.page = bidderRequest.refererInfo.page;
payload.site.mobile = /(ios|ipod|ipad|iphone|android)/i.test(navigator.userAgent) ? 1 : 0;
payload.ext.definerId = params.definerId;
if (params.test) {
payload.test = params.test;
}
if (request.gdprConsent) {
payload.regs.ext = Object.assign(
payload.regs.ext,
{gdpr: request.gdprConsent.gdprApplies === true ? 1 : 0}
);
}
if (request.gdprConsent && request.gdprConsent.gdprApplies) {
payload.user.ext = Object.assign(
payload.user.ext,
{consent: request.gdprConsent.consentString}
);
}
const postUrl = params.definerId !== PREBID_DEFINER_ID ? ENDPOINT_URL.concat('/', params.definerId) : ENDPOINT_URL;
return {
method: 'POST',
url: postUrl,
data: JSON.stringify(payload),
};
},
/**
* Unpack the response from the server into a list of bids.
*
* @param {ServerResponse} serverResponse A successful response from the server.
* @param bidRequest The payload from the server's response.
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: function(serverResponse, bidRequest) {
let bidResponse = [];
if (Object.keys(serverResponse.body).length !== 0) {
let zetaResponse = serverResponse.body;
let zetaBid = zetaResponse.seatbid[0].bid[0];
let bid = {
requestId: zetaBid.impid,
cpm: zetaBid.price,
currency: zetaResponse.cur,
width: zetaBid.w,
height: zetaBid.h,
ad: zetaBid.adm,
ttl: TTL,
creativeId: zetaBid.crid,
netRevenue: NET_REV
};
bidResponse.push(bid);
}
return bidResponse;
},
/**
* Register the user sync pixels which should be dropped after the auction.
*
* @param {SyncOptions} syncOptions Which user syncs are allowed?
* @param {ServerResponse[]} serverResponses List of server's responses.
* @param definerId The calling entity's definer id
* @param gdprConsent The GDPR consent parameters
* @param uspConsent The USP consent parameters
* @return {UserSync[]} The user syncs which should be dropped.
*/
getUserSyncs: function(syncOptions, serverResponses, definerId, gdprConsent, uspConsent) {
const syncs = [];
if (definerId === '' || definerId === null) {
definerId = PREBID_DEFINER_ID;
}
if (syncOptions.iframeEnabled) {
syncs.push({
type: 'iframe',
url: USER_SYNC_URL.concat(definerId)
});
}
return syncs;
}
}
function buildBanner(request) {
let sizes = request.sizes;
if (request.mediaTypes &&
request.mediaTypes.banner &&
request.mediaTypes.banner.sizes) {
sizes = request.mediaTypes.banner.sizes;
}
return {
w: sizes[0][0],
h: sizes[0][1]
};
}
registerBidder(spec);