This module enables bidder targeting and tracking at the ad server ad slot level.
This module is enabled by default if it’s compiled into your PBJS package. It will add the Prebid Ad Slot and GPID along with the matching GAM ad unit name to each ad unit’s first-party data before bid requests are sent to the adapters.
The Prebid Ad Slot didn’t get broad adoption, so it’s likely that someday we’ll deprecate it in favor of the more standard GPID.
Unlike many other modules, the GPT Pre-Auction Module is on by default if it’s compiled into the Prebid.js package.
Optional initialization parameters:
Param | Required? | Type | Description | Example |
enabled | no | boolean | allows turning off of module. Default value is true | true |
customGptSlotMatching | no | function | GPT slot matching function should match the customSlotMatching function sent to setTargetingForGptAsync | |
useDefaultPreAuction | no | boolean | (PBJS 6.5+) If true, use default behavior for determining GPID and PbAdSlot. Defaults to false. | true |
customPreAuction | no | function | (PBJS 6.5+) Custom function for defining the GPID and PbAdSlot. | |
customPbAdSlot | no | function | Custom PB AdSlot function. (Note, this function will be deprecated in the future.) | |
mcmEnabled | no | boolean | Removes extra network IDs when Multiple Customer Management is active. Default is false. | true |
For example:
pbjs.setConfig({
gptPreAuction: {
enabled: true, // enabled by default
useDefaultPreAuction: false,
customPreAuction: function(adUnit, adServerAdSlot) {
...
return "customPbAdSlot";
},
customGptSlotMatching: function(gptSlotObj) {
...
return true; // or false
},
mcmEnabled: true
}
});
When this module is turned on, it uses the BEFORE_REQUEST_BIDS event to insert functionality that:
If GPT slot matching succeeds:
Here’s what the module does to define these values:
In PBJS 6.5 and later, we recommend using the useDefaultPreAuction flag or the customPreAuction function.
The following customPbAdSlot function will work for many publishers. Assumptions:
If either of these isn’t the case, you’ll need to supply your own function.
// Use adunit.ortb2Imp.ext.data.pbadslot if it exists.
// compare adunit.code to find a single matching slot in GPT
// if there is a single slot match, just use that slot name
// finally, there must be multiple slots that match. Define pbadslot as slot#div
pbjs.setConfig({
gptPreAuction: {
enabled: true, // enabled by default
customPbAdSlot: function(adUnitCode, adServerAdSlot) {
// get adunit object
au=pbjs.adUnits.filter(au => au.code==adUnitCode);
if (au.length==0) {
return;
}
// use pbadslot if supplied
if (au[0].ort2bImp && au[0].ort2bImp.ext && au[0].ort2bImp.ext.data && au[0].ort2bImp.ext.data.pbadslot) {
return au[0].ort2bImp.ext.data.pbadslot;
}
// confirm that GPT is set up
if (!(googletag && googletag.apiReady)) {
return;
}
// find all GPT slots with this name
var gptSlots = googletag.pubads().getSlots().filter(function(gpt) {
return gpt.getAdUnitPath() == adServerAdSlot;
});
if (gptSlots.length==0) {
return; // should never happen
}
if (gptSlots.length==1) {
return adServerAdSlot;
}
// else the adunit code must be div id. append it.
return adServerAdSlot+"#"+adUnitCode;
}
}
});