Recent Topics

Google Analytics Tag Validation errors

Started by on Apr 22, 2019 – Contents updated: Sep 06, 2019

Apr 22, 2019 02:30    

Hi guys,

I'm getting an error of invalid XHTML for the google analytics tag inserted in "collection/settings/advanced/Custom meta tag/css section (before </head>)".
Shouldn't it be accepted just as it is? I tried to loose the settings as suggested but didn't work too.

Validation errors:
Tag <body> may not contain raw character data
Parser error: Space required near <script async src="https://www.googletagmanager.com/gtag/js?id=UA-----------"></script> <script>
Invalid Custom meta tag/css section. You can loosen this restriction in the Group settings.

Google Analytics Tag Validation errors
Google Analytics Tag Validation errors

Apr 23, 2019 02:41

This is solved, I managed to fix the google's original code so it becomes valid for the XHTML validation.
Just use a template like this (don't forget to replace 111222333-1 with your tag). Tested and receiving hits ok B)

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


Form is loading...

Community software – This forum is powered by b2evolution CMS, a complete engine for your website.