forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmixerBidAdapter.js
142 lines (135 loc) · 4.45 KB
/
admixerBidAdapter.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
import {isStr, logError, isFn, deepAccess} from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {config} from '../src/config.js';
import {BANNER, VIDEO, NATIVE} from '../src/mediaTypes.js';
import {convertOrtbRequestToProprietaryNative} from '../src/native.js';
import {find} from '../src/polyfill.js';
const BIDDER_CODE = 'admixer';
const ENDPOINT_URL = 'https://inv-nets.admixer.net/prebid.1.2.aspx';
const ALIASES = [
{code: 'go2net', endpoint: 'https://ads.go2net.com.ua/prebid.1.2.aspx'},
'adblender',
{code: 'futureads', endpoint: 'https://ads.futureads.io/prebid.1.2.aspx'},
{code: 'smn', endpoint: 'https://ads.smn.rs/prebid.1.2.aspx'},
{code: 'admixeradx', endpoint: 'https://inv-nets.admixer.net/adxprebid.1.2.aspx'},
'rtbstack'
];
export const spec = {
code: BIDDER_CODE,
aliases: ALIASES.map(val => isStr(val) ? val : val.code),
supportedMediaTypes: [BANNER, VIDEO, NATIVE],
/**
* Determines whether or not the given bid request is valid.
*/
isBidRequestValid: function (bid) {
return bid.bidder === 'rtbstack'
? !!bid.params.tagId
: !!bid.params.zone;
},
/**
* Make a server request from the list of BidRequests.
*/
buildRequests: function (validRequest, bidderRequest) {
// convert Native ORTB definition to old-style prebid native definition
validRequest = convertOrtbRequestToProprietaryNative(validRequest);
let w;
let docRef;
do {
w = w ? w.parent : window;
try {
docRef = w.document.referrer;
} catch (e) {
break;
}
} while (w !== window.top);
const payload = {
imps: [],
ortb2: bidderRequest.ortb2,
docReferrer: docRef,
};
let endpointUrl;
if (bidderRequest) {
// checks if there is specified any endpointUrl in bidder config
endpointUrl = config.getConfig('bidderURL');
if (!endpointUrl && bidderRequest.bidderCode === 'rtbstack') {
logError('The bidderUrl config is required for RTB Stack bids. Please set it with setBidderConfig() for "rtbstack".');
return;
}
// TODO: is 'page' the right value here?
if (bidderRequest.refererInfo?.page) {
payload.referrer = encodeURIComponent(bidderRequest.refererInfo.page);
}
if (bidderRequest.gdprConsent) {
payload.gdprConsent = {
consentString: bidderRequest.gdprConsent.consentString,
// will check if the gdprApplies field was populated with a boolean value (ie from page config). If it's undefined, then default to true
gdprApplies: (typeof bidderRequest.gdprConsent.gdprApplies === 'boolean') ? bidderRequest.gdprConsent.gdprApplies : true
};
}
if (bidderRequest.uspConsent) {
payload.uspConsent = bidderRequest.uspConsent;
}
}
validRequest.forEach((bid) => {
let imp = {};
Object.keys(bid).forEach(key => imp[key] = bid[key]);
imp.ortb2 && delete imp.ortb2;
let bidFloor = getBidFloor(bid);
if (bidFloor) {
imp.bidFloor = bidFloor;
}
payload.imps.push(imp);
});
let urlForRequest = endpointUrl || getEndpointUrl(bidderRequest.bidderCode)
return {
method: 'POST',
url: urlForRequest,
data: payload,
};
},
/**
* Unpack the response from the server into a list of bids.
*/
interpretResponse: function (serverResponse, bidRequest) {
const bidResponses = [];
try {
const {body: {ads = []} = {}} = serverResponse;
ads.forEach((ad) => bidResponses.push(ad));
} catch (e) {
logError(e);
}
return bidResponses;
},
getUserSyncs: function(syncOptions, serverResponses, gdprConsent) {
const pixels = [];
serverResponses.forEach(({body: {cm = {}} = {}}) => {
const {pixels: img = [], iframes: frm = []} = cm;
if (syncOptions.pixelEnabled) {
img.forEach((url) => pixels.push({type: 'image', url}));
}
if (syncOptions.iframeEnabled) {
frm.forEach((url) => pixels.push({type: 'iframe', url}));
}
});
return pixels;
}
};
function getEndpointUrl(code) {
return find(ALIASES, (val) => val.code === code)?.endpoint || ENDPOINT_URL;
}
function getBidFloor(bid) {
if (!isFn(bid.getFloor)) {
return deepAccess(bid, 'params.bidFloor', 0);
}
try {
const bidFloor = bid.getFloor({
currency: 'USD',
mediaType: '*',
size: '*',
});
return bidFloor?.floor;
} catch (_) {
return 0;
}
}
registerBidder(spec);