The Guide to Adding Google Analytics to WordPress (The Easy Way)

Your complete guide to installing Google Analytics on WordPress. We explain what it is, why you need it, and show you three easy methods to get started today.

A hyper-realistic, professional photograph showing a person’s hands at a modern, clean wooden desk. On the left, a laptop displays the WordPress dashboard, clearly visible. On the right, a tablet shows the Google Analytics 'Realtime' report with a map of the UK and charts. A steaming mug of tea sits beside the laptop. The lighting is soft and natural, coming from a nearby window, creating a focused, productive, and slightly cosy mood. The style should be that of a high-end tech blog, with a shallow depth of field focusing on the screens.

This post may contain affiliate links. If you make a purchase through these links, we may earn a commission at no additional cost to you.

Ever wondered who’s visiting your website? Are they popping in from London or Liverpool? Did they find you on Google, or did a mate share your link on WhatsApp? Running a website without knowing this stuff is like trying to make a proper brew with the kettle off—it just doesn’t work.

That’s where Google Analytics comes in. Think of it as your website’s personal detective. It gathers clues about your visitors—how many there are, what pages they love, and what makes them click away. It’s a powerful tool, and it’s completely free. But for many WordPress users, setting it up feels a bit like trying to solve a Rubik’s Cube in the dark. It sounds complicated, technical, and frankly, a bit of a faff.

Don’t worry. This guide is here to switch the lights on. We’re going to walk you through everything, step-by-step, in plain English. We’ll show you exactly how to add Google Analytics to your WordPress site, whether you’re a complete beginner who’s never touched a line of code or you’re happy getting your hands a little dirty.

By the end of this guide, you’ll have Google Analytics up and running, and you’ll finally understand what’s actually happening on your website. So, stick the kettle on, grab a biscuit, and let’s get started.

What is Google Analytics and Why Do You Need It?

Before we dive into the ‘how’, let’s quickly cover the ‘what’ and the ‘why’.

Google Analytics is a free service from Google that tracks and reports website traffic. When someone visits your site, a small snippet of code sends anonymous information back to Google. It’s like a digital headcount, but much, much cleverer.

It doesn’t just count visitors. It tells you a story about them.

What Does Google Analytics Actually Tell You?

Imagine you run a small online shop selling handmade dog collars. Google Analytics can answer questions like:

  • Who are my visitors? It gives you an idea of their age, gender, and general interests. It can even tell you which city they’re browsing from, so you’ll know if you’ve got a fan club in Manchester or a following in Cornwall.
  • How did they find me? Did they type your shop’s name into Google? Did they click a link from your Facebook page? Or did another blog mention your brilliant collars? This is gold dust for knowing where to focus your marketing efforts.
  • What do they do on my site? You can see which pages are the most popular (are your Dalmatian-spot collars a surprise hit?), how long people stick around, and which page makes them leave. If everyone is abandoning their shopping basket at the checkout, you know you’ve got a problem to fix.
  • Are they using a phone or a computer? Knowing this helps you make sure your site looks great and works properly on all devices. If 80% of your visitors are on their mobiles, your site had better be easy to use on a small screen.

In short, Google Analytics turns guesswork into facts. Instead of thinking you know what your audience wants, you’ll know. It helps you make smarter decisions to grow your website, whether it’s a blog, a business, or a portfolio.

Before You Start: Creating a Google Analytics Account

First things first, you need a Google Analytics account. If you already have a Google account (like for Gmail or YouTube), you’re halfway there.

Let’s get this sorted. It’ll only take a few minutes.

Step 1: Head to the Google Analytics Website

Open your web browser and go to the Google Analytics homepage. Click on the “Start measuring” button. You’ll be prompted to sign in with your Google account.

Step 2: Create Your Account

Google will ask you for an Account name. This is just for your own reference, especially if you manage multiple websites. You can name it after your business, your website, or just call it “My Websites.” It’s up to you.

Underneath, you’ll see some data-sharing settings. These are ticked by default and allow Google to use your anonymous data to improve its services. You can untick them if you prefer, it won’t affect your tracking. Click “Next” when you’re ready.

Step 3: Create a Property

Now, you need to create a ‘Property’. A property is just your website or app. This is where the data will be collected.

  • Property name: Enter the name of your website (e.g., “My Awesome Blog”).
  • Reporting time zone: Select (GMT+01:00) United Kingdom Time. This makes sure your reports show data based on our time zone, which is handy.
  • Currency: Select British Pound (£).

Click “Next”. Google will then ask for a few more details about your business, like its industry and size. This is optional, but it helps Google give you tailored reports later on. Fill it out and click “Next”.

Step 4: Choose Your Business Objectives

