forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmytargetBidAdapter.js
112 lines (92 loc) · 2.53 KB
/
mytargetBidAdapter.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
import { _map } from '../src/utils.js';
import { config } from '../src/config.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
const BIDDER_CODE = 'mytarget';
const BIDDER_URL = '//ad.mail.ru/hbid_prebid/';
const DEFAULT_CURRENCY = 'RUB';
const DEFAULT_TTL = 180;
function buildPlacement(bidRequest) {
let { bidId, params } = bidRequest;
let { placementId, position, response, bidfloor } = params;
let placement = {
placementId,
id: bidId,
position: position || 0,
response: response || 0
};
if (typeof bidfloor !== 'undefined') {
placement.bidfloor = bidfloor;
}
return placement;
}
function getSiteName(referrer) {
let sitename = config.getConfig('mytarget.sitename');
if (!sitename) {
const parsed = document.createElement('a');
parsed.href = decodeURIComponent(referrer);
sitename = parsed.hostname;
}
return sitename;
}
function generateRandomId() {
return Math.random().toString(16).substring(2);
}
export const spec = {
code: BIDDER_CODE,
isBidRequestValid: function(bid) {
return !!bid.params.placementId;
},
buildRequests: function(validBidRequests, bidderRequest) {
let referrer = '';
if (bidderRequest && bidderRequest.refererInfo) {
referrer = bidderRequest.refererInfo.page;
}
const payload = {
places: _map(validBidRequests, buildPlacement),
site: {
sitename: getSiteName(referrer),
page: referrer
},
settings: {
currency: DEFAULT_CURRENCY,
windowSize: {
width: window.screen.width,
height: window.screen.height
}
}
};
return {
method: 'POST',
url: BIDDER_URL,
data: payload,
};
},
interpretResponse: function(serverResponse, bidRequest) {
let { body } = serverResponse;
if (body.bids) {
return _map(body.bids, (bid) => {
let bidResponse = {
requestId: bid.id,
cpm: bid.price,
width: bid.size.width,
height: bid.size.height,
ttl: bid.ttl || DEFAULT_TTL,
currency: bid.currency || DEFAULT_CURRENCY,
creativeId: bid.creativeId || generateRandomId(),
netRevenue: true,
meta: {
advertiserDomains: bid.adomain && bid.adomain.length > 0 ? bid.adomain : [],
}
}
if (bid.adm) {
bidResponse.ad = bid.adm;
} else {
bidResponse.adUrl = bid.displayUrl;
}
return bidResponse;
});
}
return [];
}
}
registerBidder(spec);