Skip to main content
Cloud Hosting starting at $2.91/mo. Auto-scaling servers with a FREE domain included.Start Now →
Tutorials

How to Add Google Analytics to WordPress (The Right Way in 2026)

Track your website visitors, understand their behavior, and make data-driven decisions. This tutorial covers three methods for adding Google Analytics 4 to WordPress — from beginner-friendly plugins to manual code installation.

S

Serverlys Team

May 30, 2026 · 5 min read

You cannot improve what you do not measure. Google Analytics tells you exactly who is visiting your website, where they come from, which pages they view, how long they stay, and whether they take the actions you care about (purchases, form submissions, phone calls). Without analytics, you are making decisions based on gut feelings instead of data.

Google Analytics 4 (GA4) is the current version and the only one Google supports as of 2026. If you are still running the old Universal Analytics, it stopped processing data in July 2023. This tutorial covers setting up GA4 from scratch on a WordPress website.

Step 1: Create a Google Analytics Account

  1. Go to analytics.google.com and sign in with your Google account.
  2. Click Start measuring.
  3. Enter an Account name (your business name).
  4. Click Next and enter a Property name (your website name).
  5. Set your reporting time zone and currency.
  6. Click Next, select your business category and business size.
  7. Select your business objectives (generate leads, drive sales, raise brand awareness, etc.).
  8. Click Create and accept the terms of service.

