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
XXXXXXis installed with thessr: trueparameter. Session Replay is disabled in this tag's settings. - Tag
YYYYYYis installed in a standard way and uses deferred loading, such as with thesetTimeoutfunction. 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:
- The code of the first tag is generated on the server (as determined by the
ssr: trueparameter). Here, the settings in the Yandex Metrica interface determine if Session Replay is loaded or not. - Session Replay is disabled in the Yandex Metrica settings, so the loaded tag file
tag.jsdoesn't contain the Session Replay module. - The second tag is loaded after the first one. If its initialization code lacks the
ssr: trueparameter, it loads the sametag.jsfile that was generated for the first tag. - As a result,
tag.jsdoesn't contain the Session Replay code and Session Replay can't operate.
To ensure that Session Replay operates properly on tag YYYYYY:
- Enable Session Replay in the
XXXXXXtag settings. - Add the
webvisor: falseparameter to the initialization code of tagXXXXXX.
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
});
|
Useful links |
Online training |