forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
minutemediaBidAdapter.js
106 lines (95 loc) · 2.78 KB
/
minutemediaBidAdapter.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
import {
logWarn,
logInfo,
isArray,
deepAccess,
triggerPixel,
} from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import {
getEndpoint,
generateBidsParams,
generateGeneralParams,
buildBidResponse,
} from '../libraries/riseUtils/index.js';
const SUPPORTED_AD_TYPES = [BANNER, VIDEO];
const BIDDER_CODE = 'minutemedia';
const ADAPTER_VERSION = '6.0.0';
const TTL = 360;
const DEFAULT_CURRENCY = 'USD';
const BASE_URL = 'https://hb.minutemedia-prebid.com/';
const MODES = {
PRODUCTION: 'hb-mm-multi',
TEST: 'hb-multi-mm-test'
};
export const spec = {
code: BIDDER_CODE,
gvlid: 918,
version: ADAPTER_VERSION,
supportedMediaTypes: SUPPORTED_AD_TYPES,
isBidRequestValid: function (bidRequest) {
if (!bidRequest.params) {
logWarn('no params have been set to MinuteMedia adapter');
return false;
}
if (!bidRequest.params.org) {
logWarn('org is a mandatory param for MinuteMedia adapter');
return false;
}
return true;
},
buildRequests: function (validBidRequests, bidderRequest) {
const combinedRequestsObject = {};
const generalObject = validBidRequests[0];
const testMode = generalObject.params.testMode;
combinedRequestsObject.params = generateGeneralParams(generalObject, bidderRequest, ADAPTER_VERSION);
combinedRequestsObject.bids = generateBidsParams(validBidRequests, bidderRequest);
return {
method: 'POST',
url: getEndpoint(testMode, BASE_URL, MODES),
data: combinedRequestsObject
};
},
interpretResponse: function ({ body }) {
const bidResponses = [];
if (body.bids) {
body.bids.forEach(adUnit => {
const bidResponse = buildBidResponse(adUnit, DEFAULT_CURRENCY, TTL, VIDEO, BANNER);
bidResponses.push(bidResponse);
});
}
return bidResponses;
},
getUserSyncs: function (syncOptions, serverResponses) {
const syncs = [];
for (const response of serverResponses) {
if (syncOptions.iframeEnabled && deepAccess(response, 'body.params.userSyncURL')) {
syncs.push({
type: 'iframe',
url: deepAccess(response, 'body.params.userSyncURL')
});
}
if (syncOptions.pixelEnabled && isArray(deepAccess(response, 'body.params.userSyncPixels'))) {
const pixels = response.body.params.userSyncPixels.map(pixel => {
return {
type: 'image',
url: pixel
};
});
syncs.push(...pixels);
}
}
return syncs;
},
onBidWon: function (bid) {
if (bid == null) {
return;
}
logInfo('onBidWon:', bid);
if (bid.hasOwnProperty('nurl') && bid.nurl.length > 0) {
triggerPixel(bid.nurl);
}
}
};
registerBidder(spec);