Select Page

How to Install Google Analytics in WordPress

by | Nov 29, 2022 | Tutorials

Google Analytics (GA) is an essential tool for any website owner. It provides in-depth insights into your site’s traffic, user behavior, and overall performance. Integrating Google Analytics with WordPress allows you to track your site’s visitors, understand their behavior, and make data-driven decisions to enhance their experience. This guide will walk you through the step-by-step process of installing Google Analytics on your WordPress website.

Google Analytics is a powerful, free tool that helps you understand your website’s traffic and user interactions. By integrating GA with your WordPress site, you can gather valuable data about where your visitors come from, which pages they visit, how long they stay, and much more. This information is crucial for optimizing your website’s performance, improving user experience, and ultimately driving more conversions and revenue.

Integrating Google Analytics with WordPress is a straightforward process that can be done in several ways. Whether you’re a beginner or a seasoned developer, this guide will help you choose the best method for your needs and walk you through each step to ensure a successful installation.

Before installing Google Analytics on your WordPress site, there are a few preparatory steps you need to take.

Create a Google Analytics Account

The first step is to create a Google Analytics account. Here’s how you can do it:

  1. Go to the Google Analytics website: Visit Google Analytics and click on the “Start for free” button.
  2. Sign in with your Google Account: If you already have a Google account, sign in. If not, you’ll need to create one.
  3. Set up an account: After signing in, you’ll be prompted to set up a new account. Enter your account name (this could be your business name or website name).
  4. Set up a property: A property represents your website or app in Google Analytics. Enter the property name (typically your website name), select your time zone, and choose your currency.
  5. Choose the data sharing settings: Select the data sharing options you prefer. These settings determine what data you share with Google.
  6. Create the property: Click “Next” and provide your website details. Choose “Web” as the platform for a website and enter your website’s URL. Click “Create” to finish setting up your property.

Understanding Google Analytics 4 (GA4) and Universal Analytics

When setting up Google Analytics, you might notice two versions: Google Analytics 4 (GA4) and Universal Analytics. Here’s a brief overview of the differences:

  • Google Analytics 4 (GA4): The latest version of Google Analytics, GA4, is designed to provide more intelligent insights into user behavior, leveraging machine learning and offering better integration with Google Ads. It is more flexible and provides more granular data tracking across websites and apps.
  • Universal Analytics: The older version that many are still familiar with. It focuses more on tracking sessions and page views and is less event-driven compared to GA4.

Which one should you choose?
For most new users, Google Analytics 4 is recommended due to its advanced features and future-proof capabilities. However, if you’re more familiar with Universal Analytics or have specific reasons to use it, you can still set it up.

Getting Tracking Code

After setting up your Google Analytics account and property, the next step is to get the tracking code or Measurement ID that you’ll add to your WordPress site.

Setting Up a Property in Google Analytics

  1. Navigate to Admin Settings: In your Google Analytics account, go to the Admin section by clicking the gear icon in the lower-left corner.
  2. Select Your Property: In the Property column, ensure your newly created property is selected.
  3. Create Data Stream: Under Property, click on “Data Streams” and then select “Web” since we are integrating with a website.
  4. Enter Your Website URL: Input your website’s URL and give the data stream a name. Make sure to enable “Enhanced Measurement” for more detailed tracking.
  5. Get Your Measurement ID: Once the data stream is created, you’ll be presented with a Measurement ID (for GA4) or a Global Site Tag (gtag.js) code (for Universal Analytics). This is the code you’ll need to install on your WordPress site.

Retrieving the Google Analytics Tracking Code

  1. Google Analytics 4: Copy the Measurement ID (e.g., G-XXXXXXXXXX).
  2. Universal Analytics: Copy the Global Site Tag (gtag.js) code snippet. This is a JavaScript code that needs to be added to every page you want to track.

Installing Google Analytics in WordPress

There are several ways to install Google Analytics in WordPress. The method you choose depends on your comfort level with code and your preferences for using plugins.

Method 1: Using a WordPress Plugin

Installing Google Analytics using a plugin is the easiest and most popular method for WordPress users.

Popular Plugins for Google Analytics

  • MonsterInsights: The most popular Google Analytics plugin for WordPress. It offers an easy setup, advanced tracking options, and a user-friendly interface to view your analytics data directly in your WordPress dashboard.
  • Site Kit by Google: Official plugin from Google that integrates not only Google Analytics but also Search Console, AdSense, and PageSpeed Insights.
  • GA Google Analytics: A lightweight plugin that simply adds the tracking code to your WordPress site without any extra features.

Step-by-Step Guide for Installing a Plugin

  1. Install and Activate the Plugin: Go to your WordPress dashboard, navigate to Plugins > Add New, and search for the plugin (e.g., MonsterInsights). Click “Install Now,” then “Activate.”
  2. Configure the Plugin Settings: Follow the setup wizard or instructions provided by the plugin. You’ll need to connect your Google Analytics account to the plugin by logging in with your Google account and allowing the necessary permissions.
  3. Select the Correct Property: Choose the Google Analytics property you created earlier for your WordPress site.
  4. Adjust Advanced Settings: Depending on the plugin, you may have additional settings to configure, such as excluding admin users from tracking, enabling enhanced link attribution, or setting up custom dimensions.

Method 2: Adding the Tracking Code Manually

If you prefer not to use a plugin or want more control over how the code is added, you can manually add the Google Analytics tracking code.

Inserting Code Directly into the Theme

  1. Access Your Theme Files: Go to your WordPress dashboard and navigate to Appearance > Theme Editor. Select the header.php file.
  2. Insert the Tracking Code: Paste the Google Analytics tracking code snippet directly before the closing </head> tag in your header.php file.
  3. Save Your Changes: Click “Update File” to save your changes.

