> 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/javascript-api/relevantdigital.addadscallbacks.md).

# relevantDigital.addAdsCallbacks()

Use `relevantDigital.addAdsCallbacks()` to register ad-server-independent slot event listeners. These events also fire when Relevant Yield renders a winning bid directly.

### When to use it

Use this API when direct rendering is enabled. Ad-server event listeners alone cannot reliably show whether an ad was rendered.

For example, a Google Ad Manager `slotRenderEnded` event can report `isEmpty: true` when the ad server returns no ad. A winning Prebid bid may still render directly. Use these callbacks for logic such as hiding an ad container.

For direct-rendering guidance, see [Implementation and testing guidelines for direct rendering](/technical/integration/advanced-implementation-patterns/implementation-and-testing-guidelines-for-direct-rendering.md).

### Event order

Each slot triggers these events once, in order:

1. `slotRequested`
2. `slotResponseReceived`
3. `slotRenderEnded`

The events have the same meaning as the [Google Ad Manager JavaScript API](https://developers.google.com/publisher-tag/reference). Their names stay consistent across supported ad servers.

### Example

```
window.relevantDigital = window.relevantDigital || {};
relevantDigital.cmd = relevantDigital.cmd || [];
relevantDigital.cmd.push(function() {
    const printEvent = (type, ev, adUnitInstance) => {
        console.info(`********** ${type} **********`);
        console.info('Event: ', ev);
        console.info('AdUnitInstance (if any): ', adUnitInstance);
        console.info('Is direct rendering: ', ev.directRender);
        console.info('Direct rendered bid: ', ev.bid);
        console.info('Ad slot: ', ev.slot);
        console.info('Is empty: ', ev.isEmpty);
    };
    relevantDigital.addAdsCallbacks({
        slotRequested: (...args) => {
            printEvent('slotRequested', ...args);
        },
        slotResponseReceived: (...args) => {
            printEvent('slotResponseReceived', ...args);
        },
        slotRenderEnded: (ev, data) => {
            printEvent('slotRenderEnded', ev, data);
        },
    });
});
```

### Event data

#### `adUnitInstance`

Contains Relevant Yield placement data. It is `null` for slots loaded outside [relevantDigital.loadPrebid()](/technical/integration/javascript-api/relevantdigital.loadprebid.md), or for slots loaded with `loadUnknownSlots: true`.

#### Direct rendering fields

For directly rendered bids, `ev.directRender` and `ev.bid` may be available.

### Ad-server-specific event data

#### Google Ad Manager

When an ad request is made and no bid renders directly, all three events use the Google Ad Manager event objects. Otherwise, the event object can differ.

#### Microsoft Advertising (Xandr)

When the ad server triggers the event, `ev.ad` contains the Xandr ad object.


---

# 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/javascript-api/relevantdigital.addadscallbacks.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.
