Skip to content

Commit

Permalink
Pilotx Bid Adapter: add new bid adapter (prebid#7816)
Browse files Browse the repository at this point in the history
* adding pilotx bid adapter and tests

* removing commented code

* appending review changes

Co-authored-by: AnthonyBoozan <tony@pilotx.tv>
  • Loading branch information
2 people authored and avj83 committed Jan 24, 2022
1 parent 8517e65 commit fcc0cc6
Show file tree
Hide file tree
Showing 3 changed files with 441 additions and 0 deletions.
147 changes: 147 additions & 0 deletions modules/pilotxBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
import { registerBidder } from '../src/adapters/bidderFactory.js';
const BIDDER_CODE = 'pilotx';
const ENDPOINT_URL = '//adn.pilotx.tv/hb'
export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: ['banner', 'video'],
aliases: ['pilotx'], // short code
/**
* 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 sizesCheck = !!bid.sizes
let paramSizesCheck = !!bid.params.sizes
var sizeConfirmed = false
if (sizesCheck) {
if (bid.sizes.length < 1) {
return false
} else {
sizeConfirmed = true
}
}
if (paramSizesCheck) {
if (bid.params.sizes.length < 1 && !sizeConfirmed) {
return false
} else {
sizeConfirmed = true
}
}
if (!sizeConfirmed) {
return false
}
return !!(bid.params.placementId);
},
/**
* 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) {
let payloadItems = {};
validBidRequests.forEach(bidRequest => {
let sizes = [];
let placementId = this.setPlacementID(bidRequest.params.placementId)
payloadItems[placementId] = {}
if (bidRequest.sizes.length > 0) {
if (Array.isArray(bidRequest.sizes[0])) {
for (let i = 0; i < bidRequest.sizes.length; i++) {
sizes[i] = [(bidRequest.sizes[i])[0], (bidRequest.sizes[i])[1]]
}
} else {
sizes[0] = [bidRequest.sizes[0], bidRequest.sizes[1]]
}
payloadItems[placementId]['sizes'] = sizes
}
if (bidRequest.mediaTypes != null) {
for (let i in bidRequest.mediaTypes) {
payloadItems[placementId][i] = {
...bidRequest.mediaTypes[i]
}
}
}
let consentTemp = ''
let consentRequiredTemp = false
if (bidderRequest && bidderRequest.gdprConsent) {
consentTemp = bidderRequest.gdprConsent.consentString
// will check if the gdprApplies field was populated with a boolean value (ie from page config). If it's undefined, then default to true
consentRequiredTemp = (typeof bidderRequest.gdprConsent.gdprApplies === 'boolean') ? bidderRequest.gdprConsent.gdprApplies : true
}

payloadItems[placementId]['gdprConsentString'] = consentTemp
payloadItems[placementId]['gdprConsentRequired'] = consentRequiredTemp
payloadItems[placementId]['bidId'] = bidRequest.bidId
});
const payload = payloadItems;
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} serverResponse A successful response from the server.
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: function (serverResponse, bidRequest) {
const serverBody = serverResponse.body;
const bidResponses = [];
if (serverBody.mediaType == 'banner') {
const bidResponse = {
requestId: serverBody.requestId,
cpm: serverBody.cpm,
width: serverBody.width,
height: serverBody.height,
creativeId: serverBody.creativeId,
currency: serverBody.currency,
netRevenue: false,
ttl: serverBody.ttl,
ad: serverBody.ad,
mediaType: 'banner',
meta: {
mediaType: 'banner',
advertiserDomains: serverBody.advertiserDomains
}
}
bidResponses.push(bidResponse)
} else if (serverBody.mediaType == 'video') {
const bidResponse = {
requestId: serverBody.requestId,
cpm: serverBody.cpm,
width: serverBody.width,
height: serverBody.height,
creativeId: serverBody.creativeId,
currency: serverBody.currency,
netRevenue: false,
ttl: serverBody.ttl,
vastUrl: serverBody.vastUrl,
mediaType: 'video',
meta: {
mediaType: 'video',
advertiserDomains: serverBody.advertiserDomains
}
}
bidResponses.push(bidResponse)
}

return bidResponses;
},

/**
* Formats placement ids for adserver ingestion purposes
* @param {string[]} The placement ID/s in an array
*/
setPlacementID: function (placementId) {
if (Array.isArray(placementId)) {
return placementId.join('#')
}
return placementId
},
}
registerBidder(spec);
50 changes: 50 additions & 0 deletions modules/pilotxBidAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Overview

```
Module Name: Pilotx Prebid Adapter
Module Type: Bidder Adapter
Maintainer: tony@pilotx.tv
```

# Description

Connects to Pilotx

Pilotx's bid adapter supports banner and video.

# Test Parameters
```
// Banner adUnit
var adUnits = [{
code: 'div-gpt-ad-1460505748561-0',
mediaTypes: {
banner: {
sizes: [[300, 250], [300,600]],
}
},
bids: [{
bidder: 'pilotx',
params: {
placementId: ["1423"]
}
}]
}];
// Video adUnit
var videoAdUnit = {
code: 'video1',
mediaTypes: {
video: {
context: 'instream',
playerSize: [640, 480],
}
},
bids: [{
bidder: 'pilotx',
params: {
placementId: '1422',
}
}]
};
```
Loading

0 comments on commit fcc0cc6

Please sign in to comment.