---
metadata:
  - name: generator
    content: Diplodoc Platform v5.52.0
alternate:
  - https://yandex.ru/support/adfox/en/monetization/script-features.md
  - https://yandex.ru/support/adfox/ru/monetization/script-features.md
  - href: en/monetization/script-features.md
    type: text/markdown
    title: Markdown version
  - href: ../llms.txt
    type: text/markdown
    title: llms.txt
---
> **Documentation Index:** Fetch the complete configuration index at https://yandex.ru/support/adfox/en/llms.txt

# Additional script features

## The onBidsReceived callback function {#callback}

In the `YaHeaderBiddingSettings` method, the `onBidsReceived` callback function is available. It's called when the monetizer survey ends and bids are received.

The argument passed is an array of `Bids` objects, containing bids received from the last request to monetizers.

A [new request](*new-request) to the monetizers and its completion triggers the callback function again.


{% cut "Example of adding the onBidsReceived function" %}


```javascript
window.YaHeaderBiddingSettings = {
  biddersMap: adfoxBiddersMap,
  adUnits: adUnits,
  timeout: userTimeout,
  callbacks: {
    onBidsReceived: (bids) => {
      console.log('---> PUBLIC CALLBACK onBidsReceived: ', bids);
    }
  }
};
```


{% endcut %}



## A solution for sites with “infinite” scroll {#endless-scroll}

On sites with infinite scroll, new content and new ad placements load without reloading the page. If you use Header Bidding on pages of this kind of a site, there's no auction for new ad placements. This is because the bids were made at the initial page response and were already used for ad selection.