Here, you can tell Google what you want to achieve with your website. Are you trying to sell products, generate leads, or just get people to read your articles? Pick the options that best fit your goals. This helps Google Analytics set up your dashboard with the most useful reports for you.

When you’re done, click “Create” and accept the Google Analytics Terms of Service.

Step 5: Set Up Your Data Stream

You’re almost there! The final setup step is to create a ‘Data Stream’. This is the source of your data. Since you have a website, you’ll choose “Web”.

You’ll be asked for two things:

  1. Your website’s URL: Type in your website address (e.g., www.myawesomeblog.co.uk).
  2. Stream name: This is usually just the name of your website again.

Make sure ‘Enhanced measurement’ is turned on. This automatically tracks things like clicks on links, file downloads, and video views without any extra setup. It’s very useful.

Click “Create stream”.

Step 6: Find Your Measurement ID

Success! You’ve created your account, property, and data stream.

Google will now show you a page with your stream details. At the top right, you’ll see a Measurement ID. It will look something like this: G-XXXXXXXXXX.

This ID is crucial. It’s the unique identifier for your website’s data stream. Copy it and keep it safe. We’ll need it in a moment.

Right, that’s the admin out of the way. Your Google Analytics account is ready and waiting to receive data. Now, we just need to connect it to your WordPress site.

How to Add Google Analytics to WordPress: The 3 Best Methods

There are a few ways to connect Google Analytics to WordPress. We’re going to focus on the three most common and reliable methods. We’ll start with the easiest and work our way to the more hands-on approach.

  1. Method 1: Using a Plugin (The Easiest Way for Beginners)
  2. Method 2: Using Google Tag Manager (The Most Flexible Way)
  3. Method 3: Adding the Code Manually (For Confident Users)

Read through them and pick the one that feels right for you. For most people, a plugin is the perfect choice.

Method 1: Using a Plugin (The Easiest Way)

If you’re not comfortable with code, this is the method for you. A plugin does all the heavy lifting. You simply install it, connect it to your Google account, and you’re done. It’s quick, easy, and you won’t risk breaking your site.

There are lots of Google Analytics plugins out there, but one of the most popular and straightforward is Site Kit by Google. It’s Google’s official WordPress plugin, so you know it’s reliable. It also lets you see your stats right inside your WordPress dashboard.

Let’s get it installed.

Step 1: Install the Site Kit Plugin

  1. Log in to your WordPress dashboard.
  2. On the left-hand menu, go to Plugins > Add New.
  3. In the search bar at the top right, type “Site Kit by Google”.
  4. The plugin should be the first result. Click “Install Now” and then “Activate”.

Step 2: Connect Site Kit to Your Google Account

Once activated, you’ll see a banner at the top of your WordPress dashboard. Click the “Start Setup” button.

  1. Sign in with Google: Site Kit will ask you to sign in with the same Google account you used to create your Analytics property. Click the button and follow the prompts.
  2. Grant Permissions: Google will ask for permission to manage your site and access your data. This is perfectly safe—it’s just allowing the plugin to connect everything. Tick the boxes and click “Continue”.
  3. Verify Site Ownership: Site Kit will automatically verify that you own the website. This is a security step. Just click “Next”.
  4. Allow Access to Google Account Data: It will ask for permission to show your stats in WordPress. Click “Next”.
  5. Set up Search Console: Site Kit will also set up Google Search Console for you. This is another brilliant free tool that tells you how your site is performing in Google search results. Click “Next”.
  6. Set up Google Analytics: Finally, it will find the Google Analytics account you created earlier. Make sure the correct Account and Property are selected from the dropdown menus. It should find them automatically. Click “Configure Analytics”.

And that’s it! You’re all done.

Site Kit will now automatically add the necessary tracking code to every page on your website. You didn’t have to touch a single line of code.

What’s Next?

Data won’t appear instantly. It can take 24 to 48 hours for Google Analytics to start showing information. Be patient!

Once it’s working, you can see a snapshot of your traffic directly in your WordPress dashboard by clicking on the Site Kit menu item. You’ll see your most popular pages, how people found you, and more. For the full, detailed reports, you’ll still need to log in to the main Google Analytics website.

Method 2: Using Google Tag Manager (The Flexible, Future-Proof Way)

This method is a bit more advanced, but it’s incredibly powerful. Think of Google Tag Manager (GTM) as a toolbox for all your website tracking codes (or ‘tags’).

Instead of adding lots of different code snippets to your site (one for Analytics, one for Facebook Pixel, one for another marketing tool), you just add one—the Google Tag Manager code. Then, you manage all your other tags from inside the GTM dashboard.

Why is this a good idea?

  • It keeps your site tidy: You only add one piece of code to your site. This can help keep your website loading quickly.
  • It’s flexible: Adding new tracking tags is easy. You do it in GTM, not on your website. You won’t need to bother your web developer every time you want to add something new.
  • It’s powerful: You can set up advanced tracking, like monitoring how many people click a specific button or watch a video, without writing extra code.

