How to setup yandex metrica

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" >
   m[i].l=1*new Date();
   for (var j = 0; j < document.scripts.length; j++) {if (document.scripts[j].src === r) { return; }}
   (window, document, "script", "", "ym");

   ym(MY-CODE, "init", {
<noscript><div><img src="" 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


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?


1 Like