> For the complete documentation index, see [llms.txt](https://docs.relevant-digital.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.relevant-digital.com/technical/integration/advanced-implementation-patterns/add-the-gpid-to-pbjs.adunit.md).

# Add the GPID to \`pbjs.adUnit\`

## **Overview**

This article outlines a method by which a publisher can modify the pbjs.adUnit object to pass the [GPID](https://docs.prebid.org/features/pbAdSlot.html).

In this example we can use the [onSlotAndUnit](https://help.relevant-digital.com/knowledge/relevantdigital.loadprebid) callback, invoked for all slots that will participate in the auction before the pbjs.adUnit setup is done.

This can be used as an alternative or compliment to the [gptPreAuction](https://docs.prebid.org/dev-docs/modules/gpt-pre-auction.html) prebid module.

### **Code**

```
//Option 1 with unique 'pbadslot'

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'};
    }
});


//Option 2 baseline setup

relevantDigital.addAuctionCallbacks({

  onSlotAndUnit: ({ slot, unit }) => {
      if (!slot || !unit) return;

      const path = slot.getAdUnitPath();
      const pbAdUnit = unit.pbAdUnit;
      //Optional divId pickup for Adagio > pbjs.v9.50 and up.
      const divId = slot.getSlotElementId();

      pbAdUnit.ortb2Imp ??= {};
      pbAdUnit.ortb2Imp.ext ??= {};
      pbAdUnit.ortb2Imp.ext.data ??= {};

      //prebid spec
      pbAdUnit.ortb2Imp.ext.gpid = path;
      pbAdUnit.ortb2Imp.ext.data.pbadslot = path;


      // Optional Adagio-required fields > pbjs.v9.50 and up.
      pbAdUnit.ortb2Imp.ext.data.divId = divId;
      pbAdUnit.ortb2Imp.ext.data.placement = path;

  }

});

});

```

## **Walk-through**

Opposed to demonstrating the usecase in relevantDigital.loadPrebid(), the code is using [relevantDigital.addAuctionCallbacks](https://help.relevant-digital.com/knowledge/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](https://help.relevant-digital.com/knowledge/relevantdigital.loadprebid) 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](https://docs.prebid.org/features/pbAdSlot.html).

**Note:** Two code snippet options have been presented, one example for when you wish to modify 'pbadslot' with something unique, and another with the 'default' prebid specification.

You can simply copy and paste option 2 into your global custom JS in the RY UI should you wish to implement this.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.relevant-digital.com/technical/integration/advanced-implementation-patterns/add-the-gpid-to-pbjs.adunit.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
