[Resolved] Adding Google Analytics to wp_head hook

Home Forums Support [Resolved] Adding Google Analytics to wp_head hook

Home Forums Support Adding Google Analytics to wp_head hook

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #620792
    Mark

    I am trying to add GA to my wp_head hook. Below is the code GA supplies for tracking. I disguised the UA-NUMBER, of course. This is exactly what I added in the hook input box area. Am I missing something? Do I have to tick the “Execute PHP” box?

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

    gtag(‘config’, ‘UA-XXXXXX-X’);
    </script>

    #620972
    David
    Staff
    Customer Support

    Hi there,

    that looks correct, no need to check Execute PHP.
    Google provides a second piece of code, which say needs to go inside the body, this can be added to the before header hook.

    #621253
    Mark

    Thanks David,

    For anyone who is trying to do this, here’s what worked for me.

    I ended up just using the one code snippet (provided by Google) in the wp_head hook, and it works as is.

    I went to Google Analytics, Admin, Tracking Info, Tracking Code. Copied everything in the box (see snippet above). Didn’t add anything else, just the GA code snippet.

    I didn’t tick the “Execute PHP” box. And I didn’t add anything to the Before Header hook in the body. I actually couldn’t find anything about code in the body. Its working, so I’m just going to leave it as is.

    Thanks.

    #621492
    David
    Staff
    Customer Support

    Thats great to hear Mark, and thank you for providing this.

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