Note: If you’re using this method, it’s highly recommended to use a child theme to prevent your changes from being overwritten during theme updates.

Using the WordPress Customizer or Code Snippets Plugin

  1. Using the WordPress Customizer: Go to Appearance > Customize > Additional CSS/JS and paste your tracking code.
  2. Using a Code Snippets Plugin: Install a plugin like “Insert Headers and Footers” or “Code Snippets.” Navigate to the plugin settings and add your tracking code to the header section.

Verifying Google Analytics Installation 

Once you have installed the Google Analytics tracking code on your WordPress site, you need to verify that it is working correctly.

Using the Google Analytics Real-Time Report

  1. Navigate to the Real-Time Report: In your Google Analytics dashboard, go to Reports > Real-Time > Overview.
  2. Visit Your Website: Open your website in a new tab. If the tracking code is installed correctly, you should see your visit reflected in the Real-Time report.

Using Browser Extensions

  1. Google Tag Assistant: A Chrome extension that checks for Google Analytics and other Google tags on your website. It will show if your tags are firing correctly or if there are any issues.
  2. GA Debugger: Another Chrome extension that provides detailed information about the data being sent to Google Analytics from your website.

Configuring Google Analytics for WordPress

To get the most out of Google Analytics, you need to configure it to track specific actions and events on your WordPress site.

Setting Up Goals and Conversions

  1. Navigate to the Goals Section: Go to Admin > View > Goals in your Google Analytics account.
  2. Create a New Goal: Click the “New Goal” button and choose from a template or set up a custom goal.
  3. Define Your Goal: Select the goal type (e.g., destination, duration, pages/screens per session, event), then configure the goal details.
  4. Verify and Save: Test your goal to ensure it’s set up correctly, then click “Save.”

Enabling Enhanced E-commerce Tracking (if applicable)

  1. Enable E-commerce Tracking in Google Analytics: Go to Admin > View > E-commerce Settings and enable “E-commerce” and “Enhanced E-commerce Reporting.”
  2. Install an E-commerce Plugin: For WordPress sites using WooCommerce or similar, install a compatible plugin that supports enhanced e-commerce tracking.
  3. Configure Plugin Settings: Follow the plugin’s instructions to connect it with your Google Analytics account and enable enhanced tracking features.

Excluding Internal Traffic

  1. Create a Filter to Exclude Internal Traffic: Go to Admin > View > Filters > Add Filter.
  2. Set Filter Type to “Exclude”: Choose “Exclude” and filter by IP address. Enter your IP address and save the filter.
  3. Test the Filter: Make sure the filter is working by checking your Real-Time report and verifying that internal visits are not being tracked.

Advanced Google Analytics Settings for WordPress

Once you have the basics down, you can start exploring some of the more advanced features of Google Analytics.

Integrating Google Search Console with Google Analytics

  1. Link Google Search Console to Google Analytics: Go to Admin > Property Settings > Adjust Search Console.
  2. Select Your Property: Choose the Search Console property that matches your Google Analytics property and click “Save.”
  3. Access Search Console Reports in GA: Navigate to Acquisition > Search Console in your Google Analytics dashboard to view the linked data.

Enabling Site Search Tracking

  1. Enable Site Search Tracking: Go to Admin > View Settings and turn on “Site Search Tracking.”
  2. Enter Your Query Parameter: Input the query parameter (e.g., “s” or “q”) used by your WordPress search form.
  3. Save Settings: Click “Save” to start tracking site search queries.

Using Custom Dimensions and Metrics

  1. Create Custom Dimensions and Metrics: Go to Admin > Property > Custom Definitions > Custom Dimensions/Metrics.
  2. Define Your Custom Dimension/Metric: Enter a name and scope for your custom dimension or metric, then save it.
  3. Implement the Custom Dimension/Metric on Your Site: Use a plugin or manual code insertion to track specific actions or events related to your custom dimensions.

Troubleshooting Common Issues

Sometimes, things might not go as planned. Here’s how to troubleshoot common Google Analytics installation issues.

Common Installation Issues and Fixes

  • Tracking Code Not Firing: Ensure the tracking code is correctly placed in the <head> section and is not being blocked by ad blockers or browser settings.
  • Data Not Appearing in GA: It may take up to 24 hours for data to appear. If not, verify your tracking code installation and check for any errors.
  • Plugin Conflicts: Disable other plugins temporarily to see if there’s a conflict causing the issue.

Monitoring for Data Accuracy

  • Regularly Check for Discrepancies: Compare data between Google Analytics and other tools like Google Search Console or server logs to identify discrepancies.
  • Audit Your Account Settings: Regularly audit your Google Analytics account settings to ensure everything is configured correctly and working as expected.

Conclusion

Integrating Google Analytics with your WordPress website is a crucial step in understanding your audience and optimizing your site’s performance. By following this guide, you’ll be able to set up Google Analytics correctly, gain valuable insights into your visitors’ behavior, and make data-driven decisions to grow your online presence. Don’t forget to regularly check your analytics data and adjust your settings as needed to get the most out of this powerful tool.

Additional Resources

  • Google Analytics Help Center – Official documentation and resources.
  • MonsterInsights Blog – Tips and tutorials for using Google Analytics on WordPress.
  • Google Analytics Academy – Free courses to deepen your understanding of Google Analytics.

By following this comprehensive guide, you will have a solid understanding of how to install and configure Google Analytics on your WordPress website, providing you with the insights needed to improve your site’s performance and user experience.