How to Add Google Analytics in WordPress

Setting up Google Analytics is one of the first steps you should take after launching a WordPress site.

Publishing content without tracking visitor behavior leaves you in the dark. You will not know where your traffic comes from or why visitors leave your site.

How to add Google Analytics in WordPress


Google Analytics 4 (GA4) gives you free insights about your audience, popular pages, and conversion rates. Connecting GA4 to WordPress takes only a few minutes and requires no technical skills.

This guide shows you how to add Google Analytics in WordPress using three simple methods. Pick the approach that works best for your needs.


Why You Need Google Analytics in WordPress

Guessing what your readers like can lead to wasted effort. Installing Google Analytics turns every page view into useful facts.

Google Analytics gives you clear data on several key areas:

  • Audience Overview: Learn where your readers live, their languages, and what devices they use.
  • Top-Performing Pages: Find out which articles attract the most visitors so you can write more of them.
  • Traffic Sources: See if readers arrive from search engines, social media, or links on other sites.
  • Conversions: Track newsletter signups, downloads, button clicks, and online sales.

Tip: Google Analytics cannot collect data retroactively. It starts tracking only after you activate the snippet on your site. Setting it up early ensures your historical reports are ready when you need them.


Before You Start: Create Your GA4 Account

You need a Google account and an active Google Analytics 4 property before starting.

Create a Google Analytics 4 property


Google Analytics 4 uses the Google tag (gtag.js) to collect data from your website and send it directly to your Google Analytics property.

  1. Go to the Google Analytics website and sign in with your Google account.
  2. Click the setup button to begin.
  3. Enter an Account Name (like your business name) and click Next.
  4. Enter a Property Name (like "My WordPress Site"), pick your time zone, select your currency, and click Next.
  5. Select your business details and accept the terms of service.
  6. Choose Web when asked to set up a data stream.
  7. Type your website URL, name your stream, and click Create Stream.

Once created, note your Web Stream details:

  • Stream Name: Main Website
  • Website URL: https://yourdomain.com
  • Measurement ID: G-XXXXXXXXXX

Copy the Measurement ID on your stream details page. It starts with G-. Keep this tab open in case you need your code later.

Pro Tip: Consider linking your GA4 property to Google Search Console. Combining this data helps you see the exact keywords people search for before landing on your site.


Method 1: Google Site Kit (Recommended for Most Users)

Site Kit by Google is the easiest and most straightforward solution for most site owners.

It connects your site to GA4, Search Console, and PageSpeed Insights without editing HTML code. Site Kit shows key metrics inside WordPress, while full reports remain available on the main Google Analytics site.

Install Google Site Kit plugin in WordPress


  • Step 1: Install and activate the free "Site Kit by Google" plugin.
  • Step 2: Start setup and sign in with your Google account.
  • Step 3: Grant permissions and complete the verification steps.
  • Step 4: Select your GA4 property and finish the setup.

Step 1: Install and Activate Site Kit

  1. Log into your WordPress dashboard and go to Plugins.
  2. Search for Site Kit by Google.
  3. Install and activate the plugin.

Step 2: Authenticate Your Google Account

  1. Click the setup button on the banner at the top of your screen.
  2. Make sure Google Analytics is checked and sign in with Google.
  3. Select the Google account tied to your GA4 property.
  4. Grant the requested permissions.
  5. Follow the steps on screen to verify site ownership.

Step 3: Connect Analytics

  1. Site Kit will look for properties that match your domain.
  2. Confirm that your Account, Property, and Data Stream are correct.
  3. Confirm your selection to finish setting up Analytics.

Site Kit adds the Google tag to your pages automatically. You can view basic traffic stats anytime under Site Kit in your WordPress dashboard.


Method 2: Add Google Analytics Manually (Using WPCode or a Child Theme)

You can manually insert the Google tag if you want to avoid extra plugins.

This method places the GA4 tag directly into your site. The Google tag belongs in the <head> section of your site so it loads right away. (Note: Some site owners use Google Tag Manager instead, but a direct tag works great for standard sites).

Copy Google Analytics Measurement ID


First, grab your tracking code:

  1. Log in to Google Analytics.
  2. Click Admin and open Data Streams.
  3. Select your stream and locate the tag instructions.
  4. Choose the manual option and copy the entire gtag.js code.
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'G-XXXXXXXXXX');
</script>

Choose one of the options below to add this code:

Option A: Use the WPCode Snippet Plugin (Safest & Recommended Code Method)

Using a code manager like WPCode is the safest way to add code. It stops site errors and keeps your code intact even if you change your theme.

  1. Go to PluginsAdd New Plugin in WordPress.
  2. Search for WPCode, install it, and activate it.
  3. In your menu, go to Code SnippetsHeader & Footer.
  4. Paste your GA4 tag into the Header box.
  5. Click Save Changes.

Option B: Add Code via a Child Theme (For Advanced Customization)

Editing template files directly is meant for experienced users. You should only use a child theme if you need direct file customization.