It takes a little longer to set up, but it’s well worth it if you think you’ll want to add other tracking tools in the future.

Step 1: Create a Google Tag Manager Account

  1. Go to the Google Tag Manager website and sign in with your Google account.
  2. Click “Create Account”.
  3. Account Name: Give your account a name (e.g., your business name).
  4. Country: Select United Kingdom.
  5. Container Name: Enter your website’s URL (e.g., www.myawesomeblog.co.uk).
  6. Target Platform: Choose “Web”.
  7. Click “Create” and accept the terms of service.

Step 2: Get Your GTM Code Snippets

Once your container is created, a pop-up window will appear with two snippets of code. These are the codes you need to add to your WordPress site. Don’t close this window just yet!

Step 3: Add the GTM Code to WordPress

You need to place these two code snippets in the <head> and <body> sections of your website’s HTML. The easiest way to do this without editing theme files directly is with a simple plugin.

  1. In your WordPress dashboard, go to Plugins > Add New.
  2. Search for “WPCode – Insert Headers and Footers”. It’s a very popular and reliable plugin.
  3. Install and activate the plugin.
  4. From your WordPress menu, go to Code Snippets > Header & Footer.
  5. You’ll see two boxes: ‘Header’ and ‘Body’.
  6. Go back to the Google Tag Manager window. Copy the first code snippet (the one for the <head>).
  7. Paste it into the ‘Header’ box in the plugin’s settings.
  8. Now, copy the second code snippet (for the <body>).
  9. Paste it into the ‘Body’ box.
  10. Click “Save Changes”.

Great! Google Tag Manager is now installed on your site. But we haven’t added Google Analytics yet. We need to do that inside Tag Manager.

Step 4: Add Google Analytics to Google Tag Manager

  1. Go back to your Google Tag Manager dashboard.
  2. Click on “Tags” in the left-hand menu, then “New”.
  3. Give your tag a name, something like “GA4 – Page View”.
  4. Click on the “Tag Configuration” box.
  5. Choose “Google Analytics: GA4 Configuration” from the list.
  6. Now, it will ask for your Measurement ID. This is the G-XXXXXXXXXX ID you copied when you set up Google Analytics. Paste it into the box.
  7. Next, click on the “Triggering” box below. A trigger tells the tag when to fire.
  8. Choose “All Pages”. This tells GTM to fire the Google Analytics tag on every page of your site.
  9. Click “Save”.

Step 5: Publish Your Changes

You’ve created the tag, but it’s not live yet. You need to publish your container.

  1. In the top right corner of your GTM dashboard, click the blue “Submit” button.
  2. You’ll be asked to give this version a name. You can just write “Initial Setup” or “Added GA4”.
  3. Click “Publish”.

That’s it! You’ve successfully added Google Analytics using Google Tag Manager. Just like with the plugin method, it might take 24-48 hours for data to start showing up.

Method 3: Adding the Code Manually to Your Theme

This method involves directly adding the Google Analytics tracking code (also called the gtag.js snippet) to your WordPress theme’s files.

A word of warning: This is for more confident users. If you make a mistake, you could break your website. It’s also important to use a Child Theme.

Why Use a Child Theme?

When your theme’s developer releases an update, any changes you’ve made directly to the theme’s files will be wiped out. A child theme is a separate theme that inherits all the styling and functionality of the main theme (the ‘parent’ theme). You make your edits in the child theme, so when the parent theme updates, your changes are safe.

If you don’t have a child theme, we strongly recommend using Method 1 or 2 instead.

If you’re comfortable with this, let’s proceed.

Step 1: Get Your Google Analytics Tracking Code (gtag.js)

  1. Log in to your Google Analytics account.
  2. At the bottom left, click on the Admin cogwheel.
  3. In the ‘Property’ column, click on Data Streams and select your web stream.
  4. Under ‘Web stream details’, scroll down and click on “View tag instructions”.
  5. A new tab will open. Click on “Install manually”.
  6. You’ll see a snippet of JavaScript code. This is your gtag.js snippet. Click the copy icon to copy it to your clipboard.

Step 2: Add the Code to Your Child Theme’s header.php File

This code needs to be placed in the <head> section of every page on your site. In WordPress themes, this is usually controlled by a file called header.php.

  1. In your WordPress dashboard, go to Appearance > Theme File Editor.
  2. On the right, under ‘Theme Files’, make sure you have your child theme selected.
  3. Find and click on the header.php file to open it.
  4. Look for the <head> tag near the top of the file.
  5. Paste your copied gtag.js snippet just before the closing </head> tag.
  6. Click “Update File”.

