forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconceptxBidAdapter.js
76 lines (69 loc) · 2.71 KB
/
conceptxBidAdapter.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
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER } from '../src/mediaTypes.js';
// import { logError, logInfo, logWarn, parseUrl } from '../src/utils.js';
const BIDDER_CODE = 'conceptx';
const ENDPOINT_URL = 'https://conceptx.cncpt-central.com/openrtb';
// const LOG_PREFIX = 'ConceptX: ';
export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER],
isBidRequestValid: function (bid) {
return !!(bid.bidId && bid.params.site && bid.params.adunit);
},
buildRequests: function (validBidRequests, bidderRequest) {
// logWarn(LOG_PREFIX + 'all native assets containing URL should be sent as placeholders with sendId(icon, image, clickUrl, displayUrl, privacyLink, privacyIcon)');
const requests = [];
let requestUrl = `${ENDPOINT_URL}`
if (bidderRequest && bidderRequest.gdprConsent && bidderRequest.gdprConsent.gdprApplies) {
requestUrl += '?gdpr_applies=' + bidderRequest.gdprConsent.gdprApplies;
requestUrl += '&consentString=' + bidderRequest.gdprConsent.consentString;
}
for (var i = 0; i < validBidRequests.length; i++) {
const requestParent = { adUnits: [], meta: {} };
const bid = validBidRequests[i]
const { adUnitCode, auctionId, bidId, bidder, bidderRequestId, ortb2 } = bid
requestParent.meta = { adUnitCode, auctionId, bidId, bidder, bidderRequestId, ortb2 }
const { site, adunit } = bid.params
const adUnit = { site, adunit, targetId: bid.bidId }
if (bid.mediaTypes && bid.mediaTypes.banner && bid.mediaTypes.banner.sizes) adUnit.dimensions = bid.mediaTypes.banner.sizes
requestParent.adUnits.push(adUnit);
requests.push({
method: 'POST',
url: requestUrl,
options: {
withCredentials: false,
},
data: JSON.stringify(requestParent),
});
}
return requests;
},
interpretResponse: function (serverResponse, bidRequest) {
const bidResponses = [];
const bidResponsesFromServer = serverResponse.body.bidResponses;
if (Array.isArray(bidResponsesFromServer) && bidResponsesFromServer.length === 0) {
return bidResponses
}
const firstBid = bidResponsesFromServer[0]
if (!firstBid) {
return bidResponses
}
const firstSeat = firstBid.ads[0]
const bidResponse = {
requestId: firstSeat.requestId,
cpm: firstSeat.cpm,
width: firstSeat.width,
height: firstSeat.height,
creativeId: firstSeat.creativeId,
dealId: firstSeat.dealId,
currency: firstSeat.currency,
netRevenue: true,
ttl: firstSeat.ttl,
referrer: firstSeat.referrer,
ad: firstSeat.html
};
bidResponses.push(bidResponse);
return bidResponses;
},
}
registerBidder(spec);