The Prebid AdUnit ‘code’ is a mixed attribute that’s generally either the GPT slot name or the HTML div ID. The undecided nature of the ‘code’ makes it harder to utilize for reporting and auction targeting.
The Prebid Ad Slot
is an optional inventory management convention allowing publishers to supply a descriptive and stable label for each ad on the page. This makes it possible to have more granular reporting and better deal targeting.
The Prebid Ad Slot was introduced with Prebid.js 3.x.
pbAdSlot
.pbAdSlot
and can target deals to them.pbAdSlot
for more granular reporting.Example page function:
// Use adunit.fpd.context.pbAdSlot if it exists. Otherwise, if the
// the adunit.code is a div ID, then look for a data-adslotid attribute, then look a matching slot in GPT
// Otherwise, just use the AdUnit.code
var setPbAdSlot = function setPbAdSlot(adunits) {
// set pbAdSlot for all ad units
adUnits.forEach(function (adUnit) {
if (!adUnit.fpd) {
adUnit.fpd = {}
}
if (!adUnit.fpd.context) {
adUnit.fpd.context = {};
}
// use existing pbAdSlot if it is already set
if (adUnit.fpd.context.pbAdSlot) {
return;
}
// check if AdUnit.code has a div with a matching id value
const adUnitCodeDiv = document.getElementById(adUnit.code);
if (!adUnitCodeDiv) {
// try to retrieve a data element from the div called data-adslotid.
if (adUnitCodeDiv.dataset.adslotid) {
adUnit.fpd.context.pbAdSlot = adUnitCodeDiv.dataset.adslotid;
return;
}
// Else if AdUnit.code matched a div and it's a banner mediaType and googletag is present
if (adUnit.mediaType && typeof adUnit.mediaType === 'object' && adUnit.mediaType.banner && adUnit.mediaTypes.banner.sizes && window.googletag && googletag.apiReady) {
var gptSlots = googletag.pubads().getSlots();
// look up the GPT slot name from the div.
var linkedSlot = gptSlots.find(function (gptSlot) {
return (gptSlot.getSlotElementId() === adUnitCodeDiv.id);
});
if (linkedSlot) {
adUnit.fpd.context.pbAdSlot = linkedSlot.getAdUnitPath();
return;
}
}
}
// Else, just use the AdUnit.code, assuming that it's an ad unit slot
adUnit.fpd.context.pbAdSlot = adUnit.code;
};
};
pbjs.onEvent('beforeRequestBids', setPbAdSlot);
The Prebid Ad Slot is just a convention – it’s a form of adunit-specific first party data
stored under adunit.fpd.context.pbAdSlot
.
It can be utilized by any code ready to look for it.
It’s intended to be specified via Prebid.js in one of two ways:
The function could determine the pbAdSlot in any way that produces a stable value useful for targeting and reporting. Some scenarios that could be supported:
The OpenRTB location for the Prebid Ad Slot is imp[].ext.context.data.adslot
: