How to Implement Header Bidding
A complete guide to implementing header bidding on your website using Prebid.js, from initial setup to advanced optimization techniques.
What You'll Learn
- What header bidding is and why it matters
- Step-by-step Prebid.js implementation
- Configuring demand partners
- Timeout optimization
- Testing and going live
What is Header Bidding?
Header bidding is an advanced programmatic advertising technique that allows publishers to offer their ad inventory to multiple ad exchanges simultaneously before making calls to their ad servers. This creates a more competitive auction environment, typically resulting in higher CPMs and increased revenue.
Unlike the traditional waterfall method where ad networks are called sequentially, header bidding enables real-time competition among all demand sources, ensuring you get the highest possible bid for each impression.
Prerequisites
Before implementing header bidding, ensure you have:
- An active Google Ad Manager (GAM) account
- Access to your website's HTML/JavaScript
- Accounts with at least 3-5 demand partners (SSPs)
- Basic understanding of JavaScript and ad operations
Step 1: Download and Include Prebid.js
First, download Prebid.js from prebid.org with the adapters you need for your demand partners.
<!-- Add to your <head> section -->
<script async src="https://cdn.example.com/prebid.js"></script>
<script>
var pbjs = pbjs || {};
pbjs.que = pbjs.que || [];
</script>Step 2: Configure Ad Units
Define your ad units with the sizes and bidders you want to include:
var adUnits = [{
code: 'div-gpt-ad-1234567890',
mediaTypes: {
banner: {
sizes: [[300, 250], [300, 600]]
}
},
bids: [{
bidder: 'appnexus',
params: { placementId: '12345678' }
}, {
bidder: 'rubicon',
params: { accountId: '1234', siteId: '5678', zoneId: '9012' }
}]
}];Step 3: Set Timeout and Request Bids
Configure your timeout (we recommend 1000ms to start) and initiate the bid request:
pbjs.que.push(function() {
pbjs.setConfig({
priceGranularity: 'dense',
enableSendAllBids: true
});
pbjs.addAdUnits(adUnits);
pbjs.requestBids({
bidsBackHandler: sendAdserverRequest,
timeout: 1000
});
});Step 4: Configure Google Ad Manager
Create line items in GAM to capture Prebid bids. You'll need line items for each price bucket:
- Create a new Order for "Prebid Header Bidding"
- Create line items for price ranges ($0.01-$0.05, $0.05-$0.10, etc.)
- Set targeting to match hb_pb key-values
- Add creatives that render the winning bid
Step 5: Test Your Implementation
Before going live, thoroughly test your setup:
- Use Prebid Debug mode:
pbjs.setConfig({debug: true}); - Check browser console for bid responses
- Verify bids are being sent to GAM
- Test on multiple browsers and devices
Optimization Tips
Start with 5-8 bidders
Too many bidders increase latency without proportional revenue gains
Optimize timeout
Monitor timeout rates and adjust between 400-1000ms based on performance
Use lazy loading
Only request bids for ads about to enter the viewport
Monitor bidder performance
Remove bidders with low bid rates or high latency
Need Help With Implementation?
Our team can help you implement and optimize header bidding for maximum revenue.