Warning: Never edit a parent theme's header.php file directly. Theme updates will erase your changes and stop your tracking. Always use a child theme or WPCode.

  1. Access your files using AppearanceTheme File Editor, your host File Manager, or FTP.
  2. Open the header.php file inside your active Child Theme folder.
  3. Find the closing </head> tag near the top.
  4. Paste your Google tag code right above the </head> tag.
  5. Save your changes.

Note on File Editor Security: Many web hosts turn off the Theme File Editor for security. If you cannot see it, edit your child theme file using your hosting File Manager or FTP. You can also use WPCode to avoid this issue completely.


Method 3: Using MonsterInsights (Optional Dashboard Reporting)

MonsterInsights is a popular option if you want visual graphs inside your WordPress admin menu.

MonsterInsights sets up the Google tag automatically. It also offers extra options like sales and form tracking.

MonsterInsights setup wizard in WordPress


Step 1: Install MonsterInsights

  1. Go to PluginsAdd New Plugin.
  2. Search for MonsterInsights.
  3. Click Install Now, then click Activate.

Step 2: Run the Setup Wizard

  1. Launch the setup wizard.
  2. Choose your site type and continue.
  3. Click the button to connect your Google account.
  4. Log in, grant permissions, and select your GA4 property.
  5. Complete the setup wizard.

The plugin places the code on your site and begins sending traffic data to Google Analytics.


Comparing Your Options

Choosing a method depends on your experience level and how you want to view your stats:

Feature Method 1: Google Site Kit Method 2: Manual (WPCode / Child Theme) Method 3: MonsterInsights
Ideal User Beginners who want official Google tools Site owners who prefer manual control Marketers needing visual dashboard reports
Setup Process Guided account login Code copy & paste Guided setup wizard
WordPress Stats View Selected key metrics inside WordPress View on Google Analytics site Visual summary cards in dashboard
Site Performance Impact Minimal None to negligible Very low
Overall Cost Free Free Free core plugin (Paid upgrades optional)

How to Check That It Works

Always verify that your site sends data correctly after completing the setup.

Here are two quick ways to test your installation:

Google Analytics realtime report


1. Check the GA4 Realtime Report

  1. Open your website in an incognito browser window.
  2. Open your Google Analytics Dashboard in another tab.
  3. Go to ReportsRealtime in the left menu.
  4. You should see your visit show up in the report within a few moments. Active user counts will depend on your live traffic.

Realtime Verification: Shows active visitors and the pages they visit right now.

2. Inspect Your Website Source Code

  1. Visit your homepage in your browser.
  2. View your page source code (right-click and select View Page Source or press Ctrl + U / Cmd + Option + U).
  3. Press Ctrl + F and search for your G- Measurement ID or googletagmanager.com.
  4. If the code appears in the <head> section, your tag is installed correctly.

Important: Analytics plugins often exclude logged-in WordPress admins from tracking. Always test your site in an Incognito Window to verify live hits.


Common Setup Mistakes to Avoid

Avoid these simple mistakes to keep your tracking accurate:

  • Pasting Duplicate Tracking Scripts: Using Site Kit and pasting manual code at the same time loads the tag twice. This doubles your pageview counts and ruins your data. Pick one method and stick to it.
  • Editing Parent Theme Templates: Updating a parent theme deletes custom code inside header.php. Use WPCode or a child theme instead.
  • Ignoring Local Privacy Requirements: Privacy laws vary based on your location and your visitors' locations (such as GDPR or CCPA). Check which laws apply to your audience before using tracking cookies or consent banners.

Frequently Asked Questions

1. Which method should I choose?

It depends on what you prefer:

  • Google Site Kit is best for most beginners who want an official, free solution.
  • WPCode or a Child Theme is best for site owners who want custom control without extra analytics plugins.
  • MonsterInsights is a great optional pick if you want visual graphs directly inside WordPress.

2. Is Google Analytics free for WordPress sites?

Yes, Google Analytics 4 is 100% free. Official integration tools like Google Site Kit are also free to use.

3. How long does it take for traffic data to show up?

Realtime data appears in seconds. Standard reports can take 24–48 hours to update as Google processes your data.

4. Will adding Google Analytics slow down my website?

No. Google's tag uses asynchronous loading (async). The browser downloads the code quietly without slowing down your page.

5. What is a Measurement ID and where can I find it?

A Measurement ID is a unique code starting with G- that sends data to your property. You can find it under Data Streams in Google Analytics.

6. Why can't I see my own visits in my reports?

Plugins often ignore administrator visits so your stats stay accurate. Open an incognito window to test your site as a regular visitor.

7. Do I need to know how to code to set this up?

No. Automated options like Google Site Kit guide you through simple prompts without touching any code.


Summary

Adding Google Analytics to your site takes only a few minutes, but it makes a huge difference. Tracking data helps you make smart choices and grow your site with confidence.

For most users, Google Site Kit is the easiest route because it is free and sets up automatically. If you prefer a manual approach, using WPCode is the safest way to add your tracking code, though advanced users can use a Child Theme instead.

Once you finish, open an incognito window and check your Realtime report. When you see your visit register, your setup is complete!

Previous Post
No Comment
Add Comment
comment url