How to Add Google Analytics 4 to WordPress?


GA4 to WordPress feature image

Get Your Free Website Audit

($3,000 Value)

  • Uncover performance issues
  • Identify SEO opportunities
  • Security gaps, and quick wins
Get Your Free Audit!

Table of Contents

As of July 1, 2023, Google no longer supports the older version of Universal Google Analytics, hence it’s important for website owners to switch to Google Analytics 4: a new GA property. Since the Universal Analytics property is no longer accessible, switching to GA4 is a must.

The purpose of this post is to provide guidance on installing Google Analytics 4 on a WordPress site or a WooCommerce shop. This guide is a good starting point depending on whether you are a beginner to GA or a seasoned pro.

What is Google Analytics 4?

Google Analytics 4 (GA4) is the latest version of Google Analytics, designed to provide advanced insights through event-based tracking rather than session-based data. Advanced features in GA4 include cross-platform tracking for website’s performance and apps, AI-driven insights, privacy-focused data collection, and enhanced reporting for user engagement and conversion tracking.

ga 4 features

This version integrates seamlessly with WordPress, whether through plugins like Google Site Kit or manual implementation using the GA4 Measurement ID. It stands out for its flexibility, focusing on future-proofing analytics and evolving privacy regulations.

Switching from Universal Analytics to GA4

Google Analytics 4 (GA4) introduces a fundamentally different approach to enhanced tracking and reporting compared to Universal Analytics (UA).

While UA is session-based, GA4 uses an event-based model, allowing us to gain insights into user interactions on the website. It tracks everything from clicks on the website, and form submissions to details of how visitors interact on the website.

Key Changes in GA4

  • Event-Based Tracking: Every user interaction (click, scroll, purchase) is treated as an event, offering more detailed data.
  • Cross-Platform Support: Seamless integration of data across websites and mobile apps in one place.
  • Simplified Reporting: Fewer pre-configured reports, emphasizing custom reports and exploration tools.
  • Privacy-Focused Features: Automatic IP anonymisation, cookie-less tracking, and data retention policies
  • Improved Conversions: Flexible event setup allows for better customisation of goals and conversions based on the needs of the business.

Switching to GA4 ensures your analytics setup is aligned with future tracking standards while offering enhanced insights for your WordPress site.

Requirements for Adding GA4 to WordPress

Before integrating Google Analytics 4 (GA4) with your WordPress site, you need to ensure a few essential prerequisites are in place. Here’s a step-by-step guide to help you prepare for the integration:

Step 1: Create a Google Account (If You Don’t Have One)

  • Visit accounts.google.com.
  • Click “Create account” and select “For myself” or “For my business”, depending on your needs.
  • Fill in the required details (name, birth date, email, and password) and complete the account setup.
Create Google Account

Step 2: Sign Up for Google Analytics

  • Go to analytics.google.com and log in using your Google account.
  • Click “Start measuring” to begin creating your first property.

google analytics login page

Step 3: Create a Google Analytics 4 Property

  • On the setup screen, provide your account name and property name. Example: Account Name: Your Business Name, Property Name: Website GA4.
google analytics login
  • Choose your reporting time zone and currency.

GA4 create property name
  • Click Next, and select your industry category and business size.

business details
  • Click Next, and choose the business objectives. You can select multiple if you like.
business objectives
  • Click Create and accept the Google Analytics terms and conditions

Step 4: Obtain Your GA4 Measurement ID

  • Once the property is created, navigate to Admin > Data Streams.
  • Select Web as your platform and enter your website URL and stream name
Property setup screen
  • After creating the stream, you’ll see a Measurement ID (e.g., G-XXXXXXXXX). Copy this ID—it will be required for integration.
google analytics measurement ID

Step 5: Verify WordPress Compatibility

  • Check if your WordPress theme or builder supports custom scripts in the header (most do).
  • Confirm you have admin access to your WordPress dashboard to make changes.
  • Alternatively, identify a plugin like Site Kit by Google or MonsterInsights for easy integration

Step 6: Define Your Tracking Goals

  • Decide what actions you want to track (e.g., page views, form submissions, downloads).
  • Plan for any custom events or conversions you may need to set up later.

