---
metadata:
  - name: generator
    content: Diplodoc Platform v5.48.2
alternate:
  - https://yandex.com/support/varioqub/en/ads.md
  - https://yandex.com/support/varioqub/ru/ads.md
  - https://yandex.com/support/varioqub/tr/ads.md
---
> **Documentation Index:** Fetch the complete configuration index at https://yandex.com/support/varioqub/en/llms.txt

# Ad experiments

With Varioqub, you can run experiments on ad units created in the Yandex Advertising Network and Adfox. This is helpful when you need to compare different ad unit formats and settings, test their size and placement, and measure the effect of new ad units on your revenue and user metrics.

After an experiment's completion, you can check the [indicator report](https://yandex.com/support/varioqub/en/stat.md), which helps determine the variant that generates the most statistically significant increase in revenue without negatively impacting user metrics.

## Connecting the experiment {#connect}

#### **Step 1. Connect Varioqub**

To learn more, see [Getting started](https://yandex.com/support/varioqub/en/index.md#quick-start) and [Connecting](https://yandex.com/support/varioqub/en/connect.md). We recommend using JavaScript to connect Varioqub.

#### **Step 2. Add the Yandex Metrica tag to the advertising dashboard settings**

<!-- source: en/_includes/ads/list-tb.md -->
{% list tabs %}

- Yandex Advertising Network

  1. In the [Yandex Advertising Network interface](https://partner.yandex.com), go to the list of sites: **Ads on websites**&nbsp;→ **Sites and ad units**&nbsp;→ **Sites**.

  1. Next to the site you need, click <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="20px" fill="currentColor" height="20px" viewBox="0 0 20 20"><path color="currentColor" d="M8.125 3.125a1.875 1.875 0 1 1 3.75 0 1.875 1.875 0 0 1 -3.75 0m0 6.875a1.875 1.875 0 1 1 3.75 0 1.875 1.875 0 0 1 -3.75 0M10 15a1.875 1.875 0 1 0 0 3.75 1.875 1.875 0 0 0 0 -3.75"/></svg> and select **Edit**.

  1. On the **General** tab, enable the option **Show YAN reports in Yandex Metrica**.

  1. In **Metrica tags**, enter the tag ID and save changes.

- Adfox

  1. In [Adfox](https://adfox.yandex.com/promo), go to the list of sites: **Settings**&nbsp;→ **System**&nbsp;→ **Yandex Metrica tags**.

  1. In **Connected tags**, enter the tag ID and save the changes.

{% endlist %}
<!-- endsource: en/_includes/ads/list-tb.md -->

## Launching an experiment {#start}

1. In Yandex Metrica, go to **Varioqub → Experiments**.

1. Click **Create experiment**.

1. Add [experiment conditions](https://yandex.com/support/varioqub/en/create/conditions.md).

1. <!-- source: en/_includes/create/metrics-about.md -->
   Choose the key metrics by which you'll determine the experiment's success. For advanced analysis, you can also select up to 10 secondary metrics.
   <!-- endsource: en/_includes/create/metrics-about.md -->

    To measure the success of your ad experiments, we recommend choosing “Average revenue per visit” (or per user) as the primary metric. For additional metrics, you can choose custom ones, such as “Page depth” and “Visual bounce rate”.

1. Customize the experiment design. To do this, use:

    - [Ad units](#blocks): To add a new **In-image**, **Floor Ad**, **Top Ad**, or **Interstitial** ad unit.
    
    - [Visual editor](#visual): To compare changes in ad display, size, and placement of an ad unit.

    - [Flags in code](#flags): To compare ad units, to experiment with methods to call ad units, etc.

## Ad units {#blocks}

On this tab, you can create an experiment with the placement and format of ad units on your site. If you [connect Varioqub](https://yandex.com/support/varioqub/en/connect.md) (`exp.js`), you can do this without adding the ad unit code (`context.js`).

{% note info %}

If your site uses CSP, in addition to connecting Varioqub, you also need to add [rules for ads](https://yandex.com/support/partner/en/web/adplatform/csp-configuration) to conduct an experiment.

{% endnote %}

To create an experiment:

<!-- source: en/_includes/ads/ad-types.md -->
1. Select the ad unit type:

    - **Interstitial**: Displayed in full screen. Create a separate unit for each site version.

    - **Top Ad**: Stays fixed at the top of the screen, overlapping the site content. Only works in the mobile site version.

    - **Floor Ad**: Stays fixed at the bottom of the screen, overlapping the site content. Create a separate unit for each site version.

    - **In-image**: Displayed over images on the site. The same ad unit works across all site versions.

        {% cut "In-image unit limitations" %}
        
        In the current version of Varioqub, the following settings aren't used for **In-image** units:

        * **Page limit**

        * **Limitation for images**

        * **Type of integration**

      For more information, see the [In-Image](https://yandex.com/support2/partner/en/web/units/types/in-image) section in the Yandex Advertising Network Help.

        By default, these ad units use **Automatic** integration. Ads appear on all images with a size of at least 320 × 190 pixels.
        
        {% endcut %}

    Following the rules of the Yandex Advertising Network:

    - You can't display both **Top Ad** and **Floor Ad** units on the same page at the same time.

    - **Top Ad** units can only be used on mobile devices.

    See [Unit types](https://yandex.com/support/partner/en/web/units/types/) for more details.

1. Specify the [blockId](*block-id) for units that you're setting up your experiment for:

    * **Desktop block ID**: For the desktop site version.

    * **Touch block ID**: For the mobile site version.

    {% note warning %}
    
    Make sure that your **In-image** unit has the same `blockId` specified for all site versions.

    {% endnote %}
<!-- endsource: en/_includes/ads/ad-types.md -->

## Working in the visual editor {#visual}

The editor is embedded into your site and enables you to change an ad unit's size and appearance. All changes are applied in real time. Once you save the changes and run the experiment, the edits you made in the editor become visible to users selected for the experiment.

{% cut "Experiment changing an ad unit's appearance" %}



1. On the site, modify the ad unit code. Example of a modified [YAN](*yan) code:

    ```javascript
    <!-- Yandex.RTB R-A-111111-1 -->
    <div id='yandex_rtb_R-A-111111-1'></div>
    
    ```

    where

    - `R-A-111111-1` is the ad unit ID.
    - `XXXX` is the ID of the Yandex Metrica tag installed on your site.

1. In Yandex Metrica, go to **Varioqub → Experiments**.

1. Choose the **Visual editor** experiment type and specify the URL of the page you want to edit.

1. Click **Edit** next to **Variant 1**. This opens the page you specified in the visual editor field. You don't need to make any changes to the control variant. That version of the page is used in the experiment in its current form.

1. Click the unit you want to apply experimental changes to. The visual editor window opens.

1. To change the size or appearance of the container, go to the unit's parent element. To do this, click <svg width="18" height="16" viewBox="0 0 18 16" fill="none" xmlns="http://www.w3.org/2000/svg"><g clip-path="url(#svg-om2q3wms__clip0_1_2)"><path d="M0.294288 15.3523C0.479472 15.462 0.69078 15.5199 0.906048 15.5199L15.8941 15.5199C16.5568 15.5199 17.0941 14.9827 17.0941 14.3199C17.0941 14.1047 17.0362 13.8934 16.9265 13.7082L9.43241 1.06196C9.09454 0.49184 8.35844 0.30356 7.7883 0.64148C7.61503 0.74408 7.47038 0.8888 7.36771 1.06196L-0.126303 13.7082C-0.464171 14.2783 -0.275867 15.0144 0.294288 15.3523ZM8.40006 4.02764L13.7881 13.1199H3.01204L8.40006 4.02764Z" fill="currentColor"/></g><defs><clipPath id="svg-om2q3wms__clip0_1_2"><rect width="16" height="18" fill="white" transform="matrix(0 -1 1 0 0 16)"/></clipPath></defs></svg>.

    ![](_assets/exp-gen.png =356x)

1. On the **CSS** tab, specify the property that you want to apply in the experimental variant and click **Save**.

    To make sure that your changes are applied, under **Experiment testing**, click **Test** next to each variant. The site version associated with the selected variant opens at a link generated by Varioqub. You can share this link within 24 hours of its generation. Clicking **Test** again generates a new link.

1. Click **Save and run**.

{% cut "Example of changing an ad unit's height" %}

To run an experiment with different unit heights, on the **CSS** tab, specify the style property for the unit's parent element.

For example, for an experiment that switches from a fixed height to an adaptive one, change the following CSS properties:

- Remove the height restriction with `height: unset`.

- Set the maximum unit height with `max-height: 70vh`.

![](_assets/exp1-1.png =356x)

{% endcut %}

{% cut "Example of making a side banner sticky when scrolling articles" %}

To run an experiment that makes a side banner sticky when scrolling articles, on the **CSS** tab, specify the required properties for the unit's parent element.

For example:

- Change the way the unit is displayed with `position: sticky`.

- Set the unit's position relative to the parent element with `top: 20px`.

![](_assets/exp1-2.png =356x)

{% endcut %}

{% endcut %}

{% cut "Experiment adding a new ad unit" %}

You can also use the visual editor to add an ad unit embed code. This can be useful for testing new ad placements on your site. We recommend choosing **Floor Ad**, **Top Ad**, or **Interstitial** ad units. For example, you can do this in the [Yandex Advertising Network](https://yandex.com/support/partner/en/web/units/types/).

1. [Configure the Varioqub library](https://yandex.com/support/varioqub/en/objects/set-config.md) by adding the following code to the library:

    ```javascript
    
    ```

1. In Yandex Metrica, go to **Varioqub → Experiments**.

1. Choose the **Visual editor** experiment type and specify the URL of the page you want to edit.

1. Click **Edit** next to **Variant 1**. This opens the page you specified in the visual editor field. You don't need to make any changes to the control variant. That version of the page is used in the experiment in its current form.

1. On the page, select an element that appears on all pages of your site, for example, a footer.

1. Select the **JS** tab and add the function from the ad unit code.

    ![](_assets/add-func.png =356x)

    An ad container will appear on all pages where your chosen element is present, and the code from the **JS** tab will be called.

1. Click **Save**.

1. Check if your code is processed correctly on different site pages: for example, on the home page, in an article, or in other sections of your site.

{% endcut %}

## Setting up an experiment using flags {#flags}

1. In Yandex Metrica, go to **Varioqub → Experiments**.

1. Choose the **Flags in code** experiment type.

{% note info %}

Make sure the flag name and values in Yandex Metrica and in the modified embed code are specified in the language and case that is used in the code.

{% endnote %}

{% cut "Flags in code experiment" %}

1. In Varioqub, set the name and values of the flag. For example, enter `block` for the flag name, `A` for the control value, and `B` for **Variant 1**.

    ![](_assets/flags_oba.png =750x)

1. In the HTML code of the page, specify the ad containers to run the experiment on:

    ```html
    ...
    <div id="rsya_varioqub_A"></div>
    <div id="rsya_varioqub_B"></div>
    ...
    ```

    Next, change the ad unit code on the site as described below.

1. Create a function for calling the control variant. In this example, the R-A-111111-1 unit is called:

    ```javascript
    
    ```

1. Create a function for calling Variant 1. In this example, the R-A-111111-2 unit is called:

    ```javascript
    
    ```

1. Create a function for handling what happens when the experiment ends or in other scenarios (for example, when a page view doesn't match the filters set in the experiment settings):

    ```javascript
    
    ```

1. Create a function for applying experiment flags as follows:

    ```javascript
    <srcipt>
    function render_ab_answer(flags) {
      const flagVal = flags && flags.block && flags.block[0];
    switch
    (flagVal)
    {
       case 'A':
            vq_call_block_a();
            break;
       case 'B':
            vq_call_block_b();
            break;
       default:
            vq_call_block_default();
            break;
    }}
    </script>
    ```

1. Configure the passing of flags to the function from step 4 using the [ymab](https://yandex.com/support/varioqub/en/objects/ymab.md) function:

    ```javascript
    <srcipt>
    ymab('metrika.XXXX', 'init', function (answer) {
      render_ab_answer(answer.flags);
    })
    </script>
    ```

   {% note info %}

   The `ymab` function with the [init](https://yandex.com/support/varioqub/en/objects/init.md) method is called only once to pass flags.
   
   {% endnote %}

1. Check if your code is processed correctly on different site pages: for example, on the home page, in an article, or in other sections of your site.

{% cut "Example of code for comparing two ad units" %}

```javascript

```

{% endcut %}

{% endcut %}

<!-- source: en/_includes/ads/connect-git.md -->
The examples for connecting Varioqub and creating experiments are available on [GitHub](https://github.com/yandex/varioqub-extras/tree/master/web).
<!-- endsource: en/_includes/ads/connect-git.md -->

## FAQ and troubleshooting

[I'm trying to create an experiment, but all the fields are locked.](https://yandex.com/support/varioqub/en/faq.md#fields-blocked)

[Can factors that are not available in the experiment creation interface be used as conditions?](https://yandex.com/support/varioqub/en/faq.md#custom-condition)

[Can I use a custom JS script in an A/B test?](https://yandex.com/support/varioqub/en/faq.md#js-script)

[How do I disable a specific experiment type for an entire site or page?](https://yandex.com/support/varioqub/en/faq.md#disable-experiment-type)

[An element loads after the page. How do I include it in the experiment?](https://yandex.com/support/varioqub/en/faq.md#element-after-download)

[My site has dynamic element IDs. Can I still use the visual editor?](https://yandex.com/support/varioqub/en/faq.md#changing-id)

[My monetization statistics in Yandex Metrica and the partner interface are different.](https://yandex.com/support/varioqub/en/faq.md#monetization-statistics)


<!-- source: en/_includes/feedback/feedback.md -->
<details>
    <summary class="button">Contact support</summary>
    <div style="padding: 15px;
     margin: 10px 0;
     background: #FFFFFF;
     border-radius: 10px;
     border: 1px solid var(--yc-color-line-generic);">
     <iframe style="background: #FFFFFF;"
        height="700"
        width="100%"
        frameborder="0"
        src="https://forms.yandex.ru/surveys/1705/?iframe=1&lang=en">
    </iframe>
</details>






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

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

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

[*yan]: Yandex Advertising Network

[*block-id]: Ad unit ID in the Yandex Advertising Network formatted as follows: `A-B-123456-78`.