Thank you for contributing a bid adapter to the open source Prebid Server project. Each new adapter gives publishers more options for monetizing their inventory and strengthens the header bidding community.
This document guides you through the process of developing a new bid adapter for your bidding server. We encourage you to look at existing bid adapters for working examples and practical guidance. You can also ask us questions by submitting a GitHub issue.
NOTE: There are two implementations of Prebid Server, PBS-Go and PBS-Java. We recommend you build new adapters for PBS-Go and allow us to port it to PBS-Java within a couple of months.
Bid adapters are responsible for translating an OpenRTB 2.5 Bid Request to your bidding server’s protocol and mapping your server’s response to an OpenRTB 2.5 Bid Response.
An OpenRTB 2.5 Bid Request contains one or more Impressions, each representing a single ad placement. An Impression may define multiple sizes and/or multiple ad formats. If your bidding server limits requests to a single ad placement, size, or format, then your adapter will need to split the Impression into multiple calls and merge the responses.
You will need to choose a unique name for your bid adapter. Names should be written in lower case and may not contain special characters or emoji. If you already have a Prebid.js bid adapter, we encourage you to use the same name with the same bidder parameters. You may not name your adapter all
, context
, data
, general
, prebid
, skadn
or tid
as those have special meaning in various contexts. Existing bid adapter names are maintained here.
We ask that the first 6 letters of the name you choose be unique among the existing bid adapters. This consideration helps with generating targeting keys for use by some ad exchanges, such as Google Ad Manager.
Throughout the rest of this document, substitute {bidder}
with the name you’ve chosen.
We are proud to run the Prebid Server project as a transparent and trustworthy header bidding solution. You are expected to follow our community’s code of conduct and module rules when creating your adapter and when interacting with others through issues, code reviews, and discussions.
Please take the time to read the rules in full. Below is a summary of some of the rules which apply to your Prebid Server bid adapter:
Failure to follow the rules will lead to delays in approving your adapter for inclusion in Prebid Server. If you’d like to discuss an exception to a rule, please make your request by submitting a GitHub issue.
You are expected to provide support and maintenance for the code you contribute to Prebid Server as part of your bid adapter. We ask that you proactively update your adapter when your bidding server introduces new features or breaking changes.
Occasionally, we’ll introduce changes to the core framework as part of our ongoing maintenance and enhancement of the project. If this causes a compilation error or a performance impact to your adapter, we will update the affected portion of your bid adapter code and provide full unit test coverage of our changes. We will notify you via email if this happens and give you at least one week to review the PR and provide comments. Please understand that we will not wait for your explicit approval for these kinds of changes unless you respond to our email or comment on the PR.
Please be attentive in reading and responding to emails and GitHub issues from publishers, hosts, and Prebid.org project maintainers. If we receive complaints about your bid adapter and you do not respond to our communications, we may disable your adapter by default or remove it from the project entirely.
Before creating your own bid adapter, consider looking into generic adapter implementation. Its main purpose is to simplify testing of PBS. As this adapter just passes requests through without any additional manipulations with data, it can be used to test behaviour of PBS core logic. But, it can be also used as template for simple bid adapters or even for aliasing the very basic ones.
Prebid Server bid adapters consist of several components: bidder config yaml, bidder parameters, bid adapter code, configuration for framework and default configuration(.yaml) values. This chapter will guide you though each component.
Please refer to existing bid adapters for working examples and practical guidance, but understand that our adapter interfaces and coding style evolve over time. Please prefer the examples in this document over differences you may find in code.
Our project is written in the Java programming language. Please try your best and we’ll respectfully steer you in the right direction during the review process.
Please do not ignore errors from method calls made in your bid adapter code. Even if it’s seemingly impossible for an error to occur, it’s still possible under the high throughput multi-threaded nature of Prebid Server.
Let’s begin with your adapter’s bidder information YAML file. This file is required and contains your maintainer email address, specifies the ad formats your adapter will accept, and other params.
Create a file with the path static/bidder-info/{bidder}.yaml
and begin with the following template:
adapters:
yourBidderCode:
endpoint: http://possible.endpoint
endpoint-compression: gzip (or none)
meta-info:
maintainer-email: maintainer@email.com
app-media-types:
- banner
- video
- audio
- native
site-media-types:
- banner
- video
- audio
- native
supported-vendors:
vendor-id: your_vendor_id
usersync:
cookie-family-name: yourBidderCode
iframe:
url: https://some-bidder-domain.com/usersync-url?gdpr=&consent=&us_privacy=&redirect=
uid-macro: 'YOURMACRO'
support-cors: false
redirect:
url: https://some-bidder-domain.com/usersync-url?gdpr=&consent=&us_privacy=&redirect=
uid-macro: 'YOURMACRO'
support-cors: false
Modify this template for your bid adapter:
modifying-vast-xml-allowed
value to false
if you’d like to opt out of video impression tracking. It defaults to true
.pbs-enforces-ccpa
to false
if you’d like to disable ccpa enforcement. Defaults to true
.vendor-id
value to id of your bidding server as registered with the GDPR Global Vendor List (GVL). Leave this as 0
if you are not registered with IAB Europe.supported-vendors
constants: These constants should be unique. The list of existing vendor constants can be found here.capabilities
(app/site) and mediaTypes
(banner/video/audio/native) combinations which your adapter does not support.If you does not support user syncing, you can remove usersync
section of configuration.
cookie-family-name
to the name which will be used for storing your user sync id within the federated cookie. Please keep this the same as your bidder name.In appropriate usersync section:
url
to url of your usersync endpointuid-macro
to macro that will be placed in callback endpoint, to be resolved by your usersyncer. Defaults to empty string.support-cors
to true if your endpoint supports cors.The url of your user syncer can make use of the following macros which will be resolved by Prebid Server before sending the url to your server:
{{us_privacy}}
: Client’s CCPA consent string.{{gdpr}}
: Client’s GDPR TCF enforcement flag.{{gdpr_consent}}
: Client’s GDPR TCF consent string.{{redirect_url}}
: Url to redirect back to Prebid Server.Prebid Server has default configuration for common bidder properties, which can be overriden by bidders in their configurations.
Default configuration:
adapter-defaults:
enabled: false
pbs-enforces-ccpa: true
modifying-vast-xml-allowed: true
There are also some default properties which can’t be overridden in adapter-defaults, but rather in particular adapter’s config:
aliases
: Defaults to emptydeprecated-names
: Defaults to emptyextra-info
: Defaults to emptyIf you want to add bidder that is an alias of existing bidder, you need just to update configuration of parent bidder:
Example of adding bidder alias:
adapters:
yourBidderCode:
...
aliases:
yourBidderAlias:
endpoint: http://possible.alias/endpoint
app-media-types:
- banner
- video
site-media-types:
- banner
- video
usersync:
cookie-family-name: yourBidderCode
Aliases are configured by adding child configuration object at adapters.yourBidderCode.aliases.yourBidderAlias
Aliases support the same configuration options that their bidder counterparts support except aliases
(i.e. it’s not possible
to declare alias of an alias).
Aliases cannot declare support for media types not supported by their parent bidders
However aliases could narrow down media types they support.
For example: if the bidder is written to not support native site requests, then an alias cannot magically decide to change that;
However, if a bidder supports native site requests, and the alias does not want to for some reason, it has the ability to remove that support.
Your bid adapter might require extra information from the publisher to form a request to your bidding server. The bidder parameters JSON Schema codifies this information to allow Prebid Server to verify requests and to provide an API for third party configuration systems.
Publishers will provide extra information using an OpenRTB 2.5 Bid Request Extension, preferably at request.imp[].ext.prebid.bidder.{bidder}
but also supported at request.imp[].ext.{bidder}
. Prebid Server will validate the publisher information based on your schema and relocate the data to request.imp[].ext.bidder
, regardless of your bidder name or the publisher’s chosen location.
We request that you do not duplicate information that is already present in the OpenRTB 2.5 Bid Request specification or is already part of an established Prebid convention. For example, your bidder parameters should not include first party data, bid floors, schain, video parameters, referrer information, or privacy consent including COPPA, CCPA, and GDPR TCF. For video parameters in particular, you must prefer the OpenRTB 2.5 Bid Request standard of request.imp[].video
.
ENDPOINT NOTE: You may not use an endpoint domain as a bidder parameter. Prebid Server is not an open proxy. If absolutely necessary, you may specify a portion of the domain as a parameter to support geo regions or account specific servers. However, this is discouraged and may degrade the performance of your adapter since the server needs to maintain more outgoing connections. Host companies may choose to disable your adapter if it uses a dynamically configured domain.
Create a file with the path static/bidder-params/{bidder}.json
using JSON Schema to define your bidder parameters. Prebid Server requires this file for every adapter, even if yours doesn’t require bidder parameters (see the ‘no parameters’ example at the end of this section).
Let’s start with this example which defines one required placementId
string parameter:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Foo Adapter Params",
"description": "A schema which validates params accepted by the Foo adapter",
"type": "object",
"properties": {
"placementId": {
"type": "string",
"description": "Placement ID"
}
},
"required": ["placementId"]
}
We encourage you to utilize the full features of JSON Schema to narrowly define your bidder parameter data types. If you copy and paste these examples, please remember to change the title
and description
to refer to your bidder name instead of our fictional Foo example.
When choosing your parameter names, please consider aligning with the OpenRTB 2.5 standard by using lower case letters without camel casing or special characters.
In addition to the examples listed below, please refer to existing bidder parameter files for guidance.
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Foo Adapter Params",
"description": "A schema which validates params accepted by the Foo adapter",
"type": "object",
"properties": {}
}
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Foo Adapter Params",
"description": "A schema which validates params accepted by the Foo adapter",
"type": "object",
"properties": {
"placementId": {
"type": "integer",
"minimum": 1,
"description": "Placement ID"
}
},
"required": ["placementId"]
}
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Foo Adapter Params",
"description": "A schema which validates params accepted by the Foo adapter",
"type": "object",
"properties": {
"token": {
"type": "string",
"description": "Token"
},
"account": {
"type": "string",
"description": "Account",
"pattern": "^([a-fA-F\\d]+)$"
}
},
"required": ["token"]
}
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Foo Adapter Params",
"description": "A schema which validates params accepted by the Foo adapter",
"type": "object",
"properties": {
"token": {
"type": "string",
"description": "Token"
},
"secret": {
"secret": "string",
"description": "Secret"
}
},
"oneOf": [
{ "required": ["token"] },
{ "required": ["secret"] }
]
}
You can skip this step if your adapter has no bidder parameters.
If you’ve defined bidder parameters for your adapter, you also need to represent your bidder parameters in code. The core framework uses the JSON Schema file for validation, but your adapter code needs a data structure to support JSON serialization / deserialization. These data structures are organized in a shared path using a standard naming convention, which also serves as documentation of all adapter parameters.
Create a file with the path org.prebid.server.proto.openrtb.ext.request.{bidder}.ExtImp{bidder}.java
containing an exported (must start with an upper case letter) data structure named ImpExt{Bidder}
. All required and optional bidder parameters from the JSON Schema should be represented as fields.
For example, this is what the bidder parameter code looks like for the example we used in the previous section:
/**
* Defines the contract for bidrequest.imp[i].ext.{bidder}
*/
@AllArgsConstructor(staticName = "of")
@Value
public class ExtImp{bidder}{
@JsonProperty("jsonName")
Double property;
String secondProperty;
}
Please follow Java standard naming convention for the field names (particularly for acronyms) and use `@JsonProperty`
attributes to specify the JSON name, matching exactly what you defined in the bidder parameters JSON Schema. Please keep in mind that JSON is case sensitive.
Now it’s time to write the bulk of your bid adapter code.
Each adapter has its own directory (a ‘package’ in java parlance) for all code and tests associated with translating an OpenRTB 2.5 Bid Request to your bidding server’s protocol and mapping your server’s response to an OpenRTB 2.5 Bid Response. The use of separate packages provide each adapter with its own naming scope to avoid conflicts and gives the freedom to organize files as you best see fit (although we make suggestions in this guide).
Create a file with the path org.prebid.server.bidder.{bidder}/{bidder}Bidder.java
. Your bid adapter code will need to implement Bidder
Bidder<T>
interface consisting of the MakeHttpRequests
method to create outgoing requests to your bidding server and the MakeBids
method to create bid responses.Here is a reference implementation for a bidding server which uses the OpenRTB 2.5 protocol:
package org.prebid.server.bidder.{bidder};
import com.iab.openrtb.request.BidRequest;
import com.iab.openrtb.request.Imp;
import com.iab.openrtb.response.BidResponse;
import com.iab.openrtb.response.SeatBid;
import io.vertx.core.http.HttpMethod;
import org.apache.commons.collections4.CollectionUtils;
import org.prebid.server.bidder.Bidder;
import org.prebid.server.bidder.model.BidderBid;
import org.prebid.server.bidder.model.BidderError;
import org.prebid.server.bidder.model.HttpCall;
import org.prebid.server.bidder.model.HttpRequest;
import org.prebid.server.bidder.model.Result;
import org.prebid.server.exception.PreBidException;
import org.prebid.server.json.DecodeException;
import org.prebid.server.json.JacksonMapper;
import org.prebid.server.proto.openrtb.ext.response.BidType;
import org.prebid.server.util.HttpUtil;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* {bidder} {@link Bidder} implementation.
*/
public class {bidder}Bidder implements Bidder<BidRequest> {
private final String endpointUrl;
private final JacksonMapper mapper;
public {bidder}Bidder(String endpointUrl, JacksonMapper mapper) {
this.endpointUrl = HttpUtil.validateUrl(Objects.requireNonNull(endpointUrl));
this.mapper = Objects.requireNonNull(mapper);
}
@Override
public Result<List<HttpRequest<BidRequest>>> makeHttpRequests(BidRequest request) {
return Result.withValue(HttpRequest.<BidRequest>builder()
.method(HttpMethod.POST)
.uri(endpointUrl)
.headers(HttpUtil.headers())
.payload(request)
.body(mapper.encode(request))
.build()));
}
@Override
public final Result<List<BidderBid>> makeBids(HttpCall<BidRequest> httpCall, BidRequest bidRequest) {
try {
final BidResponse bidResponse = mapper.decodeValue(httpCall.getResponse().getBody(), BidResponse.class);
return Result.withValues(extractBids(httpCall.getRequest().getPayload(), bidResponse));
} catch (DecodeException | PreBidException e) {
return Result.withError(BidderError.badServerResponse(e.getMessage()));
}
}
private static List<BidderBid> extractBids(BidRequest bidRequest, BidResponse bidResponse) {
if (bidResponse == null || CollectionUtils.isEmpty(bidResponse.getSeatbid())) {
return Collections.emptyList();
}
return bidsFromResponse(bidRequest, bidResponse);
}
private static List<BidderBid> bidsFromResponse(BidRequest bidRequest, BidResponse bidResponse) {
return bidResponse.getSeatbid().stream()
.filter(Objects::nonNull)
.map(SeatBid::getBid)
.filter(Objects::nonNull)
.flatMap(Collection::stream)
.map(bid -> BidderBid.of(bid, getBidType(bid.getImpid(), bidRequest.getImp()), bidResponse.getCur()))
.collect(Collectors.toList());
}
private static BidType getBidType(String impId, List<Imp> imps) {
BidType bidType = BidType.banner;
for (Imp imp : imps) {
if (imp.getId().equals(impId)) {
if (imp.getBanner() != null) {
return bidType;
} else if (imp.getVideo() != null) {
bidType = BidType.video;
} else if (imp.getXNative() != null) {
bidType = BidType.xNative;
} else if (imp.getAudio() != null) {
bidType = BidType.audio;
}
}
}
return bidType;
}
}
The MakeHttpRequests
method is responsible for returning zero or more HTTP requests to be sent to your bidding server. Bid adapters are forbidden from directly initiating any form of network communication and must entirely rely upon the core framework. This allows the core framework to optimize outgoing connections using a managed pool and record networking metrics. The return type adapters.RequestData
allows your adapter to specify the HTTP method, url, body, and headers.
This method is called once by the core framework for bid requests which have at least one valid Impression for your adapter. Impressions not configured for your adapter will be removed and are not accessible.
The argument, request
, is the OpenRTB 2.5 Bid Request object. Extension information is stored as com.fasterxml.jackson.databind.node.ObjectNode
byte arrays and must be converted from node to be read and/or mutated. It is critical to understand that the request
object contains pointers to shared memory. If your adapter needs to alter any data referenced by a pointer then you must first make a shallow copy(you can do it by using toBuilder() method on model you want to change, but remember about objects like Lists and always create copy’s of this data types). The exact same instance of the request
object is also passed to the MakeBids
method, so please be careful when mutating. It’s safe to assume that request.Imp[]
always contains at least one element and that the request.Imp[].ext.bidder
was successfully validated by your bidder parameter JSON Schema.
// Populate the top level width and height of a banner request if it's not set by the publisher.
final List<Format> format = banner.getFormat();
if (banner.getW() == null && banner.getH() == null && CollectionUtils.isNotEmpty(format)) {
final Format firstFormat = format.get(0);
final Banner modifiedBanner = banner.toBuilder().w(firstFormat.getW()).h(firstFormat.getH()).build();
return imp.toBuilder().banner(modifiedBanner).build();
}
The MakeHttpRequests
method is expected to return a List<HttpRequest<BidRequest>
object representing the HTTP calls to be sent to your bidding server and a List<BidderError> errors
for any issues encountered creating them. If there are no HTTP calls or if there are no errors, please use different methods in Result
class specific to your case.
An Impression may define multiple sizes and/or multiple ad formats. If your bidding server limits requests to a single ad placement, size, or format, then your adapter will need to split the Impression into multiple calls and merge the responses.
@Override
public Result<List<HttpRequest<BidRequest>>> makeHttpRequests(BidRequest request) {
final List<HttpRequest<BidRequest>> httpRequests = new ArrayList<>();
for (Imp imp : request.getImp()) {
final BidRequest outgoingRequest = request.toBuilder().imp(Collections.singletonList(imp)).build();
httpRequests.add(HttpRequest.<BidRequest>builder()
.method(HttpMethod.POST)
.uri(endpointUrl)
.headers(HttpUtil.headers())
.payload(outgoingRequest)
.body(mapper.encode(outgoingRequest))
.build());
}
return Result.withValues(httpRequests);
}
If your bidding server supports multiple currencies, please be sure to pass through the request.cur
field. If your bidding server only bids in a single currency, such as USD or EUR, that’s fine. Prebid Server will convert your bid to the request currency if you include it in the bid response, otherwise we assume USD and conversion will not occur.
Please ensure you forward the bid floor (request.imp[].bidfloor
) and bid floor currency (request.imp[].bidfloorcur
) values to your bidding server for enforcement.
There are a several values of a bid request that publishers may supply that your adapter and endpoint should be aware of. Some are defined by the OpenRTB 2.5 specification and some are defined by Prebid conventions:
Parameter | Definer | Path & Description |
---|---|---|
CCPA | OpenRTB |
request.regs.ext.us_privacy The publisher is specifying the California Consumer Privacy Act consent string. |
COPPA | OpenRTB |
request.regs.ext.us_privacy The publisher is specifying the Children’s Online Privacy Protection flag. |
ATTS | OpenRTB |
request.device.ext.atts The App Tracking Transparency Status set on the device (iOS only). |
SKAdNetwork | OpenRTB |
request.imp[].ext.skadn The SKAdNetwork signaling to support mobile attribution when a user’s IDFA is unavailable for iOS traffic. |
Currency | OpenRTB |
request.cur The publisher is specifying the desired bid currency. The Prebid Server default is USD. |
Debug | Prebid |
request.ext.prebid.debug The publisher is requesting verbose debugging information from Prebid Server. |
First Party Data (FPD) | Prebid |
request.imp[].ext.context.data.* , request.app.ext.data.* , request.site.ext.data.* , request.user.ext.data.* The publisher may provide first party data (e.g. keywords). |
GDPR | OpenRTB |
request.regs.ext.gdpr , request.user.ext.consent The publisher is specifying the European General Data Protection Regulation flag and TCF consent string. |
Site or App | OpenRTB |
request.site , request.app The publisher will provide either the site or app, but not both, representing the client’s device. |
Supply Chain | OpenRTB |
request.source.ext.schain The publisher’s declaration of all parties who are selling or reselling the bid request. |
Test | OpenRTB |
request.test The publisher is sending non-production traffic which also enables verbose debugging information from Prebid Server. |
Video | OpenRTB |
request.imp[].video The publisher is specifying video ad requirements or preferences. |
Rewarded inventory | OpenRTB |
request.imp[].ext.prebid.is_rewarded_inventory Signal to indicate the inventory is rewarded. |
If you want your request body to be GZIP compressed, you should add Content-Encoding
header with gzip
value.
private static MultiMap resolveHeaders() {
return HttpUtil.headers()
.add(HttpUtil.CONTENT_ENCODING_HEADER, HttpHeaderValues.GZIP);
}
The MakeBids
method in your adapter is responsible for parsing the bidding server’s response and mapping it to the OpenRTB 2.5 Bid Response object model.
This method is called for each response received from your bidding server within the bidding window (request.tmax
). If there are no requests or if all requests time out, the MakeBids
method will not be called.
It’s imperative to include all required information in the response for your bid to be accepted. Please avoid common mistakes, such as not specifying the bid currency and not properly detecting the media type from the bidding server response.
The first argument, HttpCall
, is the HTTP response received from your bidding(contains the status code, body, and headers) and also specific to your bid HttpRequest<T>
request. If your bidding server replies with a GZIP encoded body, it will be automatically decompressed.
The second argument, request
, is the exact same OpenRTB 2.5 Bid Request object provided to (and potentially mutated by) the MakeRequests
method. The information in the request
may be useful when detecting the media type.
The MakeBids
method is expected to return an Result
object with one or more bids mapped from your bidding server’s response. This may be as simple as decorating an OpenRTB 2.5 Bid Response with a some Prebid Server metadata (such as the media type) or more complicated mapping logic depending on your server’s response format.
Please review the entire OpenRTB 2.5 Bid Response documentation to fully understand the response object model and expectations. We’ve summarized some common fields below. Data which is listed as required is enforced by the core framework and cannot be omitted.
BidderResponse Path | Scope | Description |
---|---|---|
.Currency |
Required | 3-letter ISO 4217 code defining the currency of the bid. The Prebid Server default is USD. |
.Bids[].BidType |
Required | Prebid Server defined value identifying the media type as banner , video , audio , or native . Should be mapped from the bidding server response. |
.Bids[].Bid.ADomain |
Optional | Advertiser domain for block list checking. |
.Bids[].Bid.AdM |
Optional | Ad markup to serve if the bid wins. May be HTML, Native, or VAST/VMAP formats. You should resolve any AUCTION_PRICE macros. |
.Bids[].Bid.CrID |
Required | Unique id of the creative. |
.Bids[].Bid.ID |
Required | Bidder generated id to assist with logging and tracking. |
.Bids[].Bid.ImpID |
Required | ID of the corresponding bid request Impression. Prebid Server validates the id is actually found in the bid request. |
.Bids[].Bid.Price |
Required | Net price CPM of the bid, not gross price. Publishers can correct for gross price bids by setting Bid Adjustments to account for fees. We recommend the most granular price a bidder can provide. |
.Bids[].Bid.W |
Optional | Width of the creative in pixels. |
.Bids[].Bid.H |
Optional | Height of the creative in pixels. |
.Bids[].Bid.Ext.Prebid.Meta |
Optional | Embedded JSON containing Prebid metadata (see below) or custom information. |
We recommend resolving creative OpenRTB macros in your adapter. Otherwise, AUCTION_PRICE will eventually get resolved by the Prebid Universal Creative, but by then the bid price will be in the ad server currency and quantized by the price granularity.
If you’d like to support Long Form Video Ad Pods, then you’ll need to provide the followings information:
BidderResponse Path | Description |
---|---|
.Bids[].BidVideo.PrimaryCategory |
Category for the bid. Should be able to be translated to the primary ad server format. |
.Bids[].Bid.Cat |
Category for the bid. Should be able to be translated to the primary ad server format. |
.Bids[].BidVideo.Duration |
Length of the video in integer seconds. |
.Bids[].DealPriority |
Deal tier integer value. Defaults to 0. |
Either .Bids[].BidVideo.PrimaryCategory
or .Bids[].Bid.Cat
should be provided.
In order to share granular bid response data with publishers, analytics, and reporting systems, we’ve introduced a standard object model. We encourage adapters to provide as much information as possible in the bid response.
Bid metadata will be required in Prebid.js 5.X+ release, specifically for bid.ADomain and MediaType. We recommend making sure your adapter sets these values or Prebid.js may throw out the bid.
Path | Description |
---|---|
.DemandSource |
Bidder-specific demand source |
.NetworkID |
Bidder-specific network/DSP id |
.NetworkName |
Bidder-specific network/DSP name |
.AgencyID |
Bidder-specific agency id |
.AgencyName |
Bidder-specific agency name |
.AdvertiserID |
Bidder-specific advertiser id |
.AdvertiserName |
Bidder-specific advertiser name |
.BrandID |
Bidder-specific brand id for advertisers with multiple brands |
.BrandName |
Bidder-specific brand name |
.dchain |
Demand Chain Object |
.PrimaryCategoryID |
Primary IAB category id |
.SecondaryCategoryIDs |
Secondary IAB category ids |
.MediaType |
Either banner , audio , video , or native . This is used in the scenario where a bidder responds with a mediatype different than the stated type. e.g. native when the impression is for a banner. One use case is to help publishers determine whether the creative should be wrapped in a safeframe. |
The seatnonbid feature allows analytics adapters to piece together what happened in the auction when there’s not a bid. This can be helpful to everyone involved: the publisher can get insight into why a bidder might not be bidding, which might lead them to update bid parameters or otherwise fix a setup problem.
To implement this enhanced analytics, bidders just need to link errors and non-bids to a specific impression id:
makeHttpRequests
method of bidder adapter class, utilize .impIds(Set<String>)
method of HttpRequest<T>
class. (hint, if bidder uses ortb as its main protocol it can utilize impIds
method of BidderUtil
class), for example:</br>
HttpRequest.<BidRequest>builder()
.method(HttpMethod.POST)
.uri(uri)
.body(mapper.encodeToBytes(bidRequest))
.headers(headers)
.payload(bidRequest)
.impIds(BidderUtil.impIds(bidRequest))
.build();
or more generic case:</br>
HttpRequest.<YourModel>builder()
.method(HttpMethod.POST)
.uri(uri)
.body(mapper.encodeToBytes(bidRequest))
.headers(headers)
.payload(bidRequest)
.impIds(Set.of(impId1, impId2))
.build();
makeHttpRequests
or bid in makeBids
methods in bidder adapter class, and emits error, it should provide ids of impressions that particular error covers. Bidder adapter can do this by utilizing BidderError.of(String message, Type type, Set<String> impIds)
method of BidderError
class, or by creating/using specialized methods of this class, for example:
BidderError.rejectedIpf(
"Bid with id '%s' was rejected by floor enforcement: price %s is below the floor %s"
.formatted(bid.getId(), price, floor), impId);
(Note: list of specialized methods like this will increase as needed, but bidders can contribute by extending this list.)</br></br>or more generic case:</br>
BidderError.of(
"Impression with id '%s' was dropped due to ...".formatted(impId),
BidderError.Type.bad_input,
Collections.sinleton(impId));
Note: If bidder provides PBS with impression id that was not present in provided BidRequest
, PBS will just ignore it.
Go to org.prebid.server.spring.config.bidder
and create new class Configuration{bidder}
with the following content
package org.prebid.server.spring.config.bidder;
import org.prebid.server.bidder.BidderDeps;
import org.prebid.server.bidder.{bidder}.{bidder}Bidder;
import org.prebid.server.json.JacksonMapper;
import org.prebid.server.spring.config.bidder.model.BidderConfigurationProperties;
import org.prebid.server.spring.config.bidder.util.BidderDepsAssembler;
import org.prebid.server.spring.config.bidder.util.UsersyncerCreator;
import org.prebid.server.spring.env.YamlPropertySourceFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import javax.validation.constraints.NotBlank;
@Configuration
@PropertySource(value = "classpath:/bidder-config/{bidder}.yaml", factory = YamlPropertySourceFactory.class)
public class {bidder}Configuration {
private static final String BIDDER_NAME = "{bidder}";
@Bean("{bidder}ConfigurationProperties")
@ConfigurationProperties("adapters.{bidder}")
BidderConfigurationProperties configurationProperties() {
return new BidderConfigurationProperties();
}
@Bean
BidderDeps{bidder}BidderDeps(BidderConfigurationProperties {bidder}ConfigurationProperties,
@NotBlank @Value("${external-url}") String externalUrl,
JacksonMapper mapper) {
return BidderDepsAssembler.forBidder(BIDDER_NAME)
.withConfig({bidder}ConfigurationProperties)
.usersyncerCreator(UsersyncerCreator.create(externalUrl))
.bidderCreator(config -> new {bidder}Bidder(config.getEndpoint(), mapper))
.assemble();
}
}
Prebid Server is a global product that is currency agnostic. Publishers may ask for bids in any currency. It’s totally fine if your bidding endpoint only supports a single currency, but your adapter needs to deal with it. This section will describe how to do so.
Here are 3 key points to consider:
If you need to convert floor prices from one currency into something your endpoint expects, you can use the convertCurrency function from CurrencyConversionService component.
1) Inject CurrencyConversionService to your {bidder}Configuration class and pass it to your bidder constructor.
@Autowired
private CurrencyConversionService currencyConversionService;
...
.bidderCreator(() -> new {bidder}Bidder(configProperties.getEndpoint(), currencyConversionService, mapper))
2) Create additional class variable private final CurrencyConversionService currencyConversionService;
and update constructor in your {bidder}Bidder class to set this variable.
private final CurrencyConversionService currencyConversionService;
private final String endpointUrl;
private final JacksonMapper mapper;
public {bidder}Bidder(String endpointUrl, CurrencyConversionService currencyConversionService, JacksonMapper mapper) {
this.endpointUrl = HttpUtil.validateUrl(Objects.requireNonNull(endpointUrl));
this.currencyConversionService = Objects.requireNonNull(currencyConversionService);
this.mapper = Objects.requireNonNull(mapper);
}
3) Use currencyConversionService.convertCurrency(BigDecimal price, BidRequest bidRequest, String fromCurrency, String toCurrency)
for currency converting in {bidder}Bidder class.
private Imp makeImp(Imp imp, BidRequest bidRequest) {
return imp.toBuilder().bidfloor(resolveBidFloor(imp, bidRequest)).build();
}
private BigDecimal resolveBidFloor(Imp imp, BidRequest bidRequest) {
final String bidFloorCurrency = resolveBidFloorCurrency(imp);
final BigDecimal bidFloor = imp.getBidfloor();
return convertBidFloorCurrency(imp, bidRequest, bidFloor, bidFloorCurrency);
}
private BigDecimal convertBidFloorCurrency(Imp imp, BidRequest bidRequest, BigDecimal bidFloor, String bidFloorCurrency) {
try {
return currencyConversionService.convertCurrency(bidFloor, bidRequest,
bidFloorCurrency, "NEEDED_CURRENCY");
} catch (PreBidException ex) {
throw new PreBidException(String.format("Failed to convert bidfloor with a reason: %s", ex.getMessage()));
}
}
Prebid server manages the OpenRTB floors values (imp.bidfloor and imp.bidfloorcur) at the core level using the Price Floors feature. Minimally, bid adapters are expected to read these values and pass them to the endpoint.
However, as described in the feature documentation, some adapters may benefit from access to more granular values. The primary use case is for multi-format as detailed in the document. To implement this, you may use the overloaded getFloor()
function which can use more specific values for certain fields.
Here are the instructions:
1) Inject PriceFloorResolver
to your {bidder}Configuration class and pass it to your bidder constructor.
BidderDeps {bidder}BidderDeps(BidderConfigurationProperties {bidder}ConfigurationProperties,
@NotBlank @Value("${external-url}") String externalUrl,
PriceFloorResolver floorResolver,
JacksonMapper mapper) {
...
.bidderCreator(() -> new {bidder}Bidder(configProperties.getEndpoint(), floorResolver, mapper))
2) Create an additional class variable private final PriceFloorResolver floorResolver
and update constructor in your {bidder}Bidder class to set this variable.
private final PriceFloorResolver floorResolver;
private final String endpointUrl;
private final JacksonMapper mapper;
public {bidder}Bidder(String endpointUrl, PriceFloorResolver floorResolver, JacksonMapper mapper) {
this.endpointUrl = HttpUtil.validateUrl(Objects.requireNonNull(endpointUrl));
this.floorResolver = Objects.requireNonNull(floorResolver);
this.mapper = Objects.requireNonNull(mapper);
}
3) Use floorResolver.resolve(BidRequest bidRequest,
PriceFloorRules floorRules,
Imp imp,
ImpMediaType mediaType,
Format format,
List<String> warnings)
for resolving specific floor values in your {bidder}Bidder class.
private Imp makeImp(Imp imp, BidRequest bidRequest) {
final PriceFloorResult priceFloorResult = resolvePriceFloors(
bidRequest,
imp, // com.iab.openrtb.request.Imp
specificMediatype, // org.prebid.server.proto.openrtb.ext.request.ImpMediaType
specificFormat, // com.iab.openrtb.request.Format (size)
priceFloorsWarnings);
return imp.toBuilder()
.bidfloor(ObjectUtil.getIfNotNull(priceFloorResult, PriceFloorResult::getFloorValue))
.bidfloorcur(ObjectUtil.getIfNotNull(priceFloorResult, PriceFloorResult::getCurrency))
.build();
}
private PriceFloorResult resolvePriceFloors(BidRequest bidRequest,
Imp imp,
ImpMediaType mediaType,
Format format,
List<String> warnings) {
return floorResolver.resolve(
bidRequest,
extractFloorRules(bidRequest),
imp,
mediaType,
format,
warnings);
}
4) Let the Price Floors feature know about the floors you’re using. To do that, enrich BidderBid with priceFloorInfo
private static BidderBid createBidderBid(Bid bid, Imp imp, BidType bidType, String currency) {
return BidderBid.builder()
.bid(bid)
.type(bidType)
.bidCurrency(currency)
.priceFloorInfo(imp != null ? PriceFloorInfo.of(imp.getBidfloor(), imp.getBidfloorcur()) : null)
.build();
}
This chapter will guide you through the creation of automated unit and integration tests to cover your bid adapter code. We use GitHub Action Workflows to ensure the code you submit passes validation. You can run the same validation locally with this command:
mvn clean package
This command will prepare code style checks, compile, run test and create jar file from your code
Create class {bidder}BidderTest
in the same package as your {bidder}Bidder
class, but in test directory. Here you should add unit tests to your bid code.
Try to create models by using following methods specified to your case in your test class
private static BidRequest givenBidRequest(
UnaryOperator<BidRequest.BidRequestBuilder> bidRequestCustomizer,
UnaryOperator<Imp.ImpBuilder> impCustomizer) {
return bidRequestCustomizer.apply(BidRequest.builder()
.imp(singletonList(givenImp(impCustomizer))))
.build();
}
private static BidRequest givenBidRequest(UnaryOperator<Imp.ImpBuilder> impCustomizer) {
return givenBidRequest(identity(), impCustomizer);
}
private static Imp givenImp(UnaryOperator<Imp.ImpBuilder> impCustomizer) {
return impCustomizer.apply(Imp.builder()
.ext(mapper.valueToTree(ExtPrebid.of(null, ExtImp{bidder}.of(param, secondParam)))))
.build();
}
private static BidResponse givenBidResponse(UnaryOperator<Bid.BidBuilder> bidCustomizer) {
return BidResponse.builder()
.seatbid(singletonList(SeatBid.builder().bid(singletonList(bidCustomizer.apply(Bid.builder()).build()))
.build()))
.build();
}
private static HttpCall<BidRequest> givenHttpCall(BidRequest bidRequest, String body) {
return HttpCall.success(
HttpRequest.<BidRequest>builder().payload(bidRequest).build(),
HttpResponse.of(200, null, body),
null);
}
Go to test-application.properties
file and add folowing properties
adapters.{bidder}.enabled=true
adapters.{bidder}.endpoint=http://localhost:8090/{bidder}-exchange
adapters.{bidder}.usersync.url=//{bidder}-usersync
Go to test resources org.prebid.server.it.openrtb2
and create directory with {bidder}
name.
Add files with content specific to your case:
1) test-auction-{bidder}-request.json
{
"id": "tid",
"imp": [
{
"id": "impId001",
"banner": {
"format": [
{
"w": 300,
"h": 250
}
]
},
"ext": {
"{bidder}": {
"param": "paramValue"
}
}
}
],
"device": {
"pxratio": 4.2,
"dnt": 2,
"language": "en",
"ifa": "ifaId"
},
"site": {
"publisher": {
"id": "publisherId"
}
},
"at": 1,
"tmax": 5000,
"cur": [
"USD"
],
"source": {
"fd": 1,
"tid": "tid"
},
"ext": {
"prebid": {
"targeting": {
"pricegranularity": {
"precision": 2,
"ranges": [
{
"max": 20,
"increment": 0.1
}
]
}
},
"cache": {
"bids": {}
},
"auctiontimestamp": 1000
}
},
"regs": {
"ext": {
"gdpr": 0
}
}
}
2) test-auction-{bidder}-response.json
{
"id": "tid",
"seatbid": [
{
"bid": [
{
"id": "bid001",
"impid": "impId001",
"price": 3.33,
"adm": "adm001",
"adid": "adid001",
"cid": "cid001",
"crid": "crid001",
"w": 300,
"h": 250,
"ext": {
"prebid": {
"type": "banner",
"targeting": {
"hb_pb": "3.30",
"hb_size_{bidder}": "300x250",
"hb_bidder_{bidder}": "{bidder}",
"hb_cache_path": "",
"hb_size": "300x250",
"hb_cache_host_{bidder}": "",
"hb_cache_path_{bidder}": "",
"hb_cache_id_{bidder}": "f0ab9105-cb21-4e59-b433-70f5ad6671cb",
"hb_bidder": "{bidder}",
"hb_cache_id": "f0ab9105-cb21-4e59-b433-70f5ad6671cb",
"hb_pb_{bidder}": "3.30",
"hb_cache_host": ""
},
"cache": {
"bids": {
"url": "f0ab9105-cb21-4e59-b433-70f5ad6671cb",
"cacheId": "f0ab9105-cb21-4e59-b433-70f5ad6671cb"
}
}
}
}
}
],
"seat": "{bidder}",
"group": 0
}
],
"cur": "USD",
"ext": {
"responsetimemillis": {
"{bidder}": " {bidder}.response_time_ms }}",
"cache": ""
},
"prebid": {
"auctiontimestamp": 1000
},
"tmaxrequest": 5000
}
}
3) test-{bidder}-bid-request.json
{
"id": "tid",
"imp": [
{
"id": "impId001",
"banner": {
"format": [
{
"w": 300,
"h": 250
}
]
},
"ext": {
"bidder": {
"param": "paramValue"
}
}
}
],
"site": {
"domain": "example.com",
"page": "http://www.example.com",
"publisher": {
"id": "publisherId"
},
"ext": {
"amp": 0
}
},
"device": {
"ua": "userAgent",
"dnt": 2,
"ip": "193.168.244.1",
"pxratio": 4.2,
"language": "en",
"ifa": "ifaId"
},
"user": {
"buyeruid" : "BTW-UID"
},
"at": 1,
"tmax": 5000,
"cur": [
"USD"
],
"source": {
"fd": 1,
"tid": "tid"
},
"regs": {
"ext": {
"gdpr": 0
}
},
"ext": {
"prebid": {
"targeting": {
"pricegranularity": {
"precision": 2,
"ranges": [
{
"max": 20,
"increment": 0.1
}
]
},
"includewinners": true,
"includebidderkeys": true
},
"cache": {
"bids": {}
},
"auctiontimestamp": 1000,
"channel" : {
"name" : "web"
}
}
}
}
4) test-{bidder}-bid-response.json
{
"id": "tid",
"seatbid": [
{
"bid": [
{
"id": "bid001",
"impid": "impId001",
"price": 3.33,
"adid": "adid001",
"crid": "crid001",
"cid": "cid001",
"adm": "adm001",
"h": 250,
"w": 300
}
]
}
]
}
5) test-cache-{bidder}-request.json
{
"puts": [
{
"type": "json",
"value": {
"id": "bid001",
"impid": "impId001",
"price": 3.33,
"adm": "adm001",
"adid": "adid001",
"cid": "cid001",
"crid": "crid001",
"w": 300,
"h": 250
}
}
]
}
6) test-cache-{bidder}-response.json
{
"responses": [
{
"uuid": "f0ab9105-cb21-4e59-b433-70f5ad6671cb"
}
]
}
Create class {bidder}Test
in test directory in package org.prebid.server.it
. Extend IntegrationTest
class with following content
package org.prebid.server.it;
import io.restassured.response.Response;
import org.json.JSONException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.junit4.SpringRunner;
import java.io.IOException;
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
import static com.github.tomakehurst.wiremock.client.WireMock.equalToJson;
import static com.github.tomakehurst.wiremock.client.WireMock.post;
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
import static java.util.Collections.singletonList;
@RunWith(SpringRunner.class)
public class {bidder}Test extends IntegrationTest {
@Test
public void openrtb2AuctionShouldRespondWithBidsFrom{bidder}() throws IOException, JSONException {
// given
WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/{bidder}-exchange"))
.withRequestBody(equalToJson(jsonFrom("openrtb2/{bidder}/test-{bidder}-bid-request.json")))
.willReturn(aResponse().withBody(jsonFrom("openrtb2/{bidder}/test-{bidder}-bid-response.json"))));
// pre-bid cache
WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/cache"))
.withRequestBody(equalToJson(jsonFrom("openrtb2/{bidder}/test-cache-{bidder}-request.json")))
.willReturn(aResponse().withBody(jsonFrom("openrtb2/{bidder}/test-cache-{bidder}-response.json"))));
// when
final Response response = responseFor("openrtb2/{bidder}/test-auction-{bidder}-request.json",
Endpoint.OPENRTB2_AUCTION);
// then
assertJsonEquals("openrtb2/{bidder}/test-auction-{bidder}-response.json", response, singletonList("{bidder}"));
}
}
Uids for cookie you can create using this link
Configure, build and start your server.
Then POST
an OpenRTB Request to http://localhost:8000/openrtb2/auction
.
If at least one request.imp[i].ext.{bidder}
is defined in your Request, then your bidder should be called.
To test user syncs, call /setuid using the FamilyName of your Bidder.
The next time you use /openrtb2/auction
, the OpenRTB request sent to your Bidder should have
BidRequest.User.BuyerUID
with the value you saved.
Human readable documentation for bid adapters is required in the separate prebid.github.io repository. We will not merge your bid adapter until you’ve at least opened a documentation PR and comment with a link to it.
pbs: true
variable in the header section. If your Prebid Server bidding parameters are different from your Prebid.js parameters, please include the differences in this document for publishers to be aware.---
layout: bidder
title: {bidder}
description: Prebid {Bidder} Bidder Adapter
biddercode: {bidder}
gdpr_supported: true/false
gvl_id: 111
usp_supported: true/false
coppa_supported: true/false
gpp_supported: true/false
schain_supported: true/false
dchain_supported: true/false
userId: <list of supported vendors>
media_types: banner, video, audio, native
safeframes_ok: true/false
deals_supported: true/false
floors_supported: true/false
fpd_supported: true/false
pbjs: true/false
pbs: true/false
pbs_app_supported: true/false
prebid_member: true/false
multiformat_supported: will-bid-on-any, will-bid-on-one, will-not-bid
ortb_blocking_supported: true/partial/false
---
### Registration
The Example Bidding adapter requires setup before beginning. Please contact us at setup@example.com
### Bid Params
{: .table .table-bordered .table-striped }
| Name | Scope | Description | Example | Type |
|---------------|----------|--------------|-----------|----------|
| `placementId` | required | Placement ID | `'11111'` | `string` |
Notes on the metadata fields:
pbs: true
. If you also have a Prebid.js bid adapter, add pbjs: true
. Default is false for both.gvl_id
. No default.gdpr_supported: true
. Default is false.usp_supported: true
. Default is false.userId: (list of supported vendors)
. Default is none.media_types: video, native, audio
. Note that display is added by default. If you don’t support display, add “no-display” as the first entry, e.g. media_types: no-display, native
. No defaults.coppa_supported: true
. Default is false.gpp_supported: true
. Default is false.schain_supported: true
. Default is false.dchain_supported: true
. Default is false.safeframes_ok: false
. This will alert publishers to not use safeframed creatives when creating the ad server entries for your bidder. No default.pbs_app_supported
: true. No default value.deals_supported: true
. No default value.floors_supported: true
. No default value.fpd_supported: true
. No default value.ortb_blocking_supported
to ‘true’,’partial’, or ‘false’. No default value. In order to set ‘true’, you must support: bcat, badv, battr, and bapp.prebid_member: true
. Default is false.resources/bidder-config/{bidder}.yaml
resources/org/prebid/server/it/test-application.properties
(test directory)resources/static/bidder-params/{bidder}.json
org/prebid/server/proto/openrtb/ext/request/{bidder}/ExtImp{bidder}.java
org/prebid/server/bidder/{bidder}/{bidder}Bidder.java
org/prebid/server/bidder/{bidder}/{bidder}BidderTest.java
(test directory)org/prebid/server/it/{bidder}Test.java
(test directory)resources/org/prebid/server/it/openrtb2/{bidder}/test-auction-{bidder}-request.json
(test directory)resources/org/prebid/server/it/openrtb2/{bidder}/test-auction-{bidder}-response.json
(test directory)resources/org/prebid/server/it/openrtb2/{bidder}/test-{bidder}-bid-request.json
(test directory)resources/org/prebid/server/it/openrtb2/{bidder}/test-{bidder}-bid-response.json
(test directory)resources/org/prebid/server/it/openrtb2/{bidder}/test-cache-{bidder}-request.json
(test directory)resources/org/prebid/server/it/openrtb2/{bidder}/test-cache-{bidder}-response.json
(test directory)org/prebid/server/spring/config/bidder/{bidder}Configuration.java
Whew! You’re almost done. Thank you for taking the time to develop a Prebid Server bid adapter. When you’re ready, contribute your new bid adapter by opening a PR to the PBS-Java GitHub repository with the name “New Adapter: {Bidder}”.
You don’t need to ask permission or open a GitHub issue before submitting an adapter.