Separate tag code file

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 for installing the tag code on a site.

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:

    <script type="text/javascript" src="/metrika.js"></script>
    
  2. 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>
    
  3. In the Yandex Metrica interface, add a tag.

  4. Go to the Tag section and copy the content of the script element.

  5. Add this code to the metrika.js file.

    Example of file contents
    (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(XXXXXX, "init",{
    id:XXXXXX,
    clickmap:true,
    trackLinks:true,
    accurateTrackBounce:true
    });
    

    Where XXXXXX is a Yandex Metrica tag number.

Chat with us

Write an email

If you were unable to independently check the tag, follow the recommendations below.

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.
The recommendations did not help

Please note: Our support team will never initiate a call to you. Do not follow any instructions of people who call you and introduce themselves as the Yandex Metrica support team.

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:

  • 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.
The recommendations did not help

Please note: Our support team will never initiate a call to you. Do not follow any instructions of people who call you and introduce themselves as the Yandex Metrica support team.