Skip to content

Commit

Permalink
Add AdButler bid adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
trevoradbutler committed Jan 30, 2024
1 parent a40061e commit 14c9ce2
Show file tree
Hide file tree
Showing 4 changed files with 477 additions and 4 deletions.
113 changes: 113 additions & 0 deletions modules/adbutlerBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import * as utils from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER } from '../src/mediaTypes.js';

const BIDDER_CODE = 'adbutler';

function getTrackingPixelsMarkup(pixelURLs) {
return pixelURLs
.map(pixelURL => `<img height="0" width="0" border="0" style="display:none;" src="${pixelURL}"/>`)
.join();
}

export const spec = {
code: BIDDER_CODE,
pageID: Math.floor(Math.random() * 10e6),
aliases: ['divreach', 'doceree'],
supportedMediaTypes: [BANNER],

isBidRequestValid(bid) {
return !!(bid.params.accountID && bid.params.zoneID);
},

buildRequests(validBidRequests) {
const zoneCounters = {};

return utils._map(validBidRequests, function (bidRequest) {
const zoneID = bidRequest.params?.zoneID;

zoneCounters[zoneID] ??= 0;

const domain = bidRequest.params?.domain ?? 'servedbyadbutler.com';
const adserveBase = `https://${domain}/adserve`;
const params = {
...(bidRequest.params?.extra ?? {}),
ID: bidRequest.params?.accountID,
type: 'hbr',
setID: zoneID,
pid: spec.pageID,
place: zoneCounters[zoneID],
kw: bidRequest.params?.keyword,
};

const paramsString = Object.entries(params).map(([key, value]) => `${key}=${value}`).join(';');
const requestURI = `${adserveBase}/;${paramsString};`;

zoneCounters[zoneID]++;

return {
method: 'GET',
url: requestURI,
data: {},
bidRequest,
};
});
},

interpretResponse(serverResponse, serverRequest) {
const bidObj = serverRequest.bidRequest;
const response = serverResponse.body ?? {};

if (!bidObj || response.status !== 'SUCCESS') {
return [];
}

const width = parseInt(response.width);
const height = parseInt(response.height);

const sizeValid = (bidObj.mediaTypes?.banner?.sizes ?? []).some(([w, h]) => w === width && h === height);

if (!sizeValid) {
return [];
}

const cpm = response.cpm;
const minCPM = bidObj.params?.minCPM ?? null;
const maxCPM = bidObj.params?.maxCPM ?? null;

if (minCPM !== null && cpm < minCPM) {
return [];
}

if (maxCPM !== null && cpm > maxCPM) {
return [];
}

let advertiserDomains = [];

if (response.advertiser?.domain) {
advertiserDomains.push(response.advertiser.domain);
}

const bidResponse = {
requestId: bidObj.bidId,
cpm,
currency: 'USD',
width,
height,
ad: response.ad_code + getTrackingPixelsMarkup(response.tracking_pixels),
ttl: 360,
creativeId: response.placement_id,
netRevenue: true,
meta: {
advertiserId: response.advertiser?.id,
advertiserName: response.advertiser?.name,
advertiserDomains,
},
};

return [bidResponse];
},
};

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

**Module Name**: AdButler Bidder Adapter
**Module Type**: Bidder Adapter
**Maintainer**: trevor@sparklit.com

# Description

Bid Adapter for creating a bid from an AdButler zone.

# Test Parameters
```
var adUnits = [
{
code: 'display-div',
sizes: [[300, 250]], // a display size
bids: [
{
bidder: "adbutler",
params: {
accountID: '181556',
zoneID: '705374',
keyword: 'red', //optional
minCPM: '1.00', //optional
maxCPM: '5.00' //optional
}
}
]
}
];
```
8 changes: 4 additions & 4 deletions modules/id5IdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,26 @@ export const storage = getStorageManager({moduleType: MODULE_TYPE_UID, moduleNam
* @property {string} [universal_uid] - The encrypted ID5 ID to pass to bidders
* @property {Object} [ext] - The extensions object to pass to bidders
* @property {Object} [ab_testing] - A/B testing configuration
*/
*/

/**
* @typedef {Object} FetchCallConfig
* @property {string} [url] - The URL for the fetch endpoint
* @property {Object} [overrides] - Overrides to apply to fetch parameters
*/
*/

/**
* @typedef {Object} ExtensionsCallConfig
* @property {string} [url] - The URL for the extensions endpoint
* @property {string} [method] - Overrides the HTTP method to use to make the call
* @property {Object} [body] - Specifies a body to pass to the extensions endpoint
*/
*/

/**
* @typedef {Object} DynamicConfig
* @property {FetchCallConfig} [fetchCall] - The fetch call configuration
* @property {ExtensionsCallConfig} [extensionsCall] - The extensions call configuration
*/
*/

/**
* @typedef {Object} ABTestingConfig
Expand Down
Loading

0 comments on commit 14c9ce2

Please sign in to comment.