News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

SMF 2.0.X How to make Google analytics code works

Started by srafie, November 29, 2020, 02:13:15 PM

Previous topic - Next topic

srafie

Hi Guys,

After i tried some mods to include my Google analytics code (not working), and inserted the code provided by google analytics in index.template.php with errors.
I finally found how to make it work,  tanks to @Gluz for the tweak en Spanish langage.
So here is the right code to include in the <head> section on index.template.php file of your theme:


echo '<!-- Global Site Tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-xxxxxxxxx-1"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag(\'js\', new Date());

  gtag(\'config\', \'UA-xxxxxxxxxx-1\');
</script>';


Enjoy

Advertisement: