How to Set Up Google Analytics 4 (GA4) on Your WordPress Website

Understanding how users interact with your WordPress website is crucial for its growth and success. Google Analytics 4 (GA4) is Google’s latest generation of analytics, designed to give you a more unified understanding of your customer journey across websites and apps, with a stronger focus on events rather than sessions. If you’ve been using Universal…

Understanding how users interact with your WordPress website is crucial for its growth and success. Google Analytics 4 (GA4) is Google’s latest generation of analytics, designed to give you a more unified understanding of your customer journey across websites and apps, with a stronger focus on events rather than sessions. If you’ve been using Universal Analytics (UA), you’ll notice GA4 is a significant shift, offering enhanced machine learning capabilities and privacy-centric design.

This tutorial will guide you step-by-step through the process of setting up Google Analytics 4 on your WordPress website, ensuring you can start collecting valuable data to inform your decisions.

Prerequisites:

  • A Google Account (e.g., Gmail)
  • An active WordPress website with administrator access

Step 1: Create or Access Your Google Analytics Account (GA4 Property)

The first step is to set up a GA4 property within your Google Analytics account. If you already have a Universal Analytics account, you can create a new GA4 property alongside it.

  1. Go to Google Analytics: Open your web browser and navigate to analytics.google.com.
  2. Sign In or Create an Account:
  • If you’re new to Google Analytics, click “Start measuring” to create a new account.
  • If you have an existing account (e.g., for Universal Analytics), sign in. You’ll likely see your existing properties.
  1. Create a New Account (If needed):
  • Click “Admin” (the gear icon) in the bottom-left corner.
  • In the “Account” column, click “Create Account.”
  • Enter an Account Name (e.g., “My Website Portfolio,” “My Business Name”). This is for your overall business or organization.
  • Configure Account Data Sharing Settings as desired (usually best to leave checked for benchmarking).
  • Click “Next.”
  1. Create a New GA4 Property:
  • In the “Property setup” section, enter a Property Name (e.g., “MyWebsite.com GA4” or “Website Traffic GA4”). This is for a specific website or app.
  • Select your Reporting Time Zone and Currency. This is important for accurate data interpretation.
  • Click “Next.”
  1. Provide Business Information (Optional but Recommended):
  • Select your Industry Category (e.g., “Arts & Entertainment,” “Business & Industrial”).
  • Choose your Business Size.
  • Select your Business Objectives (e.g., “Generate leads,” “Drive online sales,” “Examine user behavior”). These choices can influence the reports you see in GA4.
  • Click “Create.”
  • You may be prompted to accept the Google Analytics Terms of Service. Review and accept them to proceed.

Tip: Even if you already have a Universal Analytics property, it’s recommended to create a separate GA4 property. GA4 cannot reuse your UA data, and they collect data differently. Running both concurrently for a while is a good strategy as you transition.


Step 2: Set Up a Data Stream for Your WordPress Website

Once your GA4 property is created, the next step is to set up a “data stream.” A data stream is essentially the source of data for your property, and for a website, it’s how GA4 knows where to collect information from.

  1. Choose a Platform: After creating your property, you’ll be redirected to the “Data streams” section. Here, you’ll choose your platform. Select “Web.”
  2. Set Up Your Web Stream:
  • Website URL: Enter the full URL of your WordPress website (e.g., ZEALTERCODE0). Make sure to select ZEALTERCODE1 or ZEALTERCODE2 correctly from the dropdown.
  • Stream Name: Give your stream a descriptive name (e.g., “MyWebsite.com Web Stream”).
  • Enhanced Measurement: This feature is enabled by default and is highly recommended. It automatically tracks various common interactions without needing additional code, such as:
  • Page views
  • Scrolls (when a user scrolls to the bottom of a page)
  • Outbound clicks (clicks that lead to another domain)
  • Site search (if your site has a search function)
  • Video engagement (for embedded YouTube videos)
  • File downloads (e.g., PDFs, documents)
  • You can toggle specific events on or off by clicking the gear icon.
  • Click “Create stream.”
  1. Locate Your Measurement ID:
  • After creating the stream, you’ll see a “Web stream details” page.
  • Look for the “Measurement ID” at the top right of the page. It will be in the format G-XXXXXXXXX.
  • Copy this Measurement ID. You will need it to connect GA4 to your WordPress website. Keep this tab open or save the ID somewhere accessible.

Example: Your Measurement ID might look like ZEALTERCODE0. This unique ID tells Google Analytics where to send the data from your website.


Step 3: Integrating GA4 with Your WordPress Site

There are several ways to add the GA4 tracking code to your WordPress website. We’ll cover the most common and recommended methods, starting with the easiest for most users.

Method A: Using Site Kit by Google (Recommended for Most Users)

