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

Pilotx Bid Adapter: add new bid adapter #7816

Merged
merged 7 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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