---
metadata:
  - name: generator
    content: Diplodoc Platform v5.52.0
alternate:
  - https://yandex.com.tr/support/metrica/en/code/install-counter-csp.md
  - https://yandex.com.tr/support/metrica/es/code/install-counter-csp.md
  - https://yandex.com.tr/support/metrica/pt/code/install-counter-csp.md
  - https://yandex.com.tr/support/metrica/ru/code/install-counter-csp.md
  - https://yandex.com.tr/support/metrica/tr/code/install-counter-csp.md
  - href: en/code/install-counter-csp.md
    type: text/markdown
    title: Markdown version
  - href: ../llms.txt
    type: text/markdown
    title: llms.txt
title: Installing a tag on a site with CSP
description: How to install a tag on a site with CSP.
---
> **Documentation Index:** Fetch the complete configuration index at https://yandex.com.tr/support/metrica/en/llms.txt


# Installing a tag on a site with CSP

The tag code generated by Yandex Metrica is intended for inline insertion in the pages' HTML code. On sites that use [Content Security Policy](https://www.w3.org/TR/CSP/) technology, this code will not run unless you take specific steps. In particular, you'll have to use the HTTP header to give the browser permission to process data. The HTTP header should include the [src-script](https://www.w3.org/TR/CSP/#directive-script-src) directive with the [nonce](https://www.w3.org/TR/CSP/#framework-directive-source-list) attribute (this requires signing the contents of the `script` element) and the [img-src](https://www.w3.org/TR/CSP/#directive-img-src) directive for processing the contents of the `noscript` element.

In addition, Yandex Metrica offers another way of enabling the [code snippet](*кода-счетчика): placing only the contents of the `noscript` element in the HTML code of the pages and moving the contents of the `script` element to an [external script](#separate-code-file) (for example, to a JS file).

No matter which method you choose, you must modify the HTTP header to add permission to access Yandex Metrica.

{% cut "General list of addresses" %} {#urls}

```
https://mc.yandex.ru
https://mc.yandex.az
https://mc.yandex.by
https://mc.yandex.co.il
https://mc.yandex.com
https://mc.yandex.com.am
https://mc.yandex.com.ge
https://mc.yandex.com.tr
https://mc.yandex.ee
https://mc.yandex.fr
https://mc.yandex.kg
https://mc.yandex.kz
https://mc.yandex.lt
https://mc.yandex.lv
https://mc.yandex.md
https://mc.yandex.tj
https://mc.yandex.tm
https://mc.yandex.uz
https://mc.webvisor.com
https://mc.webvisor.org
https://yastatic.net
wss://mc.yandex.ru
wss://mc.yandex.az
wss://mc.yandex.by
wss://mc.yandex.co.il
wss://mc.yandex.com
wss://mc.yandex.com.am
wss://mc.yandex.com.ge
wss://mc.yandex.com.tr
wss://mc.yandex.ee
wss://mc.yandex.fr
wss://mc.yandex.kg
wss://mc.yandex.kz
wss://mc.yandex.lt
wss://mc.yandex.lv
wss://mc.yandex.md
wss://mc.yandex.tj
wss://mc.yandex.tm
wss://mc.yandex.uz
wss://mc.webvisor.com
wss://mc.webvisor.org
```

{% endcut %}

{% cut "Addresses for frame-ancestors" %} {#frame-ancestors-urls}

```
metrika.yandex.ru
analytics.yandex.by
analytics.yandex.com
analytics.yandex.com.tr
analytics.yandex.kz
analytics.yandex.ru
metr.yandex.by
metr.yandex.com
metr.yandex.com.tr
metr.yandex.kz
metr.yandex.ru
metrica.ya.ru
metrica.yandex
metrica.yandex.by
metrica.yandex.com
metrica.yandex.com.tr
metrica.yandex.kz
metrica.yandex.ru
metrika.ya.ru
metrika.yandex
metrika.yandex.by
metrika.yandex.com
metrika.yandex.com.tr
metrika.yandex.kz
metrika.yandex.uz
```

{% endcut %}

## Inserting the tag code in the HTML code of site pages {#nonce}

{% note alert %}

The examples don’t list all of the addresses that are necessary for Yandex Metrica to work.

- [General list of addresses](#urls)
- [Addresses for frame-ancestors](#frame-ancestors-urls)

{% endnote %}

If you want to use this method, the `Content-Security-Policy` or `Content-Security-Policy-Report-Only` HTTP header must contain the following directives:

- [script-src](https://www.w3.org/TR/CSP/#directive-script-src) with the [nonce](https://www.w3.org/TR/CSP/#framework-directive-source-list) attribute. This attribute must contain a string value with a random sequence of characters (Latin letters and numbers). This value must be generated randomly on the server separately for each request.
    
    ```no-highlight
    Content-Security-Policy: script-src 'nonce-<character sequence>';
    ```
    
    The same character sequence must be contained in the `nonce` attribute in the `script` element for the counter code on the site's pages.
    
    ```javascript
    ...
    <!-- Yandex Metrica tag -->
    
```

1. In the Yandex Metrica interface, go to **Settings** > **Tag** and copy the contents of the `script` element from the field.
1. <!-- source: en/_includes/code/separate-code-file/id-separate-code-file/7.md -->
   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 %}
   <!-- endsource: en/_includes/code/separate-code-file/id-separate-code-file/7.md -->
    
1. <!-- source: en/_includes/code/separate-code-file/id-separate-code-file/4.md -->
   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> 
   ```
   <!-- endsource: en/_includes/code/separate-code-file/id-separate-code-file/4.md -->
    
<!-- source: en/_includes/buttons/chat-button.md -->
[Chat with us](https://yandex.com.tr/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.tr/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.tr/surveys/1706/?&theme=Dannye v konsoli ne otpravlyayutsya&iframe=1&lang=tr">
    </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.tr/surveys/1706/?&theme=Dannye v konsoli est, no otchety ne otobrazhayutsya&iframe=1&lang=tr">
    </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.tr/r/dashboard?)
- [Add a tag](https://metrica.yandex.com.tr/add/)
- [Free tag setup](https://yandex.com.tr/promo/freeservice/metrica?utm_source=help_metrica_tr&utm_medium=cpc&utm_campaign=1)
- [Yandex Metrica API](https://tech.yandex.com.tr/metrika/)
- [Suggest your idea](https://yandex.com.tr/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 -->

[*кода-счетчика]: The code snippet consists of two parts: JavaScript code in the `script` element, and HTML code in the `noscript` element.
{% 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 %}