Support » Plugin: Code Snippets » Is this the proper code to connect to Google Analytics?

  • @bungeshea
    Hi Shea.
    First I want to thank you for your plugin. It’s great for people like me who don’t know how to mess with child themes.

    A question. I’ve rebuilt my site trying to use a minimum of plugins.
    https://hangmattor.se
    I want to connect the site to Google Analytics. Most guides promotes downloading plugins for doing that. I rather use your plugin.

    The code below, is that the proper code? It seems to work, but I find it hard to believe it’s as simple as that. Can you please confirm?

    add_action( 'wp_head', function () { ?>
    	
    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=XXXXXXXXXXX"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());
    
      gtag('config', 'XXXXXXXXXXX');
    </script>
    
    <?php });
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Is this the proper code to connect to Google Analytics?’ is closed to new replies.