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

integr8 Bid Adapter: add new bid adapter #6882

Merged
merged 4 commits into from Aug 3, 2021
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
141 changes: 141 additions & 0 deletions modules/integr8BidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import * as utils from '../src/utils.js';

const BIDDER_CODE = 'integr8';
const ENDPOINT_URL = 'https://integr8.central.gjirafa.tech/bid';
const DIMENSION_SEPARATOR = 'x';
const SIZE_SEPARATOR = ';';

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER, VIDEO],
/**
* 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) {
return !!(bid.params && bid.params.propertyId && 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 propertyId = '';
let pageViewGuid = '';
let storageId = '';
let bidderRequestId = '';
let url = '';
let contents = [];
let data = {};

if (bidderRequest) {
bidderRequestId = bidderRequest.bidderRequestId;

if (bidderRequest.refererInfo) {
url = bidderRequest.refererInfo.referer;
}
}

let placements = validBidRequests.map(bidRequest => {
if (!propertyId) { propertyId = bidRequest.params.propertyId; }
if (!pageViewGuid) { pageViewGuid = bidRequest.params.pageViewGuid || ''; }
if (!storageId) { storageId = bidRequest.params.storageId || ''; }
if (!contents.length && bidRequest.params.contents && bidRequest.params.contents.length) { contents = bidRequest.params.contents; }
if (!Object.keys(data).length && bidRequest.params.data && Object.keys(bidRequest.params.data).length) { data = bidRequest.params.data; }

return {
sizes: generateSizeParam(bidRequest.sizes),
adUnitId: bidRequest.adUnitCode,
placementId: bidRequest.params.placementId,
bidid: bidRequest.bidId,
count: bidRequest.params.count,
skipTime: utils.deepAccess(bidRequest, 'mediaTypes.video.skipafter', bidRequest.params.skipTime),
floor: getBidFloor(bidRequest)
};
});

let body = {
propertyId: propertyId,
pageViewGuid: pageViewGuid,
storageId: storageId,
url: url,
requestid: bidderRequestId,
placements: placements,
contents: contents,
data: data
}

return [{
method: 'POST',
url: ENDPOINT_URL,
data: body
}];
},
/**
* 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) {
const responses = serverResponse.body;
const bidResponses = [];
for (var i = 0; i < responses.length; i++) {
const bidResponse = {
requestId: responses[i].BidId,
cpm: responses[i].CPM,
width: responses[i].Width,
height: responses[i].Height,
creativeId: responses[i].CreativeId,
currency: responses[i].Currency,
netRevenue: responses[i].NetRevenue,
ttl: responses[i].TTL,
referrer: responses[i].Referrer,
ad: responses[i].Ad,
vastUrl: responses[i].VastUrl,
mediaType: responses[i].MediaType,
meta: {
advertiserDomains: Array.isArray(responses[i].ADomain) ? responses[i].ADomain : []
}
};
bidResponses.push(bidResponse);
}
return bidResponses;
}
}

/**
* Generate size param for bid request using sizes array
*
* @param {Array} sizes Possible sizes for the ad unit.
* @return {string} Processed sizes param to be used for the bid request.
*/
function generateSizeParam(sizes) {
return sizes.map(size => size.join(DIMENSION_SEPARATOR)).join(SIZE_SEPARATOR);
}

export function getBidFloor(bid) {
if (!utils.isFn(bid.getFloor)) {
return null;
}

let floor = bid.getFloor({
currency: 'EUR',
mediaType: '*',
size: '*'
});

if (utils.isPlainObject(floor) && !isNaN(floor.floor) && floor.currency === 'EUR') {
return floor.floor;
}

return null;
}

registerBidder(spec);
67 changes: 67 additions & 0 deletions modules/integr8BidAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Overview
Module Name: Integr8 Bidder Adapter Module

Type: Bidder Adapter

Maintainer: arditb@gjirafa.com

# Description
Integr8 Bidder Adapter for Prebid.js.

# Test Parameters
```js
var adUnits = [
{
code: 'test-div',
mediaTypes: {
banner: {
sizes: [
[300, 250]
]
}
},
bids: [{
bidder: 'integr8',
params: {
propertyId: '105109', //Required
placementId: '846835', //Required
data: { //Optional
catalogs: [{
catalogId: "699229",
items: ["193", "4", "1"]
}],
inventory: {
category: ["tech"],
query: ["iphone 12"]
}
}
}
}]
},
{
code: 'test-div',
mediaTypes: {
video: {
context: 'instream'
}
},
bids: [{
bidder: 'integr8',
params: {
propertyId: '105109', //Required
placementId: '846830', //Required
data: { //Optional
catalogs: [{
catalogId: "699229",
items: ["193", "4", "1"]
}],
inventory: {
category: ["tech"],
query: ["iphone 12"]
}
}
}
}]
}
];
```
Loading