---
metadata:
  - name: generator
    content: Diplodoc Platform v5.50.6
alternate:
  - https://yandex.com/support/metrica/en/code/separate-code-file.md
  - https://yandex.com/support/metrica/es/code/separate-code-file.md
  - https://yandex.com/support/metrica/pt/code/separate-code-file.md
  - https://yandex.com/support/metrica/ru/code/separate-code-file.md
  - https://yandex.com/support/metrica/tr/code/separate-code-file.md
  - https://yandex.com/support/metrica/zh/code/separate-code-file.md
---
> **Documentation Index:** Fetch the complete configuration index at https://yandex.com/support/metrica/en/llms.txt

# Separate tag code file


{% note alert %}

The counter code placed in a file on your server may become outdated when the code is updated on the Yandex Metrica side. This is why we recommend using the [standard approach](https://yandex.com/support/metrica/en/quick-start.md) for installing the tag code on a site.

{% endnote %}


To connect the Yandex Metrica tag code to a site in a separate file:

1. Add this line to the HTML code on all of the site’s pages:
    
    ```javascript
    
    ```
    
1. In order for the tag to collect data on users who have JavaScript disabled, add the content of the `noscript` element to the HTML code of the site's pages:
    
    ```
    <noscript><div><img src="https://mc.yandex.ru/watch/XXXXXX" style="position:absolute; left:-9999px;" alt="" /></div></noscript>
    ```
    
1. In the Yandex Metrica interface, [add a tag](https://metrica.yandex.com/add).
1. Go to the **Tag** section and copy the content of the `script` element.
    
1. Add this code to the `metrika.js` file.
    
    {% cut "Example of file contents" %}
    
    ```javascript
    (function(m,e,t,r,i,k,a){m[i]=m[i]||function(){(m[i].a=m[i].a||
    []).push(arguments)};
    m[i].l=1*new Date();k=e.createElement(t),a=e.getElementsByTagName(t)
    [0],k.async=1,k.src=r,a.parentNode.insertBefore(k,a)})
    (window, document, "script", "https://mc.yandex.ru/metrika/tag.js", "ym")
    ym(XXXXXXXX, "init",{
    id:XXXXXX,
    clickmap:true,
    trackLinks:true,
    accurateTrackBounce:true
    });
    ```
    
    Where `XXXXXXXX` is a Yandex Metrica tag number.
    
    {% endcut %}
    
<!-- source: en/_includes/buttons/chat-button.md -->
[Chat with us](https://yandex.com/chat/#/user/036e6a02-3620-9cdc-4c5e-a34667a7379e?utm_source=spravka){.button}

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

<!-- endsource: en/_includes/styles/href-to-button.md -->
<!-- endsource: en/_includes/buttons/chat-button.md -->

<!-- source: en/_includes/code/texing-button.md -->
<div class="cut-button">

{% cut "Write an email" %}

<!-- source: en/_includes/popup/id-qanda/check1.md -->
If you were unable to [independently check the tag](https://yandex.com/support/metrica/en/general/check-counter.md), follow the recommendations below.
<!-- endsource: en/_includes/popup/id-qanda/check1.md -->

{% list tabs radio %}

- Data is not sent to the console

  {% include [qanda-check2-2](../_includes/popup/id-qanda/check2-2.md) %}

  {% cut "The recommendations did not help" %}


  <div style="padding: 15px;
         margin: 10px 0;
         background: #FFFFFF;
         border-radius: 10px;
         border: 1px solid var(--g-color-line-generic);">
    <iframe style="background: #FFFFFF;"
            height="700"
            width="100%"
            frameborder="0"
            src="https://forms.yandex.com/surveys/1706/?&theme=Dannye v konsoli ne otpravlyayutsya&iframe=1&lang=en">
    </iframe>
  </div>

  {% endcut %}

- There is data in the console, but the reports do not appear

  <!-- source: en/_includes/popup/id-qanda/check2-3.md -->
  This means that information is being transmitted to Yandex Metrica. However, the data might not be shown in reports for any of the following reasons:
  <!-- endsource: en/_includes/popup/id-qanda/check2-3.md -->

  <!-- source: en/_includes/popup/id-qanda/check2-4.md -->
  - Data is sent to a tag with a different number.
  - The **Filters** tab in the tag settings has overly strict filters defined. Remove unneeded filters.
  - The **Filters** tab in the tag settings has the **Don’t count my sessions** filter enabled. This means that the tag doesn't register your own sessions. Try accessing the site with your browser in “incognito” mode.
  <!-- endsource: en/_includes/popup/id-qanda/check2-4.md --> 

  {% cut "The recommendations did not help" %}


  <div style="padding: 15px;
           margin: 10px 0;
           background: #FFFFFF;
           border-radius: 10px;
           border: 1px solid var(--g-color-line-generic);">
    <iframe style="background: #FFFFFF;"
              height="700"
              width="100%"
              frameborder="0"
              src="https://forms.yandex.com/surveys/1706/?&theme=Dannye v konsoli est, no otchety ne otobrazhayutsya&iframe=1&lang=en">
    </iframe>
  </div>

  {% endcut %}

{% endlist %}

{% endcut %}

</div>

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

<!-- endsource: en/_includes/styles/cut-button.md -->
<!-- endsource: en/_includes/code/texing-button.md -->


<!-- source: en/_includes/footer-links.md -->
- - -

<div class="borderless-table">

#|
||
Useful links

- [Demo tag](https://metrica.yandex.com/r/dashboard?)
- [Add a tag](https://metrica.yandex.com/add/)
- [Free tag setup](https://yandex.com/promo/freeservice/metrica?utm_source=help_metrica_en&utm_medium=cpc&utm_campaign=1)
- [Yandex Metrica API](https://tech.yandex.com/metrika/)
- [Suggest your idea](https://yandex.com/support/metrica/troubleshooting/idea.html)
- [Discuss in Telegram](https://t.me/yandexmetrika)
|
Online training

- [Get a Yandex Metrica certificate](https://yandex.ru/adv/expert/exam/metrika/?utm_source=metrika_help&utm_medium=web&utm_campaign=static&utm_content=useful_links)


- [Take a training course](https://yandex.com/adv/edu/online/metrika?utm_source=metrika_help&utm_medium=web&utm_campaign=static&utm_content=useful_links)

||
|#

</div>

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

<!-- endsource: en/_includes/styles/table-style.md -->
<!-- endsource: en/_includes/footer-links.md -->

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

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

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

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

{% included (../_includes/popup/id-qanda/check2-2.md) %}
   This might happen for the following reasons:
   - The tag is installed incorrectly. For example, the CMS modified the tag code. Reinstall the tag or contact the support service for your CMS.
   - Broken scripts are preventing the Yandex Metrica tag from working on the site. You can check this in the browser console.


{% endincluded %}