1. Documentation
  2. How to
  3. Install Google Analytics

Install Google Analytics

Google Analytics provides invaluable insights into your website’s traffic and user behavior. Follow these simple steps to integrate Google Analytics with your WordPress site.

Method 1: Using a plugin

MonsterInsights is the most popular Google Analytics plugin for WordPress. Over 1 million websites use it, including Bloomberg, PlayStation, Zillow, and more.

Install the plugin:

  1. Go to your site admin area.
  2. Navigate to Plugins -> Add New.
  3. Search for “Google Analytics for WordPress“.
  4. Install and activate the plugin.

Configure the plugin:

  1. Go to your site admin area -> click the Insights menu item.
  2. Launch the setup wizard to connect to Google Analytics.

Method 2: Adding code via theme hook

This method requires having the child theme installed and activated – learn how to install the child theme. Using a child theme’s functions.php file allows you to add Google Analytics code without directly modifying the theme. Here’s how to do it for our themes:

  1. Go to your site admin area.
  2. Navigate to Appearance > Theme File Editor.
  3. Ensure that your active child theme is selected from the dropdown in the upper-right corner.
  4. On the right side, find and click on Theme Functions (functions.php).
  5. Scroll to the bottom of the functions.php file and add the following code snippet:
function add_google_analytics_code() {
    <script async src="https://www.googletagmanager.com/gtag/js?id=YOUR_ANALYTICS_ID"></script>
        window.dataLayer = window.dataLayer || [];
        function gtag(){dataLayer.push(arguments);}
        gtag('js', new Date());
        gtag('config', 'YOUR_ANALYTICS_ID');
add_action('keydesign_head_bottom', 'add_google_analytics_code');

Important: replace YOUR_ANALYTICS_ID with your actual Google Analytics Tracking ID.

Now, your WordPress site is integrated with Google Analytics, providing you with essential data to enhance your online presence.

Was this article helpful?