forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
slimcutBidAdapter.js
129 lines (126 loc) · 4.08 KB
/
slimcutBidAdapter.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
import {getBidIdParameter, getValue, parseSizesInput} from '../src/utils.js';
import {
registerBidder
} from '../src/adapters/bidderFactory.js';
import {
ajax
} from '../src/ajax.js';
/**
* @typedef {import('../src/adapters/bidderFactory.js').BidRequest} BidRequest
* @typedef {import('../src/adapters/bidderFactory.js').Bid} Bid
* @typedef {import('../src/adapters/bidderFactory.js').validBidRequests} validBidRequests
*/
const BIDDER_CODE = 'slimcut';
const ENDPOINT_URL = 'https://sb.freeskreen.com/pbr';
export const spec = {
code: BIDDER_CODE,
gvlid: 102,
aliases: [{ code: 'scm', gvlid: 102 }],
supportedMediaTypes: ['video', 'banner'],
/**
* Determines whether or not the given bid request is valid.
*
* @param {BidRequest} bid The bid params to validate.
* @return boolean True if this is a valid bid, and false otherwise.
*/
isBidRequestValid: function(bid) {
let isValid = false;
if (typeof bid.params !== 'undefined' && !isNaN(parseInt(getValue(bid.params, 'placementId'))) && parseInt(getValue(bid.params, 'placementId')) > 0) {
isValid = true;
}
return isValid;
},
/**
* Make a server request from the list of BidRequests.
*
* @param {validBidRequests[]} an array of bids
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: function(validBidRequests, bidderRequest) {
const bids = validBidRequests.map(buildRequestObject);
const payload = {
referrer: getReferrerInfo(bidderRequest),
data: bids,
deviceWidth: screen.width
};
let gdpr = bidderRequest.gdprConsent;
if (bidderRequest && gdpr) {
let isCmp = (typeof gdpr.gdprApplies === 'boolean')
let isConsentString = (typeof gdpr.consentString === 'string')
payload.gdpr_iab = {
consent: isConsentString ? gdpr.consentString : '',
status: isCmp ? gdpr.gdprApplies : -1
};
}
const payloadString = JSON.stringify(payload);
return {
method: 'POST',
url: ENDPOINT_URL,
data: payloadString,
};
},
/**
* Unpack the response from the server into a list of bids.
*
* @param {*} serverResponse A successful response from the server.
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: function(serverResponse, request) {
const bidResponses = [];
serverResponse = serverResponse.body;
if (serverResponse.responses) {
serverResponse.responses.forEach(function(bid) {
const bidResponse = {
cpm: bid.cpm,
width: bid.width,
height: bid.height,
currency: bid.currency,
netRevenue: bid.netRevenue,
ttl: bid.ttl,
ad: bid.ad,
requestId: bid.requestId,
creativeId: bid.creativeId,
winUrl: bid.winUrl,
meta: {
advertiserDomains: bid.adomain || []
}
};
bidResponses.push(bidResponse);
});
}
return bidResponses;
},
getUserSyncs: function(syncOptions, serverResponses) {
if (syncOptions.iframeEnabled) {
return [{
type: 'iframe',
url: 'https://sb.freeskreen.com/async_usersync.html'
}];
}
return [];
},
onBidWon: function(bid) {
ajax(bid.winUrl + bid.cpm, null);
}
}
function buildRequestObject(bid) {
const reqObj = {};
let placementId = getValue(bid.params, 'placementId');
reqObj.sizes = parseSizesInput(bid.sizes);
reqObj.bidId = getBidIdParameter('bidId', bid);
reqObj.bidderRequestId = getBidIdParameter('bidderRequestId', bid);
reqObj.placementId = parseInt(placementId);
reqObj.adUnitCode = getBidIdParameter('adUnitCode', bid);
// TODO: fix auctionId leak: https://github.com/prebid/Prebid.js/issues/9781
reqObj.auctionId = getBidIdParameter('auctionId', bid);
reqObj.transactionId = bid.ortb2Imp?.ext?.tid || '';
return reqObj;
}
function getReferrerInfo(bidderRequest) {
let ref = window.location.href;
if (bidderRequest && bidderRequest.refererInfo && bidderRequest.refererInfo.page) {
ref = bidderRequest.refererInfo.page;
}
return ref;
}
registerBidder(spec);