Getting Started

Quick Start

The easiest way to get started with Prebid.js is using the following JSFiddle example. Go to the “Result” tab to see the keyword targeting for this header auction.

This example uses a test version of Prebid.js hosted on our CDN that is not recommended for production use. It includes all available adaptors. Production implementations should build from source or customize the build using the Download page to make sure only the necessary bidder adaptors are included.

For more information on how to setup your ad server, see the Ad Ops Guide.


More Details

1. Register bidder tag IDs

In a simple JSON config, define a mapping of the bidders’ tag Ids to your ad units. Load prebid.js library async. Call pbjs.requestBids() to send header bidding requests async to all bidders you’ve specified.

<script src="prebid.js" async></script>
pbjs.que.push(function() {
  var adUnits = [{
	code: "div-gpt-ad-1438287399331-0",
	sizes: [[300, 250], [300, 600]],
	bids: [{
	  bidder: "rubicon",
	  params: {
		accountId: "4934",
		siteId: "13945",
		zoneId: "23948",
		sizes: [15]
	  }
	}, {
	  bidder: 'sovrn',
	  params: { tagId: '315045' }
	}, {
	  bidder: "appnexus",
	  params: { placementId: "234235" }
	}]
  }];
  pbjs.addAdUnits(adUnits);

  pbjs.requestBids({
	bidsBackHandler: function() {
	  // callback when requested bids are all back
	}
  });
});

2. Set the ad server timeout

Define the timeout to let your ad server wait for a few hundred milliseconds, so the bidders can respond with bids.

PREBID_TIMEOUT = 300;
function sendAdserverRequest() {
    (function() {
        // Send ad server ad request here
    })();
};
setTimeout(initAdserver, PREBID_TIMEOUT);

3. Set bid targeting

Call the helper function setTargetingForGPTAsync() to handle all the targeting for all bidders.

pbjs.que.push(function() {
  pbjs.setTargetingForGPTAsync();
});


Next Step (Full Example):

View or download a full example with line by line code walkthrough!