That’s it. The code is now on your site.

An Alternative (and Safer) Manual Method: functions.php

Editing header.php works, but a slightly cleaner way is to use your child theme’s functions.php file. This method is less likely to cause issues if your theme has a complex header.php file.

  1. In the Theme File Editor, open your child theme’s functions.php file.
  2. Copy and paste the following code at the very end of the file.
function add_google_analytics_code() {
    ?>
    <!-- Paste your gtag.js code from Google Analytics here -->

    <script async src="[https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX](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_code');
  1. Very important: Replace the placeholder gtag.js code in the middle with the actual code you copied from your Google Analytics account. Make sure you replace both instances of G-XXXXXXXXXX with your real Measurement ID.
  2. Click “Update File”.

This code tells WordPress to hook into the wp_head action (which runs in the <head> section) and insert your Analytics script. It achieves the same result as editing header.php but keeps your custom code neatly contained in one function.

How to Check if Google Analytics is Working

So, you’ve installed the code. How do you know it’s actually working? Don’t just wait 24 hours and hope for the best. Here’s how to check right now.

The best way is to use the Realtime report in Google Analytics.

  1. Log in to your Google Analytics account.
  2. On the left-hand menu, go to Reports > Realtime.
  3. This report shows you visitors who are on your site right now.
  4. Now, in a new browser tab or on your phone, open your website. Visit a few different pages.
  5. Switch back to the Realtime report. After a few seconds, you should see at least one visitor pop up on the map and in the charts. You might see your location appear (e.g., London).

If you see activity, congratulations! It’s working perfectly.

If you don’t see anything after a minute or two, don’t panic. Here are a few things to check:

  • Caching Plugins: If you use a caching plugin (like W3 Total Cache or WP Rocket), clear your website’s cache. Your browser might be showing you an old, cached version of your site without the new tracking code.
  • Ad Blockers: Some browser ad blockers also block Google Analytics. Try visiting your site in an incognito/private window or from a different browser where you don’t have these extensions running.
  • Double-check your ID/Code: Go back and make sure you copied and pasted the Measurement ID or the full code snippet correctly. A single typo can stop it from working.

What Next? Making Sense of the Data

Getting Google Analytics installed is a huge first step. But the real magic happens when you start using the data to improve your website.

When you log in to Google Analytics, you’ll see a lot of reports. It can feel overwhelming at first. Here are three key reports to start with.

1. The Traffic Acquisition Report

  • Where to find it: Reports > Acquisition > Traffic acquisition
  • What it tells you: This is the ‘how did they find me?’ report. It breaks down your traffic into channels like ‘Organic Search’ (from Google), ‘Direct’ (typed your address), ‘Referral’ (clicked a link from another site), and ‘Organic Social’ (from Facebook, Twitter, etc.).
  • Why it’s useful: If you see that lots of traffic is coming from Google, it tells you your SEO (Search Engine Optimisation) efforts are paying off. If another blog sends you hundreds of visitors, you know that collaborating with them was a good idea.

2. The Pages and Screens Report

  • Where to find it: Reports > Engagement > Pages and screens
  • What it tells you: This report lists your most popular pages, ordered by the number of views.
  • Why it’s useful: It shows you what content your audience loves. If a particular blog post is getting thousands of views, you should probably write more articles on that topic. You can also spot pages that aren’t getting any attention and decide whether to improve them or remove them.

3. The Demographics Report

  • Where to find it: Reports > User > User attributes > Demographics details
  • What it tells you: This gives you an overview of your visitors’ age, gender, city, and country.
  • Why it’s useful: Understanding your audience helps you create content and products that they’ll actually be interested in. If you discover that your audience is much younger than you thought, you might want to adjust your writing style or your marketing on social media.

Conclusion: You’re Ready to Go

You’ve done it. You’ve successfully installed Google Analytics on your WordPress website. You’ve moved from flying blind to having a full control panel, giving you the insights you need to make your website better, day by day.

Whether you chose the simple plugin method, the flexible Google Tag Manager approach, or the manual code-in-theme route, the result is the same: you now have a powerful tool working for you in the background, collecting valuable data.

Remember, the key is not just to have the data, but to use it. Set aside a little time each month to pop into your Analytics account. Look at your popular pages, see where your visitors are coming from, and get to know who they are.

Your website is no longer a mystery. It’s a story, and now you have the tools to read it.

Further Reading

For those who wish to delve deeper, these resources are highly recommended:

  • Google Analytics Help Center: The official source for all things Analytics. Visit Help Center
  • Google Skillshop: Free courses from Google to become an Analytics pro. Visit Skillshop
  • The Moz Blog: A respected authority on SEO and analytics. Visit Moz Blog

Want More Like This? Try These Next: