Add Google Analytics Script

Add a Google Analytics tracking script to your site.

<?php
function add_google_analytics() {
    ?>
    <script async src="https://www.googletagmanager.com/gtag/js?id=YOUR_GA_TRACKING_ID"></script>
    <script>
        window.dataLayer = window.dataLayer || [];
        function gtag(){dataLayer.push(arguments);}
        gtag('js', new Date());
        gtag('config', 'YOUR_GA_TRACKING_ID');
    </script>
    <?php
}
add_action('wp_head', 'add_google_analytics');

Post Comment