-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
logicadBidAdapter.js
110 lines (95 loc) · 3.03 KB
/
logicadBidAdapter.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
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER, NATIVE} from '../src/mediaTypes.js';
import { convertOrtbRequestToProprietaryNative } from '../src/native.js';
import { deepAccess } from '../src/utils.js';
const BIDDER_CODE = 'logicad';
const ENDPOINT_URL = 'https://pb.ladsp.com/adrequest/prebid';
export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER, NATIVE],
isBidRequestValid: function (bid) {
return !!(bid.params && bid.params.tid);
},
buildRequests: function (bidRequests, bidderRequest) {
// convert Native ORTB definition to old-style prebid native definition
bidRequests = convertOrtbRequestToProprietaryNative(bidRequests);
const requests = [];
for (let i = 0, len = bidRequests.length; i < len; i++) {
const request = {
method: 'POST',
url: ENDPOINT_URL,
data: JSON.stringify(newBidRequest(bidRequests[i], bidderRequest)),
options: {},
bidderRequest
};
requests.push(request);
}
return requests;
},
interpretResponse: function (serverResponse, bidderRequest) {
serverResponse = serverResponse.body;
const bids = [];
if (!serverResponse || serverResponse.error) {
return bids;
}
serverResponse.seatbid.forEach(function (seatbid) {
bids.push(seatbid.bid);
})
const fledgeAuctionConfigs = deepAccess(serverResponse, 'ext.fledgeAuctionConfigs') || [];
if (fledgeAuctionConfigs.length) {
return {
bids,
paapi: fledgeAuctionConfigs,
};
}
return bids;
},
getUserSyncs: function (syncOptions, serverResponses) {
if (serverResponses.length > 0 && serverResponses[0].body.userSync &&
syncOptions.pixelEnabled && serverResponses[0].body.userSync.type == 'image') {
return [{
type: 'image',
url: serverResponses[0].body.userSync.url
}];
}
return [];
},
};
function newBidRequest(bidRequest, bidderRequest) {
const bid = {
adUnitCode: bidRequest.adUnitCode,
bidId: bidRequest.bidId,
transactionId: bidRequest.ortb2Imp?.ext?.tid,
sizes: bidRequest.sizes,
params: bidRequest.params,
mediaTypes: bidRequest.mediaTypes,
}
const fledgeEnabled = deepAccess(bidderRequest, 'paapi.enabled')
if (fledgeEnabled) {
const ae = deepAccess(bidRequest, 'ortb2Imp.ext.ae');
if (ae) {
bid.ae = ae;
}
}
const data = {
// TODO: fix auctionId leak: https://github.com/prebid/Prebid.js/issues/9781
auctionId: bidRequest.auctionId,
bidderRequestId: bidRequest.bidderRequestId,
bids: [bid],
prebidJsVersion: '$prebid.version$',
// TODO: is 'page' the right value here?
referrer: bidderRequest.refererInfo.page,
auctionStartTime: bidderRequest.auctionStart,
eids: bidRequest.userIdAsEids,
};
const sua = deepAccess(bidRequest, 'ortb2.device.sua');
if (sua) {
data.sua = sua;
}
const userData = deepAccess(bidRequest, 'ortb2.user.data');
if (userData) {
data.userData = userData;
}
return data;
}
registerBidder(spec);