Log in

Control Panel Webmail Website Builder Online Shop File Manager WordPress

Installing Google Analytics in WordPress: A guide with 3 methods

Easy guide to get started with Google Analytics in WordPress

Have you launched your new WordPress website? Then it’s time to install Google Analytics in WordPress to understand your visitors.  

In this article, we’ll guide you through three methods so you can choose the one that suits you best. These methods are: 

  • WordPress plugins 
  • Code 
  • Google Tag Manager 

Before we explain each method, there’s one step you’ll need to take, regardless of which method you select. 

Create your website with WordPress

Start building your site with the world’s most popular cms.

Choose a package
  • 40+ free and unique one.com themes
  • Stable and ultra-fast hosting
  • Free SSL certificate
  • Mobile friendly
  • 1-click install
  • 24/7 support

Create a Google Analytics account 

Before you can install Google Analytics on your WordPress website, you’ll need to create a Google account. Visit Google Analytics and set up your account if you haven’t already done so. 

You can read through our article on getting started with Google Analytics, where you can learn more about what Google Analytics is, how it works, and what you can do with it. 

Once you have a Google Analytics account, you’ll need one of two things: either a Measurement ID (which looks something like ‘G-JHFNEZN4P1’) or a code, which you can find by heading to Google Analytics and following these steps: 

  1. Click on Admin 
  2. Select Data Streams 
  3. Create or select a data stream (this is where you’ll find the Measurement ID) 
  4. Click on Configure Tag Settings 
  5. Click Installation Instructions 
  6. Choose Install Manually 

            Depending on the method you select, we’ll explain if or when you’ll need the Measurement ID or code. 

            Install Google Analytics with a WordPress plugin 

            If you’re a WordPress beginner, we recommend using a plugin to connect Google Analytics to WordPress. The advantage of a plugin is that it’s easy to install and manage. It also simplifies compliance with data collection regulations. 

            The downside of plugins is that they need updates and might affect your website’s performance, stability, or security. However, these risks are minimal if you use the plugins we recommend. You can also let us handle WordPress maintenance for you with Managed WordPress.  

            Overall, plugins are usually the best option for beginners wanting to install Google Analytics in WordPress. 

            Here are two plugins we recommend: 

            Google Site Kit

            Google Site Kit is a plugin developed by Google that allows you to connect your website to various Google services. In addition to Google Analytics, Site Kit supports other services such as Google Search Console, PageSpeed Insights, Tag Manager, Ads, and AdSense. 

            After installing and activating Google Site Kit, you can link your Google account. The plugin handles all necessary permissions, allowing you to select the correct account and Measurement ID within the plugin. This method means you won’t need to retrieve any code from Google Analytics; everything is handled automatically. 

            GA Google Analytics

            Google Site Kit is a great plugin that can help you access several Google services. However, if you only want to connect Google Analytics to WordPress without all the extras, GA Google Analytics is a simpler option. It’s much smaller than Site Kit and very easy to use. 

            All you need for GA Google Analytics is your Measurement ID. Go to Settings and Google Analytics, choose Plugin Settings, and paste your Measurement ID. Ensure GA4 is selected as the Tracking Method, then click Save Changes

            Use a WordPress theme 

            Some WordPress themes come with built-in support for Google Analytics. There might be a field in your theme settings where you can enter your Measurement ID. This isn’t available in all themes, but if your theme does support Google Analytics, this is usually the easiest option. Just remember that Google Analytics will stop working if you switch themes in the future. 

            Install Google Analytics using code 

            You can install Google Analytics in WordPress without using a dedicated plugin or being restricted to a specific theme. When you use code, you reduce the number of plugins and have complete control. 

            Code plugin 

            One option is to use a code plugin to add Google Analytics to WordPress. You might think: isn’t the whole point of using code to avoid plugins? You’re right, and we’ll get to a method that doesn’t require any plugins, but there are benefits to using a code plugin. 

            One advantage is that you may need the plugin anyway to add other scripts to your website. With a code plugin, you can add Google Analytics and other features using the same tool. 

            There are many code plugins for WordPress. One good option is WPCode. Here’s how to get started with WPCode: 

            1. Install WPCode and activate it in WordPress. 
            2. Click Code Snippets in the sidebar. 
            3. Choose Header & Footer
            4. Paste your Google Analytics code into the Header field. 
            5. Click Save Changes

              Child theme 

              A child theme allows you to modify a WordPress theme without overwriting changes when the theme is updated. This method is ideal for users who are comfortable editing WordPress files. You can learn more about creating a child theme in WordPress in our article. 

              Once you’ve created a child theme, you can add the Google Analytics code to your child theme’s functions.php file. Start by creating the functions.php file if it doesn’t already exist. Then, add the following code, inserting your Google Analytics code where indicated. Only use this method if you’re confident with PHP, as incorrect code can break your WordPress website. 

              <?php
              add_action('wp_head', 'add_google_analytics');
              function add_google_analytics() { ?>
              
              <!--Google Analytics-kod här-->
              
              <?php } ?>

              Alternatively, you can add the code to header.php if your theme includes this file. Make sure to copy the content of header.php, add it to the header.php file of your child theme, and then add the Google Analytics code. 

              Use Google Tag Manager 

              Another method for adding Google Analytics to WordPress is using Google Tag Manager. With Google Tag Manager, you can easily manage tags on your website. You add Google Tag Manager once and make updates or add new tags (code) through Google without needing to alter your website’s code directly. 

              To use Google Tag Manager, you first need to create an account. You can activate Google Tag Manager in WordPress using Google Site Kit, as described earlier. Alternatively, you can use the plugin GTM4WP. Once Google Tag Manager is set up in WordPress, you can configure a Google tag in Tag Manager

              Any future changes can be made through Google Tag Manager without editing your website. 

              Check that everything works 

              It can take up to 48 hours for Google Analytics to display data from your website. Don’t worry if you don’t see any data immediately. If there’s still no data after 48 hours, something has gone wrong, and you must double-check your installation. 

              With some manual methods, you can use Google Analytics’ built-in test tool to check that your code is working. Here’s how: 

              1. Click on Admin
              2. Select Data Streams
              3. Choose your data stream. 
              4. Click Configure Tag Settings
              5. Click Installation Instructions
              6. Select Install Manually
              7. Enter your website address under Test your website
              8. Click Test

              In the UK and EU, user consent is required for the collection of personal data, including via Google Analytics. There are several ways to obtain consent for Google Analytics. If you’re using Google Site Kit, it supports the WP Consent API, which communicates consent between plugins.  

              One consent plugin that works with WP Consent API is Complianz. With Complianz, you can ensure that only users who have consented are being tracked by Google Analytics. 

              Start using Google Analytics 

              Now that you’re collecting data through Google Analytics, it’s time to start analysing your data. Google Analytics can help you understand your visitors, see which content they’re most interested in, and figure out how to keep them engaged. Here are a few things you can do with Google Analytics: 

              Create your website with WordPress

              Start building your site with the world’s most popular cms.

              Choose a package
              • 40+ free and unique one.com themes
              • Stable and ultra-fast hosting
              • Free SSL certificate
              • Mobile friendly
              • 1-click install
              • 24/7 support