Support » Plugin: WP Maintenance Mode » Analytics gtag

  • Resolved Wendihihihi

    (@wendihihihi)


    Hi,

    I’m use the gtag tracking script. Your plugin still uses the old tracking system, analytics.js. How can I manually add the tracking script I am using?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author George J

    (@georgejipa)

    Hello @wendihihihi,

    You can use wpmm_head hook to add gtag.js script.

    Example:

    
    // this snippet should be placed inside functions.php of your theme or child-theme
    add_action('wpmm_head', 'wpmm_head_gtag_script');
    
    function wpmm_head_gtag_script() {
    	echo "<script async src=\"https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXX\"></script>
            <script>
                window.dataLayer = window.dataLayer || [];
                function gtag() {
                    dataLayer.push(arguments);
                }
                gtag('js', new Date());
    
                gtag('config', 'UA-XXXXXXX');
            </script>";
    }
    

    You have to replace UA-XXXXXXX with your real Google Analytics ID.

    George

    • This reply was modified 1 year, 7 months ago by George J.
    • This reply was modified 1 year, 7 months ago by George J.
    • This reply was modified 1 year, 7 months ago by George J.

    Thanks George, very helpful.

    • This reply was modified 1 year, 7 months ago by Wendihihihi.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Analytics gtag’ is closed to new replies.