You are here: Developers > Third-party containers > Prebid.js adapter

Prebid.js adapter

Last updated on December 28, 2017

Prebid.js is a free and open source library for publishers to quickly implement header biddingA monetization tool that exposes each impression to programmatic demand before calling the ad server. This lets publishers realize the true value of their direct and indirect inventory in real time.. OpenX's adapter allows OpenX to participate as a demand source within this solution. (http://prebid.org)

This topic will guide you through the following:

Note: You must be using Prebid.js version 0.34.0 or later.

Implementation

  1. Follow Prebid's Step by step guide to DFP setup.
  2. Provide your OpenX representative answers to the following questions:
    1. Which display ad sizes do you plan to use?
    2. Are you using other adapters?

    Also, consult with your OpenX representative to ensure OpenX is listed correctly in your ads.txt file.

  3. Customize and download your prebid.js code with the OpenX bidder adapter selected.
  4. Configure bidder: 'openx' using the properties in the table below.
      
    var adUnits = [{       
       code: 'div-gpt-ad-1438287399331-0',
       mediaTypes: {banner: 
          {sizes: [[728, 90]]}
       },       
       bids: [{             
          bidder: 'openx',             
    	  params: {
             unit: '1611023122',               
             delDomain: 'PUBLISHER-d.openx.net',
             customFloor: 1.50,
             customParams: {
                key1: 'v1',
                key2: ['v2', 'v3']
             }            
          }           
       }]     
    }];

    Property

    Type

    Description

    Required?

    delDomain

    String

    OpenX delivery domain provided by your OpenX representative.

    For example: 'PUBLISHER-d.openx.net'

    Required

    unit

    String

    OpenX ad unitThe smallest inventory component that represents the space on a site where ads display. ID provided by your OpenX representative.

    For example: '1611023122'

    Required

    customFloor

    Number

    Minimum price in USD. customFloor applies to a specific unit.

    For example, use the following value to set a $1.50 floorThe minimum price a publisher is willing to accept for a given impression.: 1.50

    Note: Supported in Prebid.js version 0.30.0 or later.

    Optional

    customParams

    Object

    User-defined targeting key-value pairs. customParams applies to a specific unit.

    For example: {key1: 'v1', key2: ['v2','v3']}

    Note: Supported in Prebid.js version 0.30.0 or later.

    Optional

  5. Add the following code to enable user syncing. By default, Prebid.js version 0.34.0+ turns off user syncing through iframes. OpenX strongly recommends enabling user syncing through iframes. This functionality improves DSPDemand-side platform, a platform or provider that allows advertisers to manage multiple ad exchange and data exchange accounts through one interface, often in real time. user match rates and increases the OpenX bid rate and bid price. Be sure to call pbjs.setConfig() only once.
    
    pbjs.setConfig({ 
       userSync: {
          iframeEnabled: true
       }
    });
  6. Send a test page to your OpenX representative for review.

Full code sample


<html>
<head>
   <script> 
      var PREBID_TIMEOUT = 700;
      var adUnits = [{       
         code: 'div-gpt-ad-1438287399331-0',       
         sizes: [[728, 90]],
         mediaTypes: {banner: {}},       
         bids: [{             
            bidder: 'openx',             
            params: {
               unit: '1611023122',               
               delDomain: 'PUBLISHER-d.openx.net',
               customFloor: 1.50,
               customParams: {
                  key1: 'v1',
                  key2: ['v2', 'v3']
               }            
            }           
         }]     
      }];
    
      var pbjs = pbjs || {};
      pbjs.que = pbjs.que || [];

   </script>

   <script>
      var googletag = googletag || {};googletag.cmd = googletag.cmd || [];
      googletag.cmd.push(function() {
         googletag.pubads().disableInitialLoad();
      });

      pbjs.que.push(function() {
         pbjs.addAdUnits(adUnits);
         pbjs.setConfig({
            priceGranularity:"dense"			 
            userSync: {
               iframeEnabled: true
            }
		 });
         pbjs.requestBids({
            bidsBackHandler: sendAdserverRequest
         });
      });

      function sendAdserverRequest() {
         if (pbjs.adserverRequestSent) return;
         pbjs.adserverRequestSent = true;
         googletag.cmd.push(function() {
            pbjs.que.push(function() {
               pbjs.setTargetingForGPTAsync();
               googletag.pubads().refresh();
            });
         });
      }

      setTimeout(function() {
         sendAdserverRequest();
      }, PREBID_TIMEOUT);

   </script>

   <script>
      (function () {
         var gads = document.createElement('script');
         gads.async = true;
         gads.type = 'text/javascript';
         var useSSL = 'https:' == document.location.protocol;
         gads.src = (useSSL ? 'https:' : 'http:') + '//www.googletagservices.com/tag/js/gpt.js';
         var node = document.getElementsByTagName('script')[0];
         node.parentNode.insertBefore(gads, node);
      })();
   </script>

   <script>
      googletag.cmd.push(function () {
         googletag.defineSlot('/90577858/prebid_auid', [[728, 90]], 'div-gpt-ad-1438287399331-0').addService(googletag.pubads());
         googletag.pubads().enableSingleRequest();
         googletag.enableServices();
      });
   </script>
</head>

<body>
<div id='div-gpt-ad-1438287399331-0'>
   <script type='text/javascript'>
      googletag.cmd.push(function() {  
         googletag.display('div-gpt-ad-1438287399331-0'); 
      });
   </script>
</div>

</body>
</html>

Best practices

Feedback form