Skip to content

Commit

Permalink
Bidmatic Bid Adapter: Initial Release (#11690)
Browse files Browse the repository at this point in the history
* Bidmatic Initial commit

* Use getFloor from price module
  • Loading branch information
GeneGenie committed Jun 5, 2024
1 parent 13b87fa commit 105c662
Show file tree
Hide file tree
Showing 4 changed files with 405 additions and 1 deletion.
110 changes: 110 additions & 0 deletions modules/bidmaticBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import { ortbConverter } from '../libraries/ortbConverter/converter.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import { replaceAuctionPrice, isNumber, deepAccess, isFn } from '../src/utils.js';

export const END_POINT = 'https://adapter.bidmatic.io/ortb-client';
const BIDDER_CODE = 'bidmatic';
const DEFAULT_CURRENCY = 'USD';

export const converter = ortbConverter({
context: {
netRevenue: true,
ttl: 290,
},
imp(buildImp, bidRequest, context) {
const imp = buildImp(bidRequest, context);
const floorInfo = isFn(bidRequest.getFloor) ? bidRequest.getFloor({
currency: context.currency || 'USD',
size: '*',
mediaType: '*'
}) : {
floor: imp.bidfloor || deepAccess(bidRequest, 'params.bidfloor') || 0,
currency: DEFAULT_CURRENCY
};

if (floorInfo) {
imp.bidfloor = floorInfo.floor;
imp.bidfloorcur = floorInfo.currency;
}
imp.tagid = deepAccess(bidRequest, 'ortb2Imp.ext.gpid') || bidRequest.adUnitCode;

return imp;
},
request(buildRequest, imps, bidderRequest, context) {
const request = buildRequest(imps, bidderRequest, context);
if (!request.cur) {
request.cur = [DEFAULT_CURRENCY];
}
return request;
},
bidResponse(buildBidResponse, bid, context) {
const { bidRequest } = context;

let resMediaType;
const reqMediaTypes = Object.keys(bidRequest.mediaTypes);
if (reqMediaTypes.length === 1) {
resMediaType = reqMediaTypes[0];
} else {
if (bid.adm.search(/^(<\?xml|<vast)/i) !== -1) {
resMediaType = VIDEO;
} else {
resMediaType = BANNER;
}
}

context.mediaType = resMediaType;

return buildBidResponse(bid, context);
}
});

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER, VIDEO],
gvlid: 1134,
isBidRequestValid: function (bid) {
return isNumber(deepAccess(bid, 'params.source'))
},

buildRequests: function (validBidRequests, bidderRequest) {
const requestsBySource = validBidRequests.reduce((acc, bidRequest) => {
acc[bidRequest.params.source] = acc[bidRequest.params.source] || [];
acc[bidRequest.params.source].push(bidRequest);
return acc;
}, {});

return Object.entries(requestsBySource).map(([source, bidRequests]) => {
const data = converter.toORTB({ bidRequests, bidderRequest });
const url = new URL(END_POINT);
url.searchParams.append('source', source);
return {
method: 'POST',
url: url.toString(),
data: data,
options: {
withCredentials: true,
}
};
});
},

interpretResponse: function (serverResponse, bidRequest) {
if (!serverResponse || !serverResponse.body) return [];
const parsedSeatbid = serverResponse.body.seatbid.map(seatbidItem => {
const parsedBid = seatbidItem.bid.map((bidItem) => ({
...bidItem,
adm: replaceAuctionPrice(bidItem.adm, bidItem.price),
nurl: replaceAuctionPrice(bidItem.nurl, bidItem.price)
}));
return { ...seatbidItem, bid: parsedBid };
});
const responseBody = { ...serverResponse.body, seatbid: parsedSeatbid };
return converter.fromORTB({
response: responseBody,
request: bidRequest.data,
}).bids;
},

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

```
Module Name: Bidmatic Bid Adapter
Module Type: Bidder Adapter
Maintainer: [email protected]
```

# Description

Adds access to Bidmatic SSP oRTB service.

# Sample Ad Unit: For Publishers
```
var adUnits = [{
code: 'bg-test-rectangle',
sizes: [[300, 250]],
bids: [{
bidder: 'bidmatic',
params: {
source: 886409,
bidfloor: 0.1
}
}]
}]
```
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 105c662

Please sign in to comment.