Simple Machines Community Forum

SMF Support => Language Specific Support => Español (Spanish) => Topic started by: ^SoporteGSM^ on October 09, 2017, 08:14:25 PM

Title: Ayuda: Como insertar este codigo en indextemplate.php (Google Analytics)
Post by: ^SoporteGSM^ on October 09, 2017, 08:14:25 PM
Quote<!-- Global Site Tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-107861100-1"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

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

Marca error la Web al subirlo tal y como esta...
Title: Re: Ayuda: Como insertar este codigo en indextemplate.php (Google Analytics)
Post by: Gluz on October 09, 2017, 10:41:04 PM
¿En qué parte y cómo insertaste el código?

Ese tipo de códigos se deben insertar en el index.template.php del tema que usas para que salga en todas partes, y para insertarlo hay que tomar en cuenta se debe usar echo de PHP para enviar al navegador esa parte y que Javascript usa comillas simples al igual que el echo de PHP, por lo que hay que escapar las comillas del código Javascript para que funcione.

Aquí dejo los códigos para que veas la diferencia:
Quote//Código directo, no funciona
<!-- Global Site Tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-107861100-1"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

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



//Código en echo sin escapar comillas, no funciona
echo '<!-- Global Site Tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-107861100-1"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

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



//Código en echo con comillas escapadas, funciona si se pone en el lugar correcto
echo '<!-- Global Site Tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-107861100-1"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag(\'js\', new Date());

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