How to setup yandex metrica

AI-generated summary

How to setup Yandex Metrica

MrAli is seeking guidance on adding Yandex Metrica to a self-hosted site. They have found the necessary code and are planning to add it to the Head section of their theme via /admin/customize/themes/1/common/head_tag/edit. The code provided includes a JavaScript counter that can be installed within the <head> or <body> tags. MrAli also considers serving the tag.js file from their S3 to avoid ad blockers, although they acknowledge this approach may not be ideal due to potential changes to the tag.js file.

Hello Everyone

I was wondering how to add yandex metrica to self host site.
I did some search but i need more info

<!-- Yandex.Metrika counter -->
<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(MY-CODE, "init", {
        clickmap:true,
        trackLinks:true,
        accurateTrackBounce:true,
        webvisor:true,
        ecommerce:"dataLayer"
   });
</script>
<noscript><div><img src="https://mc.yandex.ru/watch/MY-CODE" style="position:absolute; left:-9999px;" alt="" /></div></noscript>
<!-- /Yandex.Metrika counter -->

My idea is edit the theme, or create a new component. in the Head section because this is there instructions

/admin/customize/themes/1/common/head_tag/edit

When installing the tag in the site HTML code, place the code as close to the top of the page as possible. For example, within the or tags.

then i may serve the tag.js from my S3 to avoid ads blockers. i know this is not good idea, they may change the tag.js any time.

Is this the best way to do it?

Ali

1 Like