How To Add Google Analytics 4 to WordPress?

There are several ways to seamlessly connect GA4 to your WordPress website. You can either leverage WordPress plugins for ease or embed the tracking code manually, or harness the power of Google Tag Manager for advanced setups based on your convenience.

Using a WordPress plugin is the easiest way to add GA4 to your WordPress site, especially for beginners. There are many plugins available in the extensive plugin ecosystem, Site Kit by Google is often the best option because of its user-friendly interface. Follow these simple steps:

Step 1: Install a Google Analytics Plugin

  • Log in to your WordPress dashboard.
  • Go to Plugins > Add New.
add a new plugin
  • In the search bar, type a plugin named Site Kit by Google.
  • Click Install Now and then Activate once the plugin is installed.

install site kit

Step 2: Access Plugin Settings

  • After activation, click the “Start Setup” to begin the setup process.
site kit setup
  • The setup wizard will open up. Click “Sign in With Google“.

sign in with google

Step 3: Connect to Your Google Account

  • Once you sign in, click Allow to authorise a handful of permissions.
authorise permissions
  • If you have already added Google Search Console to WordPress, Sit Kit will integrate it automatically. If you haven’t, click Add site.

add google search console
  • The Site Kit does the rest and the setup is complete.

finish site kit setup

Step 4: Configure Tracking Options

  • Once you’ve completed the setup wizard, you can customise which services you want to add. Since we are setting up GA4, click on the Analytics option.
connect google analytics
  • Select the Account, Property and View options and click Configure Analytics to finish the setup.

configure google analytics

Step 5: Verify Data Collection

  • View Site Kit dashboard which will look something like this.
site kit dashboard
  • If you want more detailed data from Google Analytics, go to Analytics directly from your WordPress dashboard.

google analytics data
  • Also, Log in to your Google Analytics account to view the full stats.
  • Go to the Realtime section in your GA4 dashboard to confirm that your website traffic and data is being tracked.
google analytics dashboard

Method 2: Adding the GA4 Tracking Code Manually

Adding the GA4 tracking code manually is a straightforward process if you’re comfortable making small changes to your WordPress theme. Here’s a step-by-step guide:

Step 1: Get Your GA4 Tracking Code

  • Log in to your Google Analytics account.
  • Navigate to Admin > Data Streams under your GA4 property.
  • Select your website stream and scroll to View tag instructions.

gtag instructions
  • Click Install Manually and copy the entire section of the code beginning with”<!– Google tag (gtag.js) –>”

gtag

Step 2: Access Code Snippets plugin

  • Log in to your WordPress dashboard.
  • Go to Code Snippets>Header & Footer. If you do not have this plugin, install Code Snippets from the Plugins section on the WordPress sidebar.

code snippets
  • Paste the Google Tag code to the header section and click Save Changes.

add global site tag to the header section

Step 4: Verify the Code

  • It might take up to 48 hours to send data
  • To verify, go to the Realtime section in your GA4 dashboard to see live data being tracked.

Method 3: With Google Tag Manager

Google Tag Manager (GTM) is a powerful tool for managing tags and scripts on your website, including Google Analytics 4 (GA4). Here’s a step-by-step guide:

Step 1: Set Up a Google Tag Manager Account

  • Visit Google Tag Manager and log in with your Google account.
  • Click Create Account and fill in your account name and container setup (Account Name: Enter your business or website name. Container Name: Enter your website domain and select Web as the platform)
google tag manager account
  • Click Create, then review and accept the terms of google services.

Step 2: Add the GTM Code to Your WordPress Site

  • After creating the container, GTM will provide two code snippets. Head Snippet and Body Snippet. Copy both snippets.
google tag manager code
  • Follow the same procedure mentioned above by using the Code Snippets plugin in your WordPress dashboard.
  • In addition to the Header section, in this case, copy the tag and paste it to the Body section in the Code Snippets.
body tag
  • Save your changes and ensure GTM is installed correctly.

Step 3: Create a GA4 Configuration Tag in GTM

  • Log in to your GTM workspace and click Tags > New.
