Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bid adapter for Sublime #3960

Merged
merged 10 commits into from
Aug 16, 2019
135 changes: 135 additions & 0 deletions modules/sublimeBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import { registerBidder } from '../src/adapters/bidderFactory';
import { config } from '../src/config';

const BIDDER_CODE = 'sublime';
const DEFAULT_BID_HOST = 'pbjs.sskzlabs.com';
const DEFAULT_CURRENCY = 'EUR';
const DEFAULT_PROTOCOL = 'https';
const DEFAULT_TTL = 600;
const SUBLIME_VERSION = '0.4.0';

export const spec = {
code: BIDDER_CODE,
aliases: [],

/**
* 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: (bid) => {
return !!bid.params.zoneId;
},

/**
* Make a server request from the list of BidRequests.
*
* @param {BidRequest[]} validBidRequests An array of bids
* @param {Object} bidderRequest - Info describing the request to the server.
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: (validBidRequests, bidderRequest) => {
let commonPayload = {
sublimeVersion: SUBLIME_VERSION,
// Current Prebid params
prebidVersion: '$prebid.version$',
currencyCode: config.getConfig('currency.adServerCurrency') || DEFAULT_CURRENCY,
timeout: config.getConfig('bidderTimeout'),
};

// RefererInfo
if (bidderRequest && bidderRequest.refererInfo) {
commonPayload.referer = bidderRequest.refererInfo.referer;
commonPayload.numIframes = bidderRequest.refererInfo.numIframes;
}
// GDPR handling
if (bidderRequest && bidderRequest.gdprConsent) {
commonPayload.gdprConsent = bidderRequest.gdprConsent.consentString;
commonPayload.gdpr = bidderRequest.gdprConsent.gdprApplies; // we're handling the undefined case server side
}

return validBidRequests.map(bid => {
let bidPayload = {
adUnitCode: bid.adUnitCode,
auctionId: bid.auctionId,
bidder: bid.bidder,
bidderRequestId: bid.bidderRequestId,
bidRequestsCount: bid.bidRequestsCount,
requestId: bid.bidId,
sizes: bid.sizes.map(size => ({
w: size[0],
h: size[1],
})),
transactionId: bid.transactionId,
zoneId: bid.params.zoneId,
};

let protocol = bid.params.protocol || DEFAULT_PROTOCOL;
let bidHost = bid.params.bidHost || DEFAULT_BID_HOST;
let payload = Object.assign({}, commonPayload, bidPayload);

return {
method: 'POST',
url: protocol + '://' + bidHost + '/bid',
data: payload,
options: {
contentType: 'application/json',
withCredentials: true
},
};
});
},

/**
* Unpack the response from the server into a list of bids.
*
* @param {*} serverResponse A successful response from the server.
* @param {*} bidRequest An object with bid request informations
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: (serverResponse, bidRequest) => {
const bidResponses = [];
const response = serverResponse.body;

if (response) {
if (response.timeout || !response.ad || response.ad.match(/<!-- No ad -->/gmi)) {
return bidResponses;
}

// Setting our returned sizes object to default values
let returnedSizes = {
width: 1800,
height: 1000
};

// Verifying Banner sizes
if (bidRequest && bidRequest.data && bidRequest.data.w === 1 && bidRequest.data.h === 1) {
// If banner sizes are 1x1 we set our default size object to 1x1
returnedSizes = {
width: 1,
height: 1
};
}

const bidResponse = {
requestId: response.requestId || '',
cpm: response.cpm || 0,
width: response.width || returnedSizes.width,
height: response.height || returnedSizes.height,
creativeId: response.creativeId || 1,
dealId: response.dealId || 1,
currency: response.currency || DEFAULT_CURRENCY,
netRevenue: response.netRevenue || true,
ttl: response.ttl || DEFAULT_TTL,
ad: response.ad,
};

bidResponses.push(bidResponse);
}

return bidResponses;
},
};

registerBidder(spec);
62 changes: 62 additions & 0 deletions modules/sublimeBidAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Overview

```
Module Name: Sublime Bid Adapter
Module Type: Bidder Adapter
Maintainer: pbjs@sublimeskinz.com
```

# Description

Connects to Sublime for bids.
Sublime bid adapter supports Skinz and M-Skinz formats.

# Nota Bene

Our prebid adapter is unusable with SafeFrame.

# Build

You can build your version of prebid.js, execute:

```shell
gulp build --modules=sublimeBidAdapter
```

Or to build with multiple adapters

```shell
gulp build --modules=sublimeBidAdapter,secondAdapter,thirdAdapter
```

More details in the root [README](../README.md#Build)

## To build from you own repository

- copy `/modules/sublimeBidAdapter.js` to your `/modules/` directory
- copy `/modules/sublimeBidAdapter.md` to your `/modules/` directory
- copy `/test/spec/modules/sublimeBidAdapter_spec.js` to your `/test/spec/modules/` directory

Then build


# Invocation Parameters

```js
var adUnits = [{
code: 'sublime',
mediaTypes: {
banner: {
sizes: [1800, 1000]
}
},
bids: [{
bidder: 'sublime',
params: {
zoneId: <zoneId>
}
}]
}];
```

Where you replace `<zoneId>` by your Sublime Zone id
Loading