RELATED TO: RealHomes Theme

Google Analytics is one of the most useful services that you can install on your site to track session duration, check page views, determine the bounce rate, and many more.

In this article, we will be integrating Google Analytics without installing any third-party plugin by following two simple steps:

Step 1: Getting Google Analytics tracking ID.

Go to Analytics.Google.com and log into your account. If you don’t have an account, sign up for one and get your tracking id.

Step 2: Adding Google Analytics Code to the RealHomes

It’s recommended to use the child theme for changes to functions.php. If you don’t, your edits will simply be wiped out the next time your theme updates. A pre-built ready-to-use child theme is included in the main theme pack you downloaded from ThemeForest. It is commonly called rh-main-package.zip.

Copy and paste the following code into functions.php and  {your-tracking-id-goes-here} with the tracking id.

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

Please sign up at our support center and create a support ticket for any further assistance, and our support team will be happy to assist you.