Skip to content

Commit d61756d

Browse files
SublimeJeremyjsnellbaker
authored andcommitted
Add bid adapter for Sublime (#3960)
* Add bid adapter for Sublime * Fix tests for sublimeBidAdapter * Fix tests for sublimeBidAdapter * fix(sublime-adapter): fixes to submit sublimePrebidAdapter * fix(sublime-adapter): fixes to submit sublimePrebidAdapter * Remove callback and fix tests * Update adapter to version 0.4.0 - Support of multiple bid request - Remove pixel call - Remove tag - Refactor - Update test * Rearrange constant and import alphabetically * sublimeBidAdapter: remove deprecated method getTopWindowUrl
1 parent c1aa4e4 commit d61756d

File tree

3 files changed

+452
-0
lines changed

3 files changed

+452
-0
lines changed

modules/sublimeBidAdapter.js

+135
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
import { registerBidder } from '../src/adapters/bidderFactory';
2+
import { config } from '../src/config';
3+
4+
const BIDDER_CODE = 'sublime';
5+
const DEFAULT_BID_HOST = 'pbjs.sskzlabs.com';
6+
const DEFAULT_CURRENCY = 'EUR';
7+
const DEFAULT_PROTOCOL = 'https';
8+
const DEFAULT_TTL = 600;
9+
const SUBLIME_VERSION = '0.4.0';
10+
11+
export const spec = {
12+
code: BIDDER_CODE,
13+
aliases: [],
14+
15+
/**
16+
* Determines whether or not the given bid request is valid.
17+
*
18+
* @param {BidRequest} bid The bid params to validate.
19+
* @return boolean True if this is a valid bid, and false otherwise.
20+
*/
21+
isBidRequestValid: (bid) => {
22+
return !!bid.params.zoneId;
23+
},
24+
25+
/**
26+
* Make a server request from the list of BidRequests.
27+
*
28+
* @param {BidRequest[]} validBidRequests An array of bids
29+
* @param {Object} bidderRequest - Info describing the request to the server.
30+
* @return ServerRequest Info describing the request to the server.
31+
*/
32+
buildRequests: (validBidRequests, bidderRequest) => {
33+
let commonPayload = {
34+
sublimeVersion: SUBLIME_VERSION,
35+
// Current Prebid params
36+
prebidVersion: '$prebid.version$',
37+
currencyCode: config.getConfig('currency.adServerCurrency') || DEFAULT_CURRENCY,
38+
timeout: config.getConfig('bidderTimeout'),
39+
};
40+
41+
// RefererInfo
42+
if (bidderRequest && bidderRequest.refererInfo) {
43+
commonPayload.referer = bidderRequest.refererInfo.referer;
44+
commonPayload.numIframes = bidderRequest.refererInfo.numIframes;
45+
}
46+
// GDPR handling
47+
if (bidderRequest && bidderRequest.gdprConsent) {
48+
commonPayload.gdprConsent = bidderRequest.gdprConsent.consentString;
49+
commonPayload.gdpr = bidderRequest.gdprConsent.gdprApplies; // we're handling the undefined case server side
50+
}
51+
52+
return validBidRequests.map(bid => {
53+
let bidPayload = {
54+
adUnitCode: bid.adUnitCode,
55+
auctionId: bid.auctionId,
56+
bidder: bid.bidder,
57+
bidderRequestId: bid.bidderRequestId,
58+
bidRequestsCount: bid.bidRequestsCount,
59+
requestId: bid.bidId,
60+
sizes: bid.sizes.map(size => ({
61+
w: size[0],
62+
h: size[1],
63+
})),
64+
transactionId: bid.transactionId,
65+
zoneId: bid.params.zoneId,
66+
};
67+
68+
let protocol = bid.params.protocol || DEFAULT_PROTOCOL;
69+
let bidHost = bid.params.bidHost || DEFAULT_BID_HOST;
70+
let payload = Object.assign({}, commonPayload, bidPayload);
71+
72+
return {
73+
method: 'POST',
74+
url: protocol + '://' + bidHost + '/bid',
75+
data: payload,
76+
options: {
77+
contentType: 'application/json',
78+
withCredentials: true
79+
},
80+
};
81+
});
82+
},
83+
84+
/**
85+
* Unpack the response from the server into a list of bids.
86+
*
87+
* @param {*} serverResponse A successful response from the server.
88+
* @param {*} bidRequest An object with bid request informations
89+
* @return {Bid[]} An array of bids which were nested inside the server.
90+
*/
91+
interpretResponse: (serverResponse, bidRequest) => {
92+
const bidResponses = [];
93+
const response = serverResponse.body;
94+
95+
if (response) {
96+
if (response.timeout || !response.ad || response.ad.match(/<!-- No ad -->/gmi)) {
97+
return bidResponses;
98+
}
99+
100+
// Setting our returned sizes object to default values
101+
let returnedSizes = {
102+
width: 1800,
103+
height: 1000
104+
};
105+
106+
// Verifying Banner sizes
107+
if (bidRequest && bidRequest.data && bidRequest.data.w === 1 && bidRequest.data.h === 1) {
108+
// If banner sizes are 1x1 we set our default size object to 1x1
109+
returnedSizes = {
110+
width: 1,
111+
height: 1
112+
};
113+
}
114+
115+
const bidResponse = {
116+
requestId: response.requestId || '',
117+
cpm: response.cpm || 0,
118+
width: response.width || returnedSizes.width,
119+
height: response.height || returnedSizes.height,
120+
creativeId: response.creativeId || 1,
121+
dealId: response.dealId || 1,
122+
currency: response.currency || DEFAULT_CURRENCY,
123+
netRevenue: response.netRevenue || true,
124+
ttl: response.ttl || DEFAULT_TTL,
125+
ad: response.ad,
126+
};
127+
128+
bidResponses.push(bidResponse);
129+
}
130+
131+
return bidResponses;
132+
},
133+
};
134+
135+
registerBidder(spec);

modules/sublimeBidAdapter.md

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Overview
2+
3+
```
4+
Module Name: Sublime Bid Adapter
5+
Module Type: Bidder Adapter
6+
Maintainer: [email protected]
7+
```
8+
9+
# Description
10+
11+
Connects to Sublime for bids.
12+
Sublime bid adapter supports Skinz and M-Skinz formats.
13+
14+
# Nota Bene
15+
16+
Our prebid adapter is unusable with SafeFrame.
17+
18+
# Build
19+
20+
You can build your version of prebid.js, execute:
21+
22+
```shell
23+
gulp build --modules=sublimeBidAdapter
24+
```
25+
26+
Or to build with multiple adapters
27+
28+
```shell
29+
gulp build --modules=sublimeBidAdapter,secondAdapter,thirdAdapter
30+
```
31+
32+
More details in the root [README](../README.md#Build)
33+
34+
## To build from you own repository
35+
36+
- copy `/modules/sublimeBidAdapter.js` to your `/modules/` directory
37+
- copy `/modules/sublimeBidAdapter.md` to your `/modules/` directory
38+
- copy `/test/spec/modules/sublimeBidAdapter_spec.js` to your `/test/spec/modules/` directory
39+
40+
Then build
41+
42+
43+
# Invocation Parameters
44+
45+
```js
46+
var adUnits = [{
47+
code: 'sublime',
48+
mediaTypes: {
49+
banner: {
50+
sizes: [1800, 1000]
51+
}
52+
},
53+
bids: [{
54+
bidder: 'sublime',
55+
params: {
56+
zoneId: <zoneId>
57+
}
58+
}]
59+
}];
60+
```
61+
62+
Where you replace `<zoneId>` by your Sublime Zone id

0 commit comments

Comments
 (0)