forked from prebid/prebid.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RAD-1766: Docs for adding a bidder adapter to Prebid Server (prebid#324)
* Start 'Add a Bidder Adapter to Prebid Server' * Finish first draft of Prebid Server adapter docs * Add final (mandatory) integration step
- Loading branch information
1 parent
811e1cf
commit 439216c
Showing
1 changed file
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
--- | ||
layout: page | ||
title: Add a Bidder Adapter to Prebid Server | ||
description: Add a Bidder Adapter to Prebid Server | ||
pid: 28 | ||
top_nav_section: dev_docs | ||
nav_section: prebid-server | ||
--- | ||
|
||
<div class="bs-docs-section" markdown="1"> | ||
|
||
# Add a Bidder Adapter to Prebid Server | ||
{:.no_toc} | ||
|
||
This page describes how to write the code for a bidder adapter that integrates with [Prebid Server]({{site.baseurl}}/dev-docs/get-started-with-prebid-server.html). | ||
|
||
* TOC | ||
{:toc} | ||
|
||
## Step 1. Get the source code and build the API docs | ||
|
||
When writing your adapter it may be useful to refer to: | ||
|
||
- Autogenerated API documentation | ||
- Existing bidder adapter code | ||
|
||
For autogenerated API documentation using [`godoc`](http://godoc.org/golang.org/x/tools/cmd/godoc), run the following commands: | ||
|
||
``` | ||
$ git clone https://github.com/prebid/prebid-server | ||
$ cd prebid-server/ | ||
$ godoc ./adapters/ | ||
``` | ||
|
||
To read the source code of the existing adapters, see [the prebid-server repo](https://github.com/prebid/prebid-server/tree/master/adapters) (either on GitHub or your own machine, of course). | ||
|
||
## Step 2. Build Prebid Server and run the tests | ||
|
||
To build Prebid Server, see the instructions in the [README](https://github.com/prebid/prebid-server/tree/master/README.md). | ||
|
||
As of this writing, when you run `go test`, you end up testing everything in the project. To test just the adapter code, run: | ||
|
||
``` | ||
$ go test ./adapters/ | ||
``` | ||
|
||
If everything goes as planned, you should see something like: | ||
|
||
``` | ||
ok github.com/prebid/prebid-server/adapters 0.098s | ||
``` | ||
|
||
A failing test will look something like the following (I triggered this failure by changing the bidder code for the AppNexus adapter to an invalid value): | ||
|
||
``` | ||
--- FAIL: TestAppNexusBasicResponse (0.01s) | ||
appnexus_test.go:326: ParsePBSRequest returned invalid bidder | ||
body {"account_id":"","tid":"","cache_markup":0,"sort_bids":0,"max_key_length":0,"secure":0,"timeout_millis":0,"ad_units":[{"code":"first-tag","is_top_frame":0,"sizes":[{"w":300,"h":250}],"bids":[{"bidder":"audienceNetwork","bid_id":"random-id-from-pbjs-0","params":{"placementId":"987654321_999998888"}}],"config_id":""},{"code":"second-tag","is_top_frame":0,"sizes":[{"w":300,"h":250}],"bids":[{"bidder":"audienceNetwork","bid_id":"random-id-from-pbjs-1","params":{"placementId":"987654321_66775544"}}],"config_id":""}],"is_debug":false,"app":null,"device":null,"Start":"0001-01-01T00:00:00Z"} | ||
``` | ||
|
||
## Step 3. Understand the adapter interface | ||
|
||
Now that you have the `godoc` output (and have [`adapter.go`](https://github.com/prebid/prebid-server/tree/master/adapters/adapter.go) available to read), you can see that the interface you need to implement is: | ||
|
||
{: .table .table-bordered .table-striped } | ||
| Name | Description | | ||
|-------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ||
| `Name` | Returns the code name of the adapter, a string -- must match the bidder code in Prebid.js | | ||
| `FamilyName` | Returns a string used to build the OpenRTB bid request; used for cookie management | | ||
| `GetUsersyncInfo` | Returns user sync info for this bidder. For more information about user syncing, see [What is Cookie Syncing and How Does it Work?](http://clearcode.cc/2015/12/cookie-syncing/) | | ||
| `SkipNoCookies` | Returns a boolean value that answers: Should this adapter be called if there is no user ID on the impression? | | ||
| `Call` | Takes the request from the client and produces a bid request that is then sent to the adapter's external server. | | ||
|
||
Other things to keep in mind include: | ||
|
||
- Your adapter must be in the `adapters` package | ||
- Your adapter's constructor (e.g., `NewYourBidderAdapter`) needs to accept an HTTP adapter config that controls how it makes requests to your bidder | ||
|
||
## Step 4. Write code and tests | ||
|
||
There's enough variation among bidders that we can't tell you exactly how to write the code. To see how it's done, refer to the [adapters in the repo](https://github.com/prebid/prebid-server/tree/master/adapters/), their tests, and the interface documentation. | ||
|
||
The file naming conventions are: | ||
|
||
+ `yourbidder.go`: implementation | ||
+ `yourbidder_test.go`: tests | ||
|
||
## Step 5. Register your adapter with Prebid Server | ||
|
||
Finally, in order for Prebid Server to integrate your adapter, it has to be added to the list of adapters in [the implementation of `setupExchanges`](https://github.com/prebid/prebid-server/blob/master/pbs_light.go#L625). | ||
|
||
## Further Reading | ||
|
||
+ [Get Started with Prebid Server]({{site.baseurl}}/dev-docs/get-started-with-prebid-server.html) | ||
|
||
</div> |