How to Add GA4 to WordPress: Site Kit, Manual, Tag Manager
This guide walks you through three ways to add Google Analytics 4 (GA4) to a WordPress site: using the official Site Kit plugin, adding the tracking code manually to your theme, or using Google Tag Manager. By the end, you’ll have GA4 tracking active, and you’ll know which method fits your comfort level and setup.
What You’ll Need
- A WordPress site with admin access (to install plugins and edit theme files).
- A Google account (for Analytics and, optionally, Tag Manager).
- FTP or file manager access if you choose the manual method.
- For Site Kit: the ability to install plugins from the WordPress repository.
Step-by-Step
Method 1: Using Google Site Kit (Recommended for Most Users)
- Install Site Kit: In your WordPress admin, go to Plugins > Add New, search for “Site Kit by Google”, install and activate it.
- Connect Google account: After activation, click the “Start Setup” button. You’ll be asked to connect your Google account and grant Site Kit permission to access your Analytics data.
- Choose GA4 property: Site Kit will detect existing GA4 properties or offer to create a new one. If you have an existing property, select it; otherwise, follow the prompts to create one. Site Kit automatically inserts the GA4 snippet.
- Verify tracking: Once connected, go to Site Kit > Analytics in your WordPress dashboard. You should see your property listed and a green “Connected” status. To confirm data is flowing, check the Realtime report in Google Analytics (see Troubleshooting).
Method 2: Manual Installation (Without a Plugin)
- Get your GA4 tag: In Google Analytics, go to Admin > Data Streams and click on your web data stream. Under “Web stream details”, copy the entire “Measurement ID” (e.g., G-XXXXXXXXXX) and the full global snippet (the
<script>block). - Add the code to your theme: In WordPress, go to Appearance > Theme Editor. Open
header.php. Paste the snippet right after the opening<body>tag, or inside the<head>section. If you’re using a child theme, edit the child’s header.php. - Save and verify: Click “Update File”. Then in Google Analytics, go to Realtime and open your site in a new tab. If you see yourself in the Realtime report, the code is working.
Method 3: Using Google Tag Manager
- Create a Tag Manager container: Go to tagmanager.google.com, sign in, and create a new container for your website. Copy the two snippets (one for
<head>, one for<body>). - Install the container snippet: Add the head snippet to
header.php(as above) and the body snippet right after the opening<body>tag. Alternatively, use a plugin like “Insert Headers and Footers” to avoid editing theme files. - Create a GA4 tag in Tag Manager: In Tag Manager, go to Tags > New. Choose “Google Analytics: GA4 Configuration”. Enter your Measurement ID (from GA4 data stream). Set the trigger to “All Pages”. Save the tag.
- Publish the container: Click “Submit” in Tag Manager, enter a version name, and publish. Your GA4 tag will now fire on all pages.
- Verify: Use Tag Manager’s Preview mode to see if the tag fires, then check GA4 Realtime.
Common Mistakes
- Using the wrong ID: Make sure you’re using the GA4 Measurement ID (starts with G-) and not the old Universal Analytics tracking ID (starts with UA-).
- Placing the snippet incorrectly: The GA4 snippet must be in the
<head>or right after the<body>. Putting it in the footer may cause missed events. - Adding the code twice: If you install Site Kit and also manually add the snippet, you’ll send duplicate hits. Choose one method.
- Forgetting to publish in Tag Manager: Tags don’t go live until you click “Submit” and publish the container version.
- Using a caching plugin without clearing cache: Cached pages may not show the new code, so clear your cache after adding the snippet.
Tips
- Use Site Kit if you’re not comfortable editing code: It handles the snippet and also offers other Google tools like Search Console.
- For manual method, use a child theme: If you edit a parent theme’s header.php, your changes will be lost when the theme updates.
- Consider Tag Manager if you plan to add more tags later: It lets you manage all tracking scripts from one place without editing theme files each time.
- Always test in an incognito window: This prevents your own visits from being affected by browser cache or extensions.
- Set up a GA4 property even if you still use Universal Analytics: GA4 is the future, and having data accumulate now helps you compare later.
Troubleshooting
- No data in Realtime: First, clear your browser cache and cookies. Then check that the snippet is present on the page (right-click > View Page Source, search for “gtag” or “G-“). If using Tag Manager, use Preview mode to see if the tag fires.
- Site Kit shows “not connected” or errors: Disconnect and reconnect your Google account. Make sure you’ve granted all necessary permissions. Also, check that your site is publicly accessible (not behind a login or maintenance page).
- Data appears but is missing pages: If you’re using a page builder or custom post types, ensure they’re included in the default tracking. Site Kit and the manual snippet track all pages by default.
- Tag Manager preview shows tag not firing: Check your trigger conditions. For “All Pages”, the trigger should be “Page View” with no filters. Also, make sure you’ve published the container.
- Getting a “page not found” for the analytics page: This usually means you’re using a non-standard login URL or a security plugin. Temporarily disable such plugins and try again.
Frequently Asked Questions
Do I need to add both the GA4 and Universal Analytics snippets?
No, GA4 is a separate property. If you want to keep tracking in Universal Analytics, you’d need both, but Google is phasing out UA. For new setups, just add the GA4 snippet.
Will Site Kit slow down my site?
Site Kit loads its scripts asynchronously and is generally lightweight. The GA4 snippet itself is minimal and shouldn’t noticeably affect performance.
Can I use Site Kit and Tag Manager together?
Yes, but you’d be sending double hits if both add the GA4 tag. If you want to use Tag Manager, skip Site Kit’s Analytics module or remove the GA4 tag from Site Kit.
What if I don’t have a GA4 property yet?
Site Kit can create one for you during setup. In manual or Tag Manager methods, you’ll need to create one in Google Analytics first (Admin > Create Property).
How do I know if my GA4 is working?
Open your site in a new tab, then go to Google Analytics > Realtime. If you see your session, it’s working. Remember to clear your cache and cookies if you don’t see it immediately.
Is it okay to paste the snippet in the footer?
It’s not recommended. The official instructions say to place it in the <head> or right after <body>. Placing it in the footer may cause some events to be missed if the page loads slowly.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.