onSlotAndUnit
Overview
This article outlines a method by which a publisher can retrieve information from the gpt slot setup and pass it into the pbjs adUnit object. This can be useful for certain specific bidder requirements.
This example involves the use of the 'onSlotAndUnit' callback. A callback function that will be invoked for every slot that will participate in the auction.
Using the onSlotAndUnit exposes; 'slot' the gpt slot object, 'unit' information on the placement settings in yield, the auction object. From there 'unit' object we can retrieve the pbAdUnit which is where we can set extra adUnit informaiton to be passed to pbjs.
Code
relevantDigital.addAuctionCallbacks({
onSlotAndUnit: ({ slot, unit }) => {
const path = slot.getAdUnitPath();
const tgtArray = slot.getTargetingMap();
const newObj = unit.pbAdUnit.newObj = {};
const tgtValue = tgtArray.tgtValue[0];
newObj.adUnitPath = path;
newObj.targeting = {key: tgtValue}
}
});
Walk-through
Opposed to demonstrating the usecase in relevantDigital.loadPrebid(), the code is using relevantDigital.addAuctionCallbacks instead. The addAuctionCallbacks function is useful for implementing callback functions in scenarios where it may not be possible to edit relevantDigital.loadPrebid().
onSlotAndUnit is a callback function that will be invoked for every slot that will participate in the auction. onSlotAndUnit exposes; 'slot' the gpt slot object, 'unit' information on the placement settings in yield, the auction object.
From the 'slot' object we can use the gpt functions to retrieve gpt slot information to be passed to the pbAdUnit. In this example we use 'getAdunitPath()' and 'slot.getTargetingMap()' to retrieve the fulll path of the gam slot and the targeting that will be set on this slot respectively
From there 'unit' object we can retrieve the pbAdUnit which is where we can set extra adUnit informaiton to be passed to pbjs (prebid AdUnit setup).