There are two ways to create a custom Prebid.js bidder adapter.
Using “registerBidder” from bidder factory
It is the recommended way and it is covered fairly well in the official docs here: How to Add a New Prebid.js Bidder Adapter. The process is straightforward and simple, so I don’t see much value in repeating it here. If it fits your goals, just follow the official guide and stop reading further :)
Using “registerBidAdapter” method from public api
The second method is much more interesting because it allows you to create a bidder adapter without the need to follow the bidder spec. For example, it allows you to create complex marvels like the Prebid.js server adapter. It is also very simple to add this adapter on the fly without the need to recompile the library or the need to use any internal methods from the Prebid’s giblets, which also may be very useful. But unfortunately, it is covered poorly in the official docs. Reminding me of the great “draw the rest of the owl” meme.
To fix this universe disbalance, I will share a simple example of the working example of such a bidder adapter. It was tested with prebid.js@8.51.0
.
window.pbjs.que.push(() => {
window.pbjs.registerBidAdapter(
() => ({
callBids: (bidderRequest, addBidResponse, done) => {
// do anything network related here
// ...
bidderRequest.bids.forEach((bidRequest) => {
// "1" stands for STATUS.GOOD constant
const bid = window.pbjs.createBid(1, bidRequest);
// you have to fill all these internal fields to allow Prebid to match the bid
bid.requestId = bidRequest.bidId;
bid.adUnitId = bidRequest.adUnitId;
bid.auctionId = bidRequest.auctionId;
bid.adUnitCode = bidRequest.adUnitCode;
bid.bidderCode = bidRequest.bidder;
// the rest of the fields depend on the bid you want to create
bid.cpm = 10;
bid.currency = 'USD';
bid.width = 1;
bid.height = 1;
bid.ttl = 60;
bid.netRevenue = false;
bid.creativeId = '1';
bid.ad = '<div>test ad</div>';
addBidResponse(bidRequest.adUnitCode, bid);
});
done();
}),
'awesome-bidder',
);
});