Google analytics

Google analytics provides insights into who is using your site and what pages are being viewed. To use google analytics what I needed to do was to add a function into my functions.php called my_react_google_analytics. The —– is a placeholder for the tracking code provided by google analytics.


function my_react_google_analytics() {
        <!-- Global site tag (gtag.js) - Google Analytics -->
        <script async src=""></script>
        window.dataLayer = window.dataLayer || [];
        function gtag(){dataLayer.push(arguments);}
        gtag('js', new Date());
        gtag('config', '------');

To use the function I then add an action for wp_head into my functions.php.

wp_head action

add_action('wp_head', 'my_react_google_analytics');