forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmadvertiseBidAdapter.js
101 lines (89 loc) · 2.91 KB
/
madvertiseBidAdapter.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
import { parseSizesInput, _each } from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
/**
* @typedef {import('../src/adapters/bidderFactory.js').BidRequest} BidRequest
* @typedef {import('../src/adapters/bidderFactory.js').Bid} Bid
*/
// use protocol relative urls for http or https
const MADVERTISE_ENDPOINT = 'https://mobile.mng-ads.com/';
export const spec = {
code: 'madvertise',
/**
* @param {object} bid
* @return boolean
*/
isBidRequestValid: function (bid) {
if (typeof bid.params !== 'object') {
return false;
}
let sizes = parseSizesInput(bid.sizes);
if (!sizes || sizes.length === 0) {
return false;
}
if (sizes.length > 0 && sizes[0] === undefined) {
return false;
}
return typeof bid.params.s != 'undefined';
},
/**
* @param {BidRequest[]} bidRequests
* @param bidderRequest
* @return ServerRequest[]
*/
buildRequests: function (bidRequests, bidderRequest) {
return bidRequests.map(bidRequest => {
bidRequest.startTime = new Date().getTime();
// non-video request builder
var src = '?rt=bid_request&v=1.0';
for (var i = 0; i < bidRequest.sizes.length; i++) {
if (Array.isArray(bidRequest.sizes[i]) && bidRequest.sizes[i].length == 2) {
src = src + '&sizes[' + i + ']=' + bidRequest.sizes[i][0] + 'x' + bidRequest.sizes[i][1];
}
}
_each(bidRequest.params, (item, key) => src = src + '&' + key + '=' + item);
if (typeof bidRequest.params.u == 'undefined') {
src = src + '&u=' + navigator.userAgent;
}
if (bidderRequest && bidderRequest.gdprConsent) {
src = src + '&gdpr=' + (bidderRequest.gdprConsent.gdprApplies ? '1' : '0') + '&consent[0][format]=iab&consent[0][value]=' + bidderRequest.gdprConsent.consentString;
}
return {
method: 'GET',
url: MADVERTISE_ENDPOINT + src,
options: {withCredentials: false},
bidId: bidRequest.bidId
};
});
},
/**
* @param {*} responseObj
* @param {BidRequest} bidRequest
* @return {Bid[]} An array of bids which
*/
interpretResponse: function (responseObj, bidRequest) {
responseObj = responseObj.body;
// check overall response
if (responseObj == null || typeof responseObj !== 'object' || !responseObj.hasOwnProperty('ad')) {
return [];
}
let bid = {
requestId: bidRequest.bidId,
cpm: responseObj.cpm,
width: responseObj.Width,
height: responseObj.height,
ad: responseObj.ad,
ttl: responseObj.ttl,
creativeId: responseObj.creativeId,
netRevenue: responseObj.netRevenue,
currency: responseObj.currency,
dealId: responseObj.dealId,
meta: {
advertiserDomains: Array.isArray(responseObj.adomain) ? responseObj.adomain : []
}
};
return [bid];
},
getUserSyncs: function (syncOptions) {
}
};
registerBidder(spec);