To add Google Ad Exchange (AdX) demand to your Prebid setup, you need to integrate the Google Ad Manager (GAM) with Prebid.js. Here’s a step-by-step guide to help you set it up:
Step 1: Set Up Google Ad Manager (GAM)
- Ensure you have a Google Ad Manager account with Ad Exchange enabled.
- Create Ad Units in GAM for the placements where you want to serve ads.
- Create Line Items and Orders:
- Create Price Priority line items for direct-sold campaigns.
- Create Header Bidding line items for Prebid demand.
- Ensure the Header Bidding line items have the correct pricing and targeting.
Step 2: Configure Prebid.js
1. Install Prebid.js:
- Include the Prebid.js library in your website. You can use the Prebid.js CDN or host it yourself.
<script async src="https://cdn.jsdelivr.net/npm/prebid.js@latest/dist/not-for-prod/prebid.js"></script>
2. Configure Ad Units:
- Define your ad units in the Prebid.js configuration. Each ad unit should match the ad unit codes in GAM.
var adUnits = [{
code: 'div-gpt-ad-123456789-0', // Match this with your GAM ad unit code
mediaTypes: {
banner: {
sizes: [[300, 250], [728, 90]]
}
},
bids: [{
bidder: 'gam',
params: {
adUnitCode: 'div-gpt-ad-123456789-0', // Match with GAM ad unit code
sizes: [[300, 250], [728, 90]]
}
}]
}];
3. Enable Google Ad Manager as a Bidder:
- Add the
gam
bidder to your Prebid.js configuration.
var pbjs = pbjs || {};
pbjs.que = pbjs.que || [];
pbjs.que.push(function() {
pbjs.addAdUnits(adUnits);
pbjs.setConfig({
debug: true,
enableSendAllBids: true // Send all bids to GAM
});
pbjs.requestBids({
timeout: 1000,
bidsBackHandler: function() {
pbjs.setTargetingForGPTAsync();
googletag.pubads().refresh();
}
});
});
4. Enable Send All Bids:
- Ensure
enableSendAllBids
is set totrue
in thesetConfig
method. This sends all bids to GAM for header bidding.
Step 3: Set Up GPT (Google Publisher Tag)
1. Include GPT in Your Page:
- Add the GPT script to your website.
<script async src="https://securepubads.g.doubleclick.net/tag/js/gpt.js"></script>
2. Define GPT Ad Slots:
- Define ad slots that match your Prebid ad units.
googletag.cmd.push(function() {
googletag.defineSlot('/123456789/div-gpt-ad-123456789-0', [[300, 250], [728, 90]], 'div-gpt-ad-123456789-0').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
Step 4: Test Your Setup
1. Check the Console:
- Use your browser’s developer tools to check for errors in the console.
2. Verify Bids:
- Use the Prebid.js debug mode (
pbjs.setConfig({ debug: true })
) to verify that bids are being sent and received correctly.
3. Check GAM:
- Ensure that the bids are being passed to GAM and that the correct line items are being triggered.
Step 5: Optimize and Monitor
1. Adjust Timeouts:
- Adjust the
timeout
inpbjs.requestBids
to balance latency and yield.
2. Monitor Performance:
- Use Prebid Analytics or GAM reporting to monitor the performance of your header bidding setup.
3. Add More Bidders:
- Consider adding more demand partners to increase competition and revenue.
Example Full Configuration
<script async src="https://cdn.jsdelivr.net/npm/prebid.js@latest/dist/not-for-prod/prebid.js"></script>
<script async src="https://securepubads.g.doubleclick.net/tag/js/gpt.js"></script>
<script>
var adUnits = [{
code: 'div-gpt-ad-123456789-0',
mediaTypes: {
banner: {
sizes: [[300, 250], [728, 90]]
}
},
bids: [{
bidder: 'gam',
params: {
adUnitCode: 'div-gpt-ad-123456789-0',
sizes: [[300, 250], [728, 90]]
}
}]
}];
var pbjs = pbjs || {};
pbjs.que = pbjs.que || [];
pbjs.que.push(function() {
pbjs.addAdUnits(adUnits);
pbjs.setConfig({
debug: true,
enableSendAllBids: true
});
pbjs.requestBids({
timeout: 1000,
bidsBackHandler: function() {
pbjs.setTargetingForGPTAsync();
googletag.pubads().refresh();
}
});
});
googletag.cmd.push(function() {
googletag.defineSlot('/123456789/div-gpt-ad-123456789-0', [[300, 250], [728, 90]], 'div-gpt-ad-123456789-0').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>
By following these steps, you should be able to successfully integrate Google Ad Exchange demand into your Prebid setup.