To describe a new set of monetizers for new ad placements that are added as new responses, use the `window.Ya.headerBidding.pushAdUnits(AdUnit[])` method. Instead of [AdUnit[]](https://yandex.ru/support/adfox/en/monetization/script-setup.md#create), you need to specify an array of objects with information about which monetizers can be requested to bid for newly added ad placements.

1. Before calling the method for a new ad placement, add initialization of new queues. To do this, replace the context.js loader code in the `head` element:

    #| 
    || **Old code** | **New code** || 
    || 
      ```html
      
      
      ``` 
    |  
      ```html
      
      
      ```
    ||
    |#.
    
1. Add the `pushAdUnits` method to the block code. Please note:
    - For a new banner placement, the `pushAdUnits` method must be called before `adfoxCode.create`.
    - In the object description, the elements' `containerId` must differ from those previously saved in the configuration script, but you don't need to change the configuration script itself in the page `head`.
    


{% cut "Example of a final code for an ad unit" %}


```html
<div id="adfox_15218"></div>

```


{% endcut %}



## Enable custom targeting via Adfox HB {#targetings-adfox-hb}

<!-- source: en/_includes/monetization/script-features/targetings-adfox.md -->
If a monetizer account that uses Adfox HB has [custom targeting](https://yandex.ru/support/adfox/en/targeting/puid.md) set up, you need to add the `puidN` parameters and targeting values to the ad tag, where `N` is the characteristic number from 1 to 63. The `puid` parameters are added to the `params` object in `name: value` format, where:

- `name` is the parameter name (`puidN`).
- `value` is the parameter value.


{% cut "Example of a configuration script with a monetizer that uses Adfox HB and the added puid parameters" %}


```javascript
window.YaHeaderBiddingSettings = {
  biddersMap: { 'adfox_example': '957356' },
  adUnits: [{
    code: 'adfox_154875622348837699',
    bids: [{
      bidder: 'adfox_example',
      params: {
        pp: 'g',
        ps: 'cqmv',
        p2: 'fqnq',
        puid1: 'woman',
        puid2: '16:17:18:19',
        puid3: 'green'
      }
    }]
  }],
  timeout: 500
};
```


{% endcut %}
<!-- endsource: en/_includes/monetization/script-features/targetings-adfox.md -->


## Checking monetizer bids {#customer-bid-check}

In several cases, bid requests can be sent to monetizers multiple times:

- When loading the page: Requests are sent to all monetizers specified in the configuration script.
- When reloading a placement: Using the `reload()` method, the monetizers that are only related to the reloaded ad are polled again.
- When calling the [`pushAdUnits()`method](https://yandex.ru/support/adfox/en/monetization/script-features.md#endless-scroll): The request is only sent to the monetizers specified in it.

To get bids from the latest monetizer polling, use the [ad console](https://yandex.ru/support/adfox/en/support/yan_console.md) or the `getLastBidsReceived` method in the browser console:

```javascript
window.Ya.headerBidding.getLastBidsReceived();
```

The response contains an array filled with `Bid` objects for each “placement + monetizer” pair. An object may only contain one of the following fields:

- `banner`: If the monetizer responds with a regular banner.
- `native`: If the monetizer responds with a native banner.
- `error`: If an error occurs.


{% cut "Example of a method call in the browser console" %}

![](../_images/monetization/HB_console.png)

```javascript
interface Bid {
    adapterName: string; // monetizer name
    containerId: string; // container ID
    campaignId: number; // campaign ID in Adfox
    requestDuration: number; // request duration
    cost?: {
        currency: string; // currency, "RUB"/"USD"
        cpm: number; // CPM rate returned by the server
    },
    banner?: {
        src: string; // banner contents     
    },
    size?: {
        width: number; // width in px
        height: number; // height in px
    },
    error?: {
        code: number; // error code        
        message: string; // error name    
    },
    native?: {
        nativePayload: any; // object with contents for a native banner impression
    }
};
```


{% endcut %}


**Error codes**:

**Error code** | **Value**
----- | -----
`0` | Unknown error.
`1` | No bid or response.
`2` | Incorrect response.
`3` | Timeout.
`4` | HTTP error.
`5` | Incorrect user data in the configuration script.
`6` | Incorrect monetizer settings.
`7` | The container ID received from the monetizer differs from the ID specified in the request.
`8` | A correct response with no status is received from the monetizer.
`9` | The monetizer's response has no or an incorrect `CodeType`.


## Calling the cookie-sync pixels when a request is sent to the monetizer {#cookie-sync-call}

From the page where you placed the ad tag, you can call cookie-sync pixels at the time of the request. The pixel link is provided by the monetizer.

To trigger the cookie-sync pixel:

1. Declare a variable and add the pixel link to it. If there are multiple links, add them as a comma-separated string to the `pixels` array.
    
    ```javascript
    var syncPixels = [{
        bidder: 'sape',
        pixels: ['https://ssp-rtb.sape.ru/rmatch/.....']
      }]
    ```
    
1. Add a pixel call to the `YaHeaderBiddingSettings` section:
    
    ```javascript
    syncPixels: syncPixels
    ```
    


{% cut "Example of a configuration script with a cookie-sync pixel for the Sape monetizer" %}


```html

```

 
{% endcut %}

## Disabling the Adfox substrate for fullscreen banners {#banner-backing}

When the Adfox ad tag is configured to display [fullscreen banners](https://yandex.ru/support/adfox/en/ad-inventory/codes/code.md#fullscreen), but the monetizer wants to render a banner substrate on their own, they can return `disableFullscreen: true` in their response. Setting this parameter will prevent Adfox from rendering a banner substrate, allowing the monetizer's custom substrate to be displayed.

<!-- source: en/_includes/feedback.md -->
## Contact support


<a href="en/form"> <!--ссылка, куда ведет кнопка. Если внутренняя ссылка, пишем без .md и .html --> 
  <span class="button">Send an email</span> <!--текст на кнопке--> 
</a>



<!-- source: en/_includes/styles/button.md -->

<!-- endsource: en/_includes/styles/button.md -->
<!-- endsource: en/_includes/feedback.md -->

[*new-request]: New requests to monetizers are sent when the placement is reloaded or the `pushAdUnits` method is called.