Step 2: Set Up a Web Data Stream

  1. After creating the property, you will be prompted to choose a platform. Select Web.
  2. Enter your website URL (e.g., https://yourdomain.com).
  3. Enter a Stream name (e.g., "Main Website").
  4. Click Create stream.
  5. You will see your Measurement ID (starts with G-). Copy this — you will need it for the next step.

Important: Your Measurement ID looks like G-XXXXXXXXXX. This is different from the old Universal Analytics tracking IDs that started with UA-. Make sure you are using the GA4 Measurement ID, not an old UA code.

Method 1: Google Site Kit Plugin (Recommended)

Site Kit is Google's official WordPress plugin. It connects Analytics, Search Console, AdSense, and PageSpeed Insights directly to your WordPress dashboard.

  1. Go to Plugins → Add New and search for Site Kit by Google.
  2. Install and activate the plugin.
  3. Click Start Setup in the Site Kit welcome banner.
  4. Sign in with the same Google account you used to create your Analytics property.
  5. Grant the required permissions when prompted.
  6. Site Kit will automatically detect your GA4 property and connect it. If it does not, click Connect Service under the Analytics section.
  7. The tracking code is now automatically added to every page of your site.

After connecting, Site Kit displays key metrics directly in your WordPress dashboard: sessions, page views, average engagement time, and top pages. You can still access the full Google Analytics interface at analytics.google.com for detailed reports.

Method 2: Manual Code Installation

If you prefer not to install a plugin, you can add the GA4 tracking code directly to your theme. This method gives you full control and adds zero plugin overhead.

Get Your Tracking Code

  1. In Google Analytics, go to Admin → Data Streams.
  2. Click on your web stream.
  3. Under "Google tag," click View tag instructions.
  4. Select Install manually.
  5. Copy the entire code snippet. It looks like this:
<!-- Google tag (gtag.js) -->
<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>

Add the Code to WordPress

The safest way to add custom code to WordPress is through your theme's functions.php file or a custom plugin. Here is the functions.php method:

  1. Go to Appearance → Theme File Editor.
  2. Select functions.php from the file list on the right.
  3. Add this code at the end of the file:
function add_google_analytics() { ?>
<!-- Google tag (gtag.js) -->
<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>
<?php }
add_action('wp_head', 'add_google_analytics');

Replace G-XXXXXXXXXX with your actual Measurement ID.

"If you use a child theme, add the code to the child theme's functions.php. If you add it to the parent theme, your changes will be overwritten when the theme updates."

Method 3: Google Tag Manager

Google Tag Manager (GTM) is a tag management system that lets you add and manage tracking codes without editing your website's code directly. It is the most flexible option and is recommended if you plan to add multiple tracking tools (Facebook Pixel, LinkedIn Insight, etc.) in the future.

  1. Go to tagmanager.google.com and create an account.
  2. Create a container for your website (select "Web").
  3. Install the GTM code snippet on your WordPress site (using the same methods as above, or the "Insert Headers and Footers" plugin).
  4. Inside GTM, click Tags → New.
  5. Select Google Analytics: GA4 Configuration as the tag type.
  6. Enter your Measurement ID.
  7. Set the trigger to All Pages.
  8. Click Save, then click Submit to publish the container.

Step 3: Verify Your Installation

After adding the tracking code, verify it is working:

  1. Real-time report: Go to Google Analytics → Reports → Realtime. Open your website in another browser tab. You should see yourself as an active user within 30 seconds.
  2. Google Tag Assistant: Install the Google Tag Assistant Chrome extension. Visit your website and it will confirm whether your GA4 tag is firing correctly.
  3. DebugView: In Google Analytics, go to Admin → DebugView. Enable debug mode in your browser and you will see events in real time as you navigate your site.

Step 4: Set Up Key Events (Conversions)

GA4 automatically tracks certain events (page views, scrolls, outbound clicks, site searches, file downloads). But you should also set up custom events for actions that matter to your business:

Marking Events as Conversions

  1. In Google Analytics, go to Admin → Events.
  2. Find the event you want to mark as a conversion (e.g., form_submit).
  3. Toggle the Mark as key event switch to on.

Step 5: Connect Google Search Console

Linking Search Console to Analytics gives you search query data inside your Analytics reports. You can see which Google searches bring visitors to your site and which pages appear in search results.

  1. In Google Analytics, go to Admin → Product Links → Search Console Links.
  2. Click Link.
  3. Select your Search Console property and the GA4 web stream.
  4. Click Submit.

If you have not set up Search Console yet, go to search.google.com/search-console, add your website, and verify ownership (the easiest method is the HTML tag verification if you already have GA4 installed).

Serverlys Tip: Fast-loading websites get more engagement and better analytics data. Slow sites cause visitors to bounce before the tracking code even fires, which underreports your actual traffic. Serverlys cloud hosting delivers fast load times that keep visitors on your site and your data accurate.

Understanding Your GA4 Dashboard

GA4 organizes data differently than the old Universal Analytics. Here is where to find the reports that matter most:

What You Want to Know Where to Find It
How many people visit your siteReports → Acquisition → Overview
Where visitors come fromReports → Acquisition → Traffic Acquisition
Which pages are most popularReports → Engagement → Pages and Screens
How long visitors stayReports → Engagement → Overview
What devices visitors useReports → Tech → Tech Details
Where visitors are locatedReports → Demographics → Overview
Conversion trackingReports → Engagement → Conversions

Frequently Asked Questions

Is Google Analytics free?

Yes. Google Analytics 4 is completely free for all websites. Google also offers Analytics 360 for enterprise users ($150,000+/year), but the free version handles everything small and medium businesses need.

Does Google Analytics slow down my website?

The GA4 tracking script is lightweight (around 28KB) and loads asynchronously, meaning it does not block your page from rendering. The performance impact is negligible — typically less than 50ms of additional load time.

How long does it take for data to appear?

Real-time data appears within 30 seconds. Standard reports can take 24–48 hours to process new data. If you do not see data after 48 hours, verify your tracking code installation.

Should I use a plugin or manual installation?

For most WordPress users, Google Site Kit is the best option. It is the official plugin, handles installation automatically, and displays key metrics in your dashboard. Manual installation is better if you want to minimize plugins or need custom event tracking.

Can I track multiple websites with one Analytics account?

Yes. Each website gets its own "property" within your Analytics account. You can create up to 2,000 properties per account. Each property has its own Measurement ID and data stream.

Related Tutorials

Fast hosting means better analytics data

Slow websites lose visitors before the tracking code fires. Serverlys cloud hosting delivers fast load times so your analytics capture every visit.