1. Help Center
  2. HB Manager
  3. Applications & Use-cases

Modify / Enrich pbjs.adUnit Object 2: Add GPID

onSlotAndUnit

Overview

This article outlines a method by which a publisher can modify the pbjs.adUnit object to pass the GPID.

In this example we can use the onSlotAndUnit callback, invoked for all slots that will participate in the auction before the pbjs.adUnit setup is done.

Code

relevantDigital.addAuctionCallbacks({
    onSlotAndUnit: ({ slot, unit }) => {
        const path = slot.getAdUnitPath();
        const ortb2 = unit.pbAdUnit.ortb2Imp = {};
        const ext = ortb2.ext = {};
        ext.gpid = path;
        ext.data = { pbadslot: gpid + "#" + 'somethingUnique'};
    }
});

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 callback, invoked for all slots that will participate in the auction (before the pbjs.adUnit setup is done), unless the callback returns false, in which case the slot will be skipped. onSlotAndUnit callback exposes slot & unit information; the 'slot' information pertaining to all the google publisher tag (gpt) setup and 'unit' to all information in the UI for that slot.

From the slot information we can retrieve the gam path using getAdUnitPath(), which is both used as the ext.gpid value, but also in the ext.data.pbadslot.

The 'unit' data contains a 'pbAdUnit' object, this will be the object that becomes the pbjs.adUnit object, so it can be edited at this stage. In the case above a ortb2Imp object is added, including nested ext & data objects.

The gam path, previously retrieved using getAdUnitPath(), is then set to the ext & data objects. 

The exact formatting of the data object will depend on the 'uniqueness' of your gam paths / ad slot setup as described here.