Site logo

[Resolved] Google Analytics script in wp_head

Home Forums Support [Resolved] Google Analytics script in wp_head

Home Forums Support Google Analytics script in wp_head

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1566892
    Ivan

    Hi,
    In En Appearance -> Elements -> Legacy Hooks -> wp_head
    Would it be okay to paste the Google Analytics code?
    I say this because there is the meta data that is html and the Google Analytics code is a script
    If I paste it there, the whole web will take it, right?
    thanks,

    <head>
    <title>EMCO LIMPIEZAS</title>
    <meta name=”Inicio” content=”Servicios profesionales de limpieza en Valencia España”>
    <meta name=”Empresa” content=”Información sobre la empresa”>
    <meta name=”Servicios” content=”EMCO, Servicios de Limpieza, Limpieza de Comunidades, Limpieza de Oficinas, Limpieza de Despachos, Limpieza de Comercios, Limpieza de Cristales, Limpieza de Garajes, Vitrificado y Abrillantado, Limpieza Fin de Obra”>
    <meta name=”Contacto” content=”Datos de Contacto”>

    // Codigo Google Analytics
    <!– Global site tag (gtag.js) – Google Analytics –>
    <script async src=”https://www.googletagmanager.com/gtag/js?id=G-0WFG04H5CP”></script&gt;
    <script>
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag(‘js’, new Date());
    gtag(‘config’, ‘G-0WFG04H5CP’);
    </script>
    // FIN Codigo Google Analytics

    </head>

    #1566939
    Elvin
    Staff
    Customer Support

    Hi,

    To clarify: You’re trying to hook your google analytics code to your wp_head?

    If so, then Appearance -> Elements -> Hook element is definitely a good way to add it in.
    https://docs.generatepress.com/article/hooks-element-overview/

    But be specific, you will only need this to add in to the Hook element:

    // Codigo Google Analytics
    <!– Global site tag (gtag.js) – Google Analytics –>
    <script async src=”https://www.googletagmanager.com/gtag/js?id=G-0WFG04H5CP”></script>
    <script>
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag(‘js’, new Date());
    gtag(‘config’, ‘G-0WFG04H5CP’);
    </script>
    // FIN Codigo Google Analytics

    And perhaps you can add the meta tags as well if its not already automatically added in.

    To shed more light on this matter:

    You don’t need to add <head>..</head> & <title>...</title> as it already exist and wp_head is basically the hook we use to place within the existing <head> tag of the page.

    Title tag is automatically generated by WordPress when you created the page, the text string inside it is taken from the title you set when you created the page.

    #1566962
    Ivan

    Hi Elvin, “You’re trying to hook your google analytics code to your wp_head?” -> yes i’m trying to connect google analytics code with wp_head.
    So what I have done I understand that it is good?
    I have deleted the <head> from wp_head.
    Gracias,

    #1567601
    David
    Staff
    Customer Support

    Hi there,

    yes that is good 🙂

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.