---
metadata:
  - name: generator
    content: Diplodoc Platform v5.52.0
alternate:
  - https://yandex.com/support/adfox/en/banners/specs/code-transfer.md
  - https://yandex.com/support/adfox/ru/banners/specs/code-transfer.md
  - href: en/banners/specs/code-transfer.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.com/support/adfox/en/llms.txt

# Code forwarding

## Description {#description3}

With code forwarding, you can install arbitrary HTML code in the banner container. If the code contains scripts, they will be executed in the context of the page.

You can use the following banner features in Adfox:

- Both HTML5 code and asynchronous embed code from any ad management system can be installed.
- You can place any HTML code that can go beyond the container: for example, showing Fullscreen, Background, or expandable banners.

Format features:

- Click statistics can only be taken into account when placing [HTML5 banner code considering the requirements](#clicksrequirements).
- When placing a banner with an ad tag, click statistics aren't taken into account.

To place the Adfox ad tag with the context.js library, use the [Adfox forwarding code [context]](https://yandex.com/support/adfox/en/banners/specs/adfox-code-transfer.md) template.


## Code requirements {#coderequirements}

1. The maximum allowed number of characters in the HTML code is 65,000.
1. <!-- source: en/_includes/banners/specs/banner-html5/js-css.md -->
   It's best to place JavaScript and CSS inside the HTML code of the banner. If the final HTML code exceeds the maximum acceptable size, reduce it by splitting JavaScript and CSS code into separate files:
   1. Save the JS and CSS code in separate files with the .js or .css extension.
   1. File size can't exceed 10 MB.
   1. Upload the files to the ad campaign's **Files** tab and add the resulting file links to the HTML code:
       
       - If the project includes absolute links (`src="js/script.js"`, `src="css/style.css"`), Adfox will recognize the paths to the files and automatically add them to the **Files** tab, replacing all links to these files in the project during the upload.
       - If the project includes relative links (`src="../js/script.js"`), use one of the following methods:
       
           - Replace `.js` and `.css` file links with absolute paths: Adfox parsing will trigger, and all links will be replaced automatically.
           - Manually upload `.js` and `.css` files to the **Files** tab and replace relative links in your HTML code with the ones you'll get from Adfox.
       
       Example of connecting JS and CSS files:
       
       ```html
       <link rel="stylesheet" type="text/css" href="LINK_TO_FILE" />
       ```
       
   <!-- endsource: en/_includes/banners/specs/banner-html5/js-css.md -->
    
1. You can install any HTML code, Adfox ad tag with the context.js library, or asynchronous ad tag of another ad system (without the document.write function).


{% note info %}

If the HTML code that you want to add to Adfox as a banner contains `document.write`, you can't use the **Code forwarding [context]** template. In that case, we recommend adding the code through the [Banner HTML5 [context]](https://yandex.com/support/adfox/en/banners/specs/banner-html5.md) template.

{% endnote %}



## Requirements for counting clicks in a banner with HTML5 code {#clicksrequirements}

1. Counting clicks on banners.

    To count click statistics for a banner in Adfox, you need to include the following variable in the `а` tag for the `href` attribute in the HTML code:

    `%banner.reference_mrc_user25%`
    
    For links, use the `target` attribute with the `%banner.target%` variable as an attribute. If the attribute is missing, the link will open inside the iframe: that is, the advertised site will open in the location of the banner.
    
    Example of HTML code that counts banner clicks:

    ```html
    <a href="%banner.reference_mrc_user25%" target="%banner.target%">Advertiser's site</a>
    ```
    
1. Counting clicks for multiple links on the banner.
    Let's say the banner has several links leading to different pages of the advertised site, and you need to count the number of clicks for each of them.
    
    ```html
    <a href="http://site.ru" target="_blank">First link</a>
    <a href="http://site.ru/about/" target="_blank">Second link</a>
    ```
    
    Replace the `href` attribute value with the `%request.reference_mrc%&pf=%banner.eventN:urlenc%` variables, where `N` is the event number from 1 to 28.
    
    For example:

    ```html
    <a href="%request.reference_mrc%&pf=%banner.event1:urlenc%" target="%banner.target%">First link</a>  
    <a href="%request.reference_mrc%&pf=%banner.event2:urlenc%" target="%banner.target%">Second link</a>
    ```
    
    You need to inform the manager who adds the banner to Adfox about which links correspond to which variables. When adding a banner, you'll need to specify the first link for Event 1, and the second link for Event 2 on the **Events** tab.
    


## Add a banner {#addbanner3}

1. To add a banner with a code, use the **Code forwarding [context]** template.
1. If this template is missing from the banner type list, [add it from the preset](https://yandex.com/support/adfox/en/ad-inventory/settings/template.md#predefined-template).
1. When adding a banner, specify the parameters:

   #|
   || **Parameter** | **Description** ||
   || **Tracking pixel link** | By default, the Adfox `//banners.adfox.ru/transparent.gif` pixel is used. If you want to count impressions in a third-party system, delete the Adfox pixel and provide another link. ||
   || **HTML ad tag** | Insert the HTML code. ||
   || **Transition URL** | Specify the link to the advertiser's site, provided that the HTML code complies with the [requirements for embedding code to count clicks](#clicksrequirements).
    
   If the HTML code contains several links to different pages of the advertised site, leave the **Transition URL** field empty and specify the links on the **Events** tab after adding the banner.
   
   For the click-through to work correctly, make sure that the link includes the protocol (`http://` or `https://`). ||
   || **Name of the banner container class attribute** | If necessary, enter a name (or multiple names separated by a space) for the `class` attribute of the banner container. ||
   || **Advertising label settings**:
   - **Ad label**
   - **Domain** |

   {% note info %}
    
   If the format of the banner is [sticky](*sticky), manually add the layout for the “Ad” label to your ad unit code. We don't recommend enabling the “Ad” label in the banner parameters in Adfox.
    
   {% endnote %}

   {% include [ad-label-add-menu](../../_includes/labeling/ad-label/ad-tag-settings.md) %} 

   ||   
   || **Show banner menu** | 

   <!-- source: en/_includes/labeling/ad-label/add-menu.md -->
   To add a token to a non-clickable banner, enable the **Show banner menu** option in the banner settings. When the banner is served, the ![](../../_images/kebab.png) menu icon will be displayed in its upper-right corner. When a user clicks the icon, the advertiser's details and the copy token button appear (if ad register is enabled for the banner or a third-party token is specified).
   <!-- endsource: en/_includes/labeling/ad-label/add-menu.md -->

   <!-- source: en/_includes/labeling/ad-label/mark.md -->
   The banner menu contains a link to the rules for using recommendation technologies. It's required for compliance with Clause 3 of Section 1 of Article 10.2-2 of the Federal Law No. 149-FZ “On information, information technologies, and information protection”, dated July 27, 2006.
   <!-- endsource: en/_includes/labeling/ad-label/mark.md -->

   <!-- source: en/_includes/labeling/ad-label/non-clickable.md -->
   {% note info %}

   If the banner is non-clickable (the **Transition URL** field is empty) and has not been added to the ad register, you can enable the banner menu to make the token available when serving the banner.

   {% endnote %}
   <!-- endsource: en/_includes/labeling/ad-label/non-clickable.md --> 

   ||
   || **Advertising labeling** | 
   
   <!-- source: en/_includes/banners/specs/background-html5/labeling-banner.md -->
   **Advertising labeling**: This section is only available if you've selected **Submit data to state register** as a labeling procedure in the campaign settings. Fill in the fields in this section to [register the creative in the Yandex advertising data operator](https://yandex.com/support/adfox/en/labeling/token.md). The creative is assigned a token automatically.
   <!-- endsource: en/_includes/banners/specs/background-html5/labeling-banner.md --> 
   
   ||    
   |# 


## Add a default banner {#defoltbanner}

1. To add a default banner with any HTML code, [use the code generator](https://yandex.ru/promo/yan/adfox-specs/default-generator/index_en).
1. Select the **Third-party ad tag** code type and paste the HTML code into the code input field.
1. Add tracking pixels if necessary.
1. Copy the ad tag and paste it in the **Code** field with the **JavaScript** type.

Example of placing third-party code:

![](../../_images/banners/default.transfer_any_2.png =500x){style="border: solid 1px #cccccc; max-width=500px"}


<!-- 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 -->

[*sticky]: The banner is fixed in the browser window and stays in the viewport as the user scrolls through the page.
{% included (../../_includes/labeling/ad-label/ad-tag-settings.md) %}

In the **Ad label** list, select `Ad` or `Social ad` to label the banner. If your ad creative already contains a label, you can leave the `Disabled` value in the drop-down list.

  {% note info %}

  Adding the “Social ad” label doesn't automatically define the creative as social advertising. To label a creative as a social ad (PSA) in the state register, select **Social advertising contract with payment** or **Social advertising contract by quota** for the corresponding [contract with the end advertiser](../../../labeling/token.md#step-2).

  {% endnote %}

In the **Domain** field, specify the advertiser domain, and it will be added to the label: “Ad \| example.com” or “Social ad \| example.com” (only if the `Ad` or `Social Ad` value is selected in the dropdown list).

{% endincluded %}