Site Kit is Google’s official plugin for WordPress, making it incredibly easy to connect your site to various Google services, including Analytics, Search Console, AdSense, and PageSpeed Insights.

  1. Install and Activate Site Kit:
  • Log in to your WordPress admin dashboard.
  • Navigate to Plugins > Add New.
  • In the search bar, type “Site Kit by Google.”
  • Find the plugin by Google and click “Install Now.”
  • Once installed, click “Activate.”
  1. Start Setup:
  • After activation, you’ll see a prompt to “Start Setup” for Site Kit. Click it.
  • You’ll be redirected to Google to verify your account. Click “Sign in with Google.”
  • Select the Google Account you used to set up your GA4 property.
  • Grant Site Kit the necessary permissions by clicking “Allow.”
  1. Verify Site Ownership:
  • Site Kit will prompt you to grant access to your Google Account data. Confirm and click “Next.”
  • It will then ask to “Verify site ownership.” Click “Proceed.”
  1. Connect Google Search Console:
  • Site Kit will offer to set up Google Search Console. It’s highly recommended to do this. Click “Next.”
  • Click “Add Site” to finish the Search Console setup.
  1. Connect Google Analytics:
  • Now, you’ll be on the “Connect Google Analytics” step. Click “Connect Service.”
  • Select the Google Account again.
  • Grant permissions.
  • Site Kit will then display your available Google Analytics properties. Crucially, select your newly created GA4 property (e.g., “MyWebsite.com GA4 – G-XXXXXXXXX”) from the dropdown menu.
  • Click “Configure Analytics.”
  1. Done! Site Kit will confirm that Analytics is now set up. You’ll be redirected back to your WordPress dashboard.

Tip: Site Kit not only installs the GA4 tracking code but also provides a convenient dashboard within WordPress to view key data from Analytics, Search Console, and more.

Method B: Using MonsterInsights (Popular Analytics Plugin)

MonsterInsights is another highly popular premium plugin (with a free version) that makes integrating GA4 (and Universal Analytics) very easy, offering more advanced features and reports directly in your WordPress dashboard.

  1. Install and Activate MonsterInsights:
  • From your WordPress admin, go to Plugins > Add New.
  • Search for “MonsterInsights.”
  • Install and activate “MonsterInsights – Google Analytics Dashboard for WordPress.”
  1. Launch Setup Wizard:
  • Upon activation, the MonsterInsights setup wizard will launch. Follow the prompts.
  • Choose your website category (e.g., “Business Website,” “Blog”).
  • Click “Connect MonsterInsights.”
  1. Authenticate with Google:
  • Sign in with the Google Account associated with your GA4 property.
  • Grant MonsterInsights the required permissions.
  • Select your GA4 property from the dropdown list. MonsterInsights will automatically detect it.
  • Click “Complete Connection.”
  1. Finish Setup:
  • Continue through the remaining wizard steps, configuring recommended settings (e.g., event tracking, file download tracking). Most default settings are good to start with.
  • Click “Save and Exit Wizard.”

Tip: MonsterInsights offers extensive reports right within your WordPress dashboard, making it easier to track your site’s performance without leaving your site. Its Pro version adds even more advanced tracking options.

Method C: Manual Installation (For Advanced Users/Developers)

If you prefer not to use a plugin or need more control, you can manually add the GA4 Global Site Tag (gtag.js) to your WordPress theme. This method requires a bit more technical comfort.

  1. Retrieve the Global Site Tag (gtag.js):
  • Go back to your Google Analytics GA4 property.
  • Navigate to Admin (gear icon) > Data Streams.
  • Click on your Web stream.
  • Under “Tagging Instructions,” click “View tag instructions.”
  • Select the “Install manually” tab.
  • You’ll see a code snippet that starts with ZEALTERCODE0 and includes your Measurement ID. Copy this entire code snippet.
  1. Add the Code to Your WordPress Theme:
  • Option 1: Using a Child Theme’s ZEALTERCODE0 (Recommended for Theme Modifications)
  • This is the safest method for adding code to your theme, as it prevents updates from overwriting your changes. If you don’t have a child theme, consider creating one or using a “Custom Code” plugin.
  • From your WordPress admin, go to Appearance > Theme File Editor (or use an FTP client/cPanel File Manager).
  • Select your active child theme from the dropdown on the right.
  • Open the ZEALTERCODE0 file.
  • Add the following code to the end of the file, replacing ZEALTERCODE0 with your actual G-XXXXXXXXX ID and the full ZEALTERCODE1 script you copied:
        <?php
        function add_ga4_tracking_code() {
        ?>
            <!-- Google tag (gtag.js) -->
            <script async src="https://www.googletagmanager.com/gtag/js?id=YOUR_MEASUREMENT_ID"></script>
            <script>
              window.dataLayer = window.dataLayer || [];
              function gtag(){dataLayer.push(arguments);}
              gtag('js', new Date());

              gtag('config', 'YOUR_MEASUREMENT_ID');
            </script>
        <?php
        }
        add_action('wp_head', 'add_ga4_tracking_code');
        ?>
  • Important: Ensure you wrap the JavaScript within the ZEALTERCODE0 tags and use the ZEALTERCODE1 hook to place it correctly in the ZEALTERCODE2 section of your site.
  • Click “Update File.”
  • Option 2: Using a Custom Code Plugin (E.g., “Code Snippets” or “Header and Footer Scripts”)
  • These plugins provide a safe interface to add custom code snippets without directly editing theme files.
  • Install and activate a plugin like “Code Snippets” or “Insert Headers and Footers.”
  • For “Code Snippets”: Go to Snippets > Add New. Give your snippet a title (e.g., “GA4 Tracking Code”). Paste the entire ZEALTERCODE0 code (including the ZEALTERCODE1 comments) into the code area. Select “Run snippet everywhere” and “Only run on front-end.” Save and activate the snippet.
  • For “Insert Headers and Footers”: Go to Settings > Insert Headers and Footers. Paste the entire ZEALTERCODE0 code into the “Scripts in Header” box. Click “Save.”
  • Option 3: Directly Editing ZEALTERCODE0 (Not Recommended Without a Child Theme)
  • This is generally discouraged because theme updates will overwrite your changes. Only use this if you understand the risks or are certain your theme will not be updated.
  • From your WordPress admin, go to Appearance > Theme File Editor.
  • Select your active theme.
  • Open the ZEALTERCODE0 file.
  • Paste the entire ZEALTERCODE0 code snippet just after the opening ZEALTERCODE1 tag.
  • Click “Update File.”