add a new tag
  • Name your tag (e.g., “GA4 Configuration”).
  • Click Tag Configuration and select Google Analytics: GA4 Configuration.

tag type
  • Select Google Analytics: GA4 Event. Enter your GA4 Measurement ID (found in your GA4 property under Admin > Data Streams) and name the event “GA4”

GA4 tag id

Step 4: Set a Trigger for the Tag

  • In the same tag setup, click Triggering and select All Pages. This ensures the GA4 tag fires on every page of your website.
GA4 tag id
  • Save the tag.

Step 5: Publish Your Tag Manager Changes

  • In GTM, click Submit in the top-right corner.

submi the tag
  • Add a name and description for the version (e.g., “Added GA4 Tracking”).
  • Click Publish to make your changes live.

Step 6: Verify Tracking

  • Open your website and ensure the GTM container is loading correctly.
  • It can take up to 24 hours to get the data to the GA4. In the meantime, test your setup with Tag Assistant.
  • Click Preview within Tag Manager, enter your website’s URL, and click Connect.
check if the tag has fired
  • Your website will open in a separate tab. In the Tag Assitant, you will see that your GA4 Configuration tag has fired.
  • Click on the fired GA4 tag and make sure that the page view event is not sent to a separate account by comparing the Measurement ID.
fired tags
  • Go to the Realtime report in your GA4 dashboard to verify data collection.

Common Issues and Troubleshooting Tips

Issue 1: Beginners often place the Measurement ID in the wrong location, leading to no tracking.

Solution: To ensure proper placement, it’s best to use a plugin like Google Site Kit that automatically handles the configuration. If you’re adding the script manually, insert it into the section of your WordPress site. You can do this by using a plugin like Code Snippets, which allows you to add custom scripts without directly modifying theme files.

Issue 2: GA4 data is not showing despite following the setup process.

Solution: First, clear both your browser and website cache to ensure the tracking script is active. Test whether the GA4 tag is firing using other Google tools like Google Tag Assistant or the GA Debugger browser extension. Additionally, ensure that Enhanced Measurement is enabled in your GA4 settings (found under Admin > Data Streams > Enhanced Measurement).

Issue 3: Manually added GA4 scripts in theme files (like header.php) get overwritten after a theme update.

Solution: To avoid this issue, never modify core theme files directly. Instead, use a child theme for customisations, or better yet, rely on a plugin like Coder Snippets to add your GA4 script in a way that persists across theme updates.

Need Help Configuring a GA4 Property?

We have the expertise you need to elevate your WordPress website and unlock its full potential. Whether you’re looking to optimise your site’s speed, enhance your analytics, or scale your online business to new heights, our team of skilled developers at WP Creative is here to help. With proven strategies and a results-driven approach, we’ll ensure your site is built for success.

Ready to take your site to the next level? For expert support with web development, SEO, and analytics integration, book a consultation with WP Creative today and let us help you achieve your digital goals!

Slow website wasting your marketing spend?

  • Uncover performance issues
  • Identify SEO opportunities
  • Security gaps, and quick wins
Grab your FREE copy now!

Conclusion

Integrating Google Analytics 4 (GA4) into your WordPress site is essential for tracking and understanding user behaviour, helping you make data-driven decisions for growth. Google Analytics 4 (GA4) is an important tool to track your user behaviour and optimise site performance. The advanced features help to get deeper insights into user journeys.

Each of the methods mentioned above empowers you to unlock the power of GA4’s cutting-edge reporting and predictive analytics, tailored to your site’s needs.

Looking for the Best Analytics Plugins for WordPress? Check out our top recommendations.

Get Your Free Website Audit

($3,000 Value)

  • Uncover performance issues
  • Identify SEO opportunities
  • Security gaps, and quick wins
Get Your Free Audit!


Updated on: 10 March 2025 |


Nirmal Gyanwali, Director of WP Creative

Nirmal Gyanwali

With over 16 years of experience in the web industry, Nirmal has built websites for a wide variety of businesses; from mom n’ pop shops to some of Australia’s leading brands. Nirmal brings his wealth of experience in managing teams to WP Creative along with his wife, Saba.