Audience Network Display Bidding with Prebid.js

This guide outlines how to use Prebid.js's open source wrapper with the Audience Network API to access Audience Network Demand for mobile web display.

Integration Steps

Step 1: Setup Prebid.js

Step 2: Setup DFP

Step 3: Raw Request / Response details

Step 4: Testing and Troubleshooting


  • A signed addendum
  • A Facebook Audience Network App ID that is approved for Header Bidding
  • Your domain added and approved for Audience Network
  • Existing Prebid.js wrapper integration with other demand partners already integrated

For Audience Network account setup details, you can review the Getting started guide.

1. Setup Prebid.js

var adUnits = [{
  code: 'div-gpt-ad-1486479040361-0',
  sizes: [[300, 250]],
  bids: [{
    bidder: 'audienceNetwork',
    params: {
     placementId: '<YOUR_PLACEMENT_ID>',
  • Set up bidder settings (fb_bidid if using Audience Network tag in DFP, hb_adid if using the Prebid Snippet in DFP):
pbjs.bidderSettings = {
          audienceNetwork: {
            adserverTargeting: [
                      key: "fb_bidid",
                      val: function (bidResponse) {
                          // make the bidId available for targeting if required
                          return bidResponse.fb_bidid;
                      key: "hb_bidder",
                      val: function (bidResponse) {
                          return bidResponse.bidderCode;
                    key: "hb_pb",
                    val: function(bidResponse) {
                      return bidResponse.pbMg;

2. Setup DFP

Fetch and Display the Ads

For each ad unit won by Audience Network, manipulate the DOM with Javascript to inject an iframe at the relevant tag. The iframe’s document needs customizing for each placement, passing in the placement ID, the bid ID, and the size for banner ads. The iframe must be friendly and non-sandboxed. If an iframe is not required, use only the first <div> tag from each example (stripping off the <html><head>...</head><body> and </body></html> tags). The ad should be requested and displayed within 10 minutes of the bid being issued. For ad units served directly (not through DFP), the iframe’s document should be:
    <div style="display:none;">
      <script type="text/javascript" src="" async></script>
      <script type="text/javascript">
        window.ADNW = window.ADNW || {};
        window.ADNW.v60 = window.ADNW.v60 || {};
        window.ADNW.v60.slots = window.ADNW.v60.slots || [];
          rootElement: document.currentScript.parentElement,
          placementid: '%%PATTERN:fb_placementid%%',
          format: '%%PATTERN:fb_format%%', bidid: '%%PATTERN:fb_bidid%%', 
          testmode: false,
          onAdLoaded: function(rootElement) {
            console.log('Audience Network [%%PATTERN:fb_placementid%%] ad loaded');
   = 'block';
          onAdError: function(errorCode, errorMessage) {
            console.log('Audience Network [%%PATTERN:fb_placementid%%] error (' + errorCode + ') ' + errorMessage);

For units served via DFP but injected into the page by Prebid.js, set the DFP line-item's creative to:

var w = window;for (i = 0; i < 10; i++) {
w = w.parent;
  if (w.pbjs) {
    try {
      w.pbjs.renderAd(document, '%%PATTERN:hb_adid%%');
    } catch (e) {

3. Raw Request / Response details


We support 300x250 banner placements for Header Bidding.


A single call can request bids for multiple placements. There can be up to a maximum of ten placements; any additional placements will be ignored. Each placement needs to provide an ID and a format. Placement IDs should be unique within a single request unless you have Lazy Loading implemented on your site. Viewability for each Placement ID is taken into account when determining the bid request so keeping these unique is extremely important for optimal performance.

Example of Raw Request

Here's an example of a raw request with three 300x250 banner placements using different Placement IDs for each slot on the page:
sdk=6.0.web&/* placement 1 */
adformats[]=300x250&/* placement 2 */
adformats[]=300x250/* placement 3 */


We return a JSON object describing the bids.

  • errors holds a list of error messages, e.g. missing mandatory parameters, disabled placement, etc. Where the error affects a single placement only, it will be prefixed with the placement ID.
  • bids holds a map of placement ID to an array of bids (there may not be entries for all placement IDs or all bids requested per placement ID, e.g. for no bid).
  • Within each bid,
    • bid_id is a token needed to later fetch and display the ad associated with this bid. The token is valid for 10 minutes.
    • bid_price_cents is the bid value, in USD cents, on a CPM basis. E.g. if the bid is 711.2, then the CPM is $7.11, and we will pay 0.7 cents for this single impression.
  "errors": [
  "bids": {
    "123_456": [
        "placement_id": "123_456",
        "bid_id": "12345_67890",
        "bid_price_cents": 321.96265882399,
        "bid_price_currency": "usd",
        "bid_price_model": "cpm"
    "123_789": [
        "placement_id": "123_789",
        "bid_id": "12345_09876",
        "bid_price_cents": 711.28405256274,
        "bid_price_currency": "usd",
        "bid_price_model": "cpm"
        "placement_id": "123_789",
        "bid_id": "12345_60987",
        "bid_price_cents": 702.34565789214,
        "bid_price_currency": "usd",
        "bid_price_model": "cpm"

No Bids

We may choose not to bid on any request. Common reasons include not being able to match the user to a Facebook account, or the page not running in a mobile browser.

4. Testing and Troubleshooting

  • You can pass the ?anhb_testmode=true query string on the URL to force a dummy bid (with 9999 CPM) and fill
  • You can pass the ?pbjs_debug=true query string on the URL to print auction info to console