forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmaticBidAdapter.js
147 lines (131 loc) · 4.42 KB
/
admaticBidAdapter.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
import * as utils from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
const BIDDER_CODE = 'admatic';
const ENDPOINT_URL = 'https://ads4.admatic.com.tr/prebid/v3/bidrequest';
export const spec = {
code: BIDDER_CODE,
aliases: ['admatic'], // short code
/**
* 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) {
return !!(bid.params.pid && bid.params.wid && bid.params.url);
},
/**
* Make a server request from the list of BidRequests.
*
* @param {validBidRequests[]} - an array of bids
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: function (validBidRequests) {
const payload = {
request: []
};
for (var i = 0; i < validBidRequests.length; i++) {
var validBidRequest = validBidRequests[i];
payload.auctionId = validBidRequest.auctionId;
payload.bidder = validBidRequest.bidder;
payload.bidderRequestId = validBidRequest.bidderRequestId;
payload.pid = validBidRequest.params.pid;
payload.wid = validBidRequest.params.wid;
payload.url = validBidRequest.params.url;
var request = {
adUnitCode: validBidRequest.adUnitCode,
bidId: validBidRequest.bidId,
transactionId: validBidRequest.transactionId,
priceType: validBidRequest.params.priceType,
sizes: transformSizes(validBidRequest.sizes)
}
payload.request.push(request);
}
const payloadString = JSON.stringify(payload);
return {
method: 'POST',
url: ENDPOINT_URL,
data: payloadString,
bidder: 'admatic',
bids: validBidRequests
};
},
/**
* Unpack the response from the server into a list of bids.
*
* @param {ServerResponse} serverResponse A successful response from the server.
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: function (serverResponse, bidRequest) {
const serverBody = serverResponse.body;
const bidResponses = [];
if (serverBody) {
if (serverBody.tags && serverBody.tags.length > 0) {
serverBody.tags.forEach(serverBid => {
if (serverBid != null) {
if (serverBid.cpm !== 0) {
const bidResponse = {
requestId: serverBid.bidId,
cpm: serverBid.cpm,
width: serverBid.width,
height: serverBid.height,
creativeId: serverBid.creativeId,
dealId: serverBid.dealId,
currency: serverBid.currency,
netRevenue: serverBid.netRevenue,
ttl: serverBid.ttl,
referrer: serverBid.referrer,
ad: serverBid.ad
};
bidResponses.push(bidResponse);
}
}
});
}
}
return bidResponses;
},
/**
* 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.
* @return {UserSync[]} The user syncs which should be dropped.
*/
getUserSyncs: function (syncOptions, serverResponses) {
const syncs = [];
if (syncOptions.iframeEnabled) {
syncs.push({
type: 'iframe',
url: 'https://ads4.admatic.com.tr/prebid/static/usersync/v3/async_usersync.html'
});
}
if (syncOptions.pixelEnabled && serverResponses.length > 0) {
syncs.push({
type: 'image',
url: 'https://ads5.admatic.com.tr/prebid/v3/bidrequest/usersync'
});
}
return syncs;
}
}
/* Turn bid request sizes into ut-compatible format */
function transformSizes(requestSizes) {
let sizes = [];
let sizeObj = {};
if (utils.isArray(requestSizes) && requestSizes.length === 2 && !utils.isArray(requestSizes[0])) {
sizeObj.width = parseInt(requestSizes[0], 10);
sizeObj.height = parseInt(requestSizes[1], 10);
sizes.push(sizeObj);
} else if (typeof requestSizes === 'object') {
for (let i = 0; i < requestSizes.length; i++) {
let size = requestSizes[i];
sizeObj = {};
sizeObj.width = parseInt(size[0], 10);
sizeObj.height = parseInt(size[1], 10);
sizes.push(sizeObj);
}
}
return sizes;
}
registerBidder(spec);