# Come configurare Yandex Metrica

**URL:** <https://meta.discourse.org/t/how-to-setup-yandex-metrica/301495>\
**Category:** Data & reporting\
**Created:** [29 Marzo 2024, 1:25pm UTC](https://meta.discourse.org/t/how-to-setup-yandex-metrica/301495 "2024-03-29T13:25:31Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![MrAli](https://avatars.discourse-cdn.com/v4/letter/m/7ea924/32.png) [@MrAli](https://meta.discourse.org/u/MrAli)\
**Post date:** [29 Marzo 2024, 1:25pm UTC](https://meta.discourse.org/t/how-to-setup-yandex-metrica/301495/1 "2024-03-29T13:25:31Z")

</div>

Ciao a tutti

Mi stavo chiedendo come aggiungere Yandex Metrica a un sito self-hosted.  
Ho fatto qualche ricerca ma ho bisogno di maggiori informazioni

> [@Adding Yandex Metrica counter to Discourse](https://meta.discourse.org/t/293282):
>
> I apologize for writing out of such stupidity, but my head is already boiling from this problem. I’ve tried a lot, but apparently I don’t know how to do it correctly. I need to install the Yandex.Metrica counter code in the , but due to CSP it does not work. I tried to somehow configure Goofle Tags, but apparently I did everything wrong there too. Please tell me step by step how I can do this. There are instructions from Yandex on this topic, but I’m stupid: Here is the counter code that ne…

```html
<!-- 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 -->

```

La mia idea è modificare il tema, ~~o creare un nuovo componente.~~ nella sezione `Head` perché queste sono le istruzioni  
`/admin/customize/themes/1/common/head_tag/edit`

> Quando si installa il tag nel codice HTML del sito, posizionare il codice il più vicino possibile all’inizio della pagina. Ad esempio, all’interno dei tag `<head></head>` o `<body></body>`.

poi potrei servire il `tag.js` dal mio S3 per evitare gli ad blocker. so che non è una buona idea, potrebbero cambiare il `tag.js` in qualsiasi momento.

È questo il modo migliore per farlo?

Ali

---

_[View the full topic](https://meta.discourse.org/t/how-to-setup-yandex-metrica/301495)._
