Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #28170
    Bryan
    Guest

    Hi.
    I have searched high and low.
    I need to add this code into the header of all my pages.

    <!-- Global site tag (gtag.js) - Google Ads: [redacted] -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=AW-[redacted]"></script>
    <script>
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('js', new Date());
    
    gtag('config', 'AW-[redacted]');
    </script>
    #28210
    Jesse Owens
    Keymaster

    Hi Bryan-

    My personal recommendation for adding Analytics or any other Google gtag script is the official Google Site Kit plugin.

    This will allow you to use Google-native tools to manage your tags as well as have access to Analytics and Search Console data directly in your Dashboard.

    That said, there are many other plugins to add gtags to your site, or you can choose to manually insert it using a plugin like Code Snippets. If you choose to go the manual route, add a function like this (Code Snippets includes an Example JavaScript Snippet you can modify):

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

    Keep in mind that I’ve redacted your personal gtag identifier code, so don’t copy and paste this code directly- use the code you were provided by Google.

Viewing 2 posts - 1 through 2 (of 2 total)
  • The topic ‘Need to know how to add this to some page headers’ is closed to new replies.