Wruczek/ts-website

google analytics not working

Closed this issue · 5 comments

Hey, i've tried to put my google analytics in the google-analytics.latte file.
But somehow the code is not working as expected, google analytics is not showing anything.

How to fix that?

Hi, the file google-analytics.latte is currently not used anywhere. You can put your tracking code in body.latte

Tried that, but the whole site is unavailable as soon as i put the tracking code in the body.latte..

Can you paste your code here?

Sure, just removed my personal code tho

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

  gtag('config', 'PERSONALCODE');
</script>

Characters { and } have special meaning in latte and must be escaped.
Replace all { with {l}, and all } with {r}:

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

  gtag('config', 'PERSONALCODE');
</script>