Caution: Always back up your website before making direct code edits to theme files. Incorrect code can break your site. Using a child theme or a custom code plugin is safer.


Step 4: Verify Your GA4 Installation

After setting up the tracking code, it’s crucial to confirm that GA4 is correctly collecting data from your website.

  1. Use GA4 Realtime Report:
  • Go back to your Google Analytics 4 property in your browser.
  • In the left-hand navigation, click “Realtime” (under “Reports”).
  • Now, open your website in a new incognito or private browser window. Navigate to a few different pages on your site.
  • Within seconds, you should start seeing activity in the GA4 Realtime report (e.g., “Users in last 30 minutes,” “Views by Page title,” “Event count by Event name” like ZEALTERCODE0). This is the quickest way to confirm basic tracking.
  1. Use Google Tag Assistant (Chrome Extension):
  • Install the “Google Tag Assistant Companion” Chrome extension from the Chrome Web Store.
  • Once installed, navigate to your website.
  • Click on the Tag Assistant extension icon in your browser toolbar.
  • Click “Connect.” This will open a new window or tab displaying diagnostic information.
  • Go back to your website and browse a few pages.
  • Switch back to the Tag Assistant tab. You should see a “Google Analytics 4” tag firing with your Measurement ID (G-XXXXXXXXX). If you see it, your GA4 tag is firing correctly.

Troubleshooting Tip: If you don’t see any data in the Realtime report after a few minutes, double-check your Measurement ID, ensure the code is correctly placed, and clear any website caching plugins.


Step 5: Understanding Your Initial GA4 Data

Once your GA4 is collecting data, you’ll start to see information populate in your reports.

  • Data Latency: While the Realtime report is immediate, most other GA4 reports (like Engagement, Acquisition) have a processing delay. It can take up to 24-48 hours for data to fully appear in these standard reports. Don’t worry if they look empty immediately after setup.
  • Key Reports to Explore:
  • Reports snapshot: A quick overview of key metrics.
  • Realtime: As mentioned, for immediate user activity.
  • Acquisition > User acquisition: How users first found your site.
  • Acquisition > Traffic acquisition: How traffic arrived in specific sessions.
  • Engagement > Events: A list of all tracked events (page views, scrolls, clicks, etc.).
  • Engagement > Pages and screens: Which pages are being viewed most.

Note: GA4 is event-based. Almost everything is an “event.” A page view is an event, a click is an event, a scroll is an event. This is a fundamental difference from Universal Analytics’ session-based model.


Helpful Tips for WordPress Users

  • Child Themes for Manual Code: If you choose to manually add code, always use a child theme. This prevents your customizations from being overwritten when your parent theme receives updates.
  • GDPR/CCPA Compliance: Google Analytics collects user data. Ensure your website has a clear privacy policy and, if required by your region (e.g., EU, California), implements a cookie consent banner to inform users and obtain their consent for tracking. Many plugins are available for this.
  • Exclude Internal Traffic: To avoid skewing your data with your own visits (or those of your team), you can configure GA4 to filter out internal traffic. In GA4, go to Admin > Data Settings > Data Filters and create a filter based on IP addresses.
  • Link Google Search Console: If you used Site Kit, this is already done. If not, linking Search Console to GA4 (Admin > Product Links > Search Console Linking) provides valuable insights into how your site appears in search results and which queries drive traffic.
  • Regularly Review Data: Don’t just set it and forget it! Regularly check your GA4 reports to understand user behavior, identify popular content, find areas for improvement, and track the effectiveness of your marketing efforts.

By following these steps, you’ll successfully set up Google Analytics 4 on your WordPress website and begin collecting the valuable data needed to make informed decisions for your online presence. Happy analyzing!


Was this helpful?

Previous Article

How to Safely Redirect an Old URL to a New URL in WordPress Using the Redirection Plugin

Next Article

How to Dramatically Improve Your WordPress Site Speed by Optimizing Images with Smush

Write a Comment

Leave a Comment