Installing multiple tags on a site

Sometimes you may need to put multiple tags on a page at once. Similarly, you can place the image embed code, which is used when JavaScript is disabled, inside a single noscript element.

If you're installing multiple tags, only connect Session Replay to one tag specified in the code.

To initialize a tag, use the ssr parameter.

<!-- Yandex Metrica tag -->
<script type="text/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();
        for (var j = 0; j < document.scripts.length; j++) {if (document.scripts[j].src === r) { return; }}
        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?id=XXXXXXX', 'ym');

ym(XXXXXXX, 'init', {ssr:true, webvisor:true, clickmap:true, accurateTrackBounce:true, trackLinks:true});

    (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();
        for (var j = 0; j < document.scripts.length; j++) {if (document.scripts[j].src === r) { return; }}
        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?id=YYYYYYY', 'ym');

ym(YYYYYYY, 'init', {ssr:true, clickmap:true, accurateTrackBounce:true, trackLinks:true});

</script>
<noscript>
  <div>
    <img src="https://mc.yandex.ru/watch/XXXXXXX" style="..." alt="" />
  </div>
  <div>
    <img src="https://mc.yandex.ru/watch/YYYYYYY" style="..." alt="" />
  </div>
</noscript>
<!-- /Yandex.Metrika counter -->

Here, XXXXXX and YYYYYY are the IDs of the Yandex Metrica tags.

Code snippet without the ssr parameter
<!-- Yandex Metrica tag -->
<script type="text/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();
   for (var j = 0; j < document.scripts.length; j++) {if (document.scripts[j].src === r) { return; }}
   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", {clickmap:true, trackLinks:true, accurateTrackBounce:true});
ym(YYYYYY, "init", {clickmap:true, trackLinks:true, accurateTrackBounce:true, webvisor: true});

</script>
<noscript>
  <div>
    <img src="https://mc.yandex.ru/watch/XXXXXX" style="..." alt="" />
    <img src="https://mc.yandex.ru/watch/YYYYYY" style="..." alt="" />
  </div>
</noscript>
<!-- /Yandex.Metrika counter -->

Here, XXXXXX and YYYYYY are the IDs of the Yandex Metrica tags.

Combining tags with different code versions

If multiple tags are installed on a page, and one of them loads with the ssr: true parameter, some combinations of settings might cause Session Replay issues.

Imagine there are two tags set up on the same page:

  • Tag XXXXXX is installed with the ssr: true parameter. Session Replay is disabled in this tag's settings.
  • Tag YYYYYY is installed in a standard way and uses deferred loading, such as with the setTimeout function. Session Replay is enabled in this tag's settings.

In this case, Session Replay won't work on both tags due to a specific code loading process:

  1. The code of the first tag is generated on the server (as determined by the ssr: true parameter). Here, the settings in the Yandex Metrica interface determine if Session Replay is loaded or not.
  2. Session Replay is disabled in the Yandex Metrica settings, so the loaded tag file tag.js doesn't contain the Session Replay module.
  3. The second tag is loaded after the first one. If its initialization code lacks the ssr: true parameter, it loads the same tag.js file that was generated for the first tag.
  4. As a result, tag.js doesn't contain the Session Replay code and Session Replay can't operate.

To ensure that Session Replay operates properly on tag YYYYYY:

  1. Enable Session Replay in the XXXXXX tag settings.
  2. Add the webvisor: false parameter to the initialization code of tag XXXXXX.

In this case, tag.js will contain the Session Replay code, but the webvisor: false parameter will prevent Session Replay from operating on the first tag.

Sample code for tag XXXXXX:

ym(XXXXXX, "init", {
    ssr: true,
    webvisor: false,
    // other parameters
});

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

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