Tips & TricksWordPress

Cum sa adaugi Google Analytics in WordPress fara modul (plugin) dedicat

Mai intai trebuie sa creati un Google Analytics Property.

Apoi instalati in siteul dvs. (daca nu aveti deja instalat) orice modul (plugin) care va permite sa introduceti snippet-uri (bucati de cod). Recomandarea noasta este Code Snippets.

Cu Code Snippets creati un nou snippet si lipiti bucata de cod din Google Analytics. Ar trebui sa arate ca bucata de mai jos dar cu id-ul dvs.

add_action( 'wp_head', function () { ?>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=XXX-XXX-XXX"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'XXX-XXX-XXX');
</script>
<?php } );