
If you have a WordPress website, it’s important to understand how people use it. This is where Google Analytics (GA4) comes in. This tool helps you track what visitors do on your site.
With GA4, the latest version of Google Analytics, you get even better insights into your visitors’ behavior and interests. It provides real-time data and powerful reports, to see how people find your website, what pages they visit, how long they stay, and much more.
Tracking your website’s data with GA4 is essential for making smart decisions. By knowing what’s working and what’s not, you can improve your content, optimize the user experience, and grow your site’s audience.
For example, if you notice most visitors are on social media, you might focus more on that platform. Or, if a page has a high exit rate (bounce rate), you could improve its content to keep people engaged.
In this tutorial, we walk you through every step to add Google Analytics to WordPress website. We’ll cover different methods—adding GA4 manually, using a plugin, or setting it up with Google Tag Manager—so you can choose the best option for your needs. By the end, you’ll have GA4 ready to track all the important data for your website.
KEY TAKEAWAYS
- Google Analytics WordPress integration helps you track visitor behavior and improve your website.
- GA4 is the latest version of Google Analytics with enhanced tracking features.
- You need a Google Analytics account and a GA4 property to get started.
- You can add Google Analytics to WordPress using a plugin, manual code, CAOS, or Google Tag Manager.
- Plugins like Site Kit by Google and MonsterInsights make setup easy for beginners.
- Add the tracking code in the header.php or functions.php file for manual set up.
- Google Tag Manager offers a flexible way to manage and add tracking tags.
- Verify your setup by checking real-time data in Google Analytics.
- Tracking data helps you make data-driven decisions to improve user experience.
TABLE OF CONTENTS
Significance of Setting up Google Analytics
Adding Google Analytics to WordPress is one of the smartest moves to make. Google Analytics (GA4) shows you exactly how people use your site. Moreover, you’ll get valuable information about your visitors, such as where they come from, which pages they like most, and how long they stay on each page. This helps you understand your audience better so you can create content they’ll enjoy.
GA4 also offers insights into important areas, like user behavior and demographics. User behavior shows what people do on your site, such as which pages they visit first, and where they go next.
Demographic data tells you details about your target audience, such as their age, country, and interests. Another big feature is traffic sources—this lets you see how visitors access your site, whether through Google search, social media platforms, or other websites. Understanding these details can make a big difference in your strategy.
This information lets you make data-driven decisions to improve your website. For example, if you notice that a certain blog post gets a lot of traffic, you might create more content on similar topics.
Or, if you see that most visitors don’t stay long, you might work on making your homepage more engaging. By using GA4, you can adjust and optimize your site for a better user experience and higher performance. This means more happy visitors and a site that works better for everyone.
Prerequisites
Before we continue to add Google Analytics to WordPress, there’s one important thing you need: a Google Analytics account. If you haven’t set one up yet, don’t worry! It’s quick and simple. Let’s walk through the steps to create your account and, if needed, upgrade to GA4.
Create a Google Analytics Account
To start with Google Analytics, head over to the Google Analytics website and sign in with your Google account. If you don’t have a Google account, you must create one first. Once you’re signed in, click Start measuring to set up your Google Analytics account.

On the next screen, enter your account name. It’s not the name of your website; it’s like the umbrella where all your different kinds of websites – if you have those – can be placed. This name helps you keep track of all the websites you monitor.

Under Account Data Sharing Settings, select the options you prefer. For example, you may wish to enable Technical support to get help from Google if necessary. If you don’t know what to do here, keep the default settings and click Next to continue.

Google Analytics will now ask you to set up a Property. This refers to the website you want to track. Enter your website’s name. Then, change your reporting time zone.
This is important, to find out when your visitors are converting the most so you can adjust your marketing efforts towards those PRIME TIMES. If your target audience is all around the globe, use your time zone.
After that, change the currency as per your choice and click Next to move to the next section.

Now, Google asks for basic information about your business, such as the industry category and the size of your company. Choose the Industry Category that best fits your website. This step is helpful if you want more customized data. Click Next to continue.

Here, you need to choose your business objective. You might be wondering why you need this. It’s because Google Analytics will make some reports you can click and open to see all these metrics. For example, if you’re not selling anything but wish to generate leads, click Generate leads.
However, if you don’t know what to do with your website, click Other then press Create.

Now, you need to accept the terms of the service agreement. For this, do the following:
- Choose your country.
- Select the option: “I also accept the Data Processing Terms as required by GDPR. Learn more”.
- Click I Accept.

Before collecting data, you need to add code to your website. To do this, choose the Web platform.

Fill in your Website URL, such as mywebsite.com, and ensure you use www if you have it. Choose your protocol (http:// or https://). For Stream name, we suggest you use your brand or website name, GA4, and then the year you created the stream. You can always check when you’ve created the stream. For example, our website is “My Blog”, so the Stream name will be “My Blog GA4 2024”.
Keep the Enhanced measurement option turned on, and if you’re wondering what kind of data you’re collecting, click the gear icon to see it all. Then, click Create and continue.

After setting up your property, you’ll see the installation instructions for connecting Google Analytics to WordPress. You’ll need this code to add Google Analytics to WordPress, so keep this tab open or copy the code to use later.

Important: If you’ve been using the older version of Google Analytics, called “Universal Analytics”, it’s a good idea to switch to GA4, which provides more detailed tracking and future support.
How to Add Google Analytics to WordPress
Now that you have a Google Analytics account, it’s time to add it to your WordPress website. There are a few ways to add Google Analytics to WordPress, and you can choose the one that works best for you.
For most people, using a WordPress plugin is the easiest and quickest way to get started. We recommend using a plugin for beginners since it doesn’t require coding. It also makes it easier to manage settings directly from your WordPress dashboard.
On the other hand, manual code insertion may be a good choice if you prefer to keep your site light on plugins or have specific customization needs. However, if you want to manage multiple websites, Google Tag Manager (GTM) provides a single platform for all your tags, including Google Analytics.
You can manage and update tags across different sites from one GTM account, which is efficient for web admins managing multiple sites. And if you’re more concerned about your website’s speed and performance, you can use Complete Analytics Optimization Suite (CAOS).
Method 1: Use a Plugin
Beginners find adding Google Analytics to WordPress with a plugin the simplest choice. Several popular plugins make it easy to set up tracking without touching any code. Two top choices are Site Kit by Google and MonsterInsights. In this tutorial example, we use Site Kit. Here’s how you can also use it:
Go to your WordPress dashboard, and from the left menu, click Plugins → Add New Plugin. In the search bar, type in the name of the plugin you want to use, such as “Site Kit by Google”. Once you find it, click Install Now.

Then click Activate.

Once the plugin is activated, you’ll see a new Site Kit option appear in the left-side menu of your dashboard; click on this. Then, check Connect Google Analytics as part of your setup option and click Sign in with Google.

Click Continue to allow Google to share your name, email address, language preferences, and profile picture with Site Kit.

The plugin will ask for permission to access your Google Analytics account. Click Select All and then Continue.

After that, click Verify for Google to verify site ownership.

Click Allow to turn on metrics in your dashboard. Doing this will let your website access your Google account data.

Click Set up to see how people find your website on Google Search, and have Google add [your website name] to Search Console for you and connect it to Site Kit.

After that, click Next to set up Google Analytics to understand how your audience finds and uses your website.

You will now be navigated back to your WordPress admin dashboard. Select your Account and Property. The Web Data Stream will automatically be populated once you choose your Property. Ensure all details are correct, then click Complete setup.

After connecting, the plugin will confirm that Google Analytics is successfully tracking your website. You can check the plugin’s dashboard or your GA4 account to see if data is being recorded. If your website is new, you might see “gathering data” instead of statistics. However, after 24 hours you’ll see some statistical numbers.

To integrate GA4 for valuable insights on your WordPress site hosted on Hosted.com, you can leverage its advanced analytics capabilities that track user interactions and behaviors across platforms.
Additionally, our expert support team is available to assist you throughout the integration process, ensuring you maximize the benefits of this powerful tool.
Method 2: Add Tracking Code Manually
If you’d rather not use a plugin to add Google Analytics to WordPress, you can add the tracking code manually. This option is great if you prefer to keep your site lightweight by minimizing plugins.
However, this method requires editing your site’s code, so you must be careful when making changes to avoid errors. Let’s see how you can grab your tracking code from your Google Analytics account and add it to your website:
Log into your Google Analytics account. If you have multiple properties, click on the dropdown menu and select the one for which you want to get the Google tag (tracking code).

In the left menu, click Admin. Then, navigate to Data collection and modification → Data Streams.

Select your website’s data stream.

On the Web Stream Details page, scroll down to Google tag and click on View tag instructions to retrieve your Google tag code.

Switch to Install Manually and click Copy to copy your Google tag.

Now, to insert this code, log into your WordPress dashboard and head over to Appearance → Theme File Editor. Open the header.php file and paste your Google tag code at the end of this file. Then, click Update File.

Alternatively, you can also add this tracking code to your theme’s functions.php file (located at Appearance → Theme File Editor) as follows:
function add_google_analytics_code() {
?>
<!-- Paste your Google Analytics tracking code here -->
<?php
}
add_action('wp_head', 'add_google_analytics_code');
Don’t forget to paste your actual Google Analytics tracking code. Then save the file, and WordPress will include the tracking code in the <head> section of all the pages.
Important: When making changes to your site’s code, it’s essential to be careful. Even small mistakes, like missing a character, can cause errors on your site. Before saving, double-check your changes. If possible, create a backup of your theme files so you can quickly restore them if something goes wrong.
The above solutions (editing header.php and functions.php files) work if you use a classic WordPress theme, such as Astra. However, for block themes, which use the Full Site Editing (FSE) feature, you won’t typically edit the header.php file directly, as block themes organize templates and template parts differently.
In this case, you can add Google Analytics to WordPress in two ways:
First, you can add the tracking code to the functions.php file, as we showed you earlier. To access this file, use an FTP client or your web host’s File Manager feature. To make it easy for you, we’ve covered how to use both in separate guides that you can find below:
How to Configure a Site Using FTP Client (FileZilla)
How to Use Hosted.com’s File Manager Feature
Important: The functions.php file lives in the public_html/wp-content/themes/your-active-theme/ directory.
The second approach to add Google Analytics to WordPress block theme is to install and activate a WPCode plugin from your WordPress dashboard. Next, go to Code Snippets → Header & Footer. Write your Google Analytics tracking code into the Header section and click Save Changes. The plugin will add the tracking code in the <head> section across all web pages.

Method 3: Use Google Tag Manager
Another way to add Google Analytics to WordPress is to use Google Tag Manager (GTM). It has several advantages, as it allows you to add and manage tracking codes, like Google Analytics, without editing the website’s code. This makes it simpler and less risky, especially for non-technical users.
With GTM, you can set up advanced tracking, like event tracking for button clicks, form submissions, or scroll depth, which isn’t easy with standard Google Analytics. All tracking tags are managed in one place, so you don’t have to keep adding or removing tags directly in the WordPress code.
Additionally, you can update or add new tags from GTM without touching your site’s files. It’s also useful when working on multiple sites.
Here’s how to use Google Tag Manager to add Google Analytics to WordPress:
Go to Google Tag Manager and sign in with your Google account. Click Accounts, then Create Account.

Enter your Account Name (usually your business name). Select your country. You may also check Share data anonymously with Google and others. For this tutorial, we didn’t check this option.

In the Container name box, specify your domain name (like www.yourdomain.com) and select Web as the target platform. Then, click Create.

A new window will appear; review the terms and click Yes to agree. You may also accept the data processing terms as required by GDPR.

After setting up your container, GTM will give you two code snippets. Copy both snippets.

In your WordPress dashboard, install and activate the WPCode plugin. Then, go to Code Snippets → Header & Footer. Paste the first code snippet into the Header section, and the second code snippet into the Body section, then click Save Changes. Now, GTM is active on your WordPress site.

Next, in your Google Tag Manager dashboard, go to Tags and click New.

Name your tag something recognizable, like Google Analytics – GA4. Click Tag Configuration and select Tag Type and Tag ID (Measurement ID). Click Triggering and choose All Pages as the trigger. This will make the tag fire on all your website pages. Then click Save to save your tag.

You can now locate your newly created tag under the Tags tab. Click Submit.

Now, click Publish to push changes to your website.

Using GTM to add Google Analytics to WordPress offers flexibility, centralized control, and easier management of tracking codes, making it ideal for beginners and advanced users.
Important: Those who use classic themes and don’t want to use any plugin with GTM can add these two code snippets in the header.php file. Ensure you add the first code snippet within the <head> tag and the second within the <body> tag.
Verify Your Google Analytics Setup
Once you successfully add Google Analytics to WordPress site, it’s time to ensure everything is set up correctly. Verifying your Google Analytics setup ensures your tracking code is working and collecting data. This step is important because you want to be confident that the analytics data you see is accurate and reflects what’s happening on your website.
Confirm your tracking code is working by logging into your Google Analytics account. In the left menu, click Reports → Realtime overview. This section shows real-time activity on your site.
Now, open your site in a new browser tab and browse a few pages. Within a few seconds, you’ll see your website activity in the real-time report In Google Analytics. If you see this, your tracking code is active and functioning correctly.

In real-time reports, check basic details like how many users are on your site, which pages they view, and where they’re located. This is a great way to confirm that visitors are being tracked and to understand how people interact with your site at any moment. If you don’t see any data immediately, try refreshing the Realtime overview page; this can sometimes take a moment to update.
If no data appears, double-check your tracking code and ensure it is correctly placed in your site’s header (if done manually) or configured properly in your plugin or Google Tag Manager setup.
![Integrate GA4 for insights on your WordPress site with our Hosting solutions Strip Banner Text - Integrate GA4 for insights on your WordPress site with our Hosting solutions. [Learn more]](https://www.hosted.com/articles/wp-content/uploads/2024/12/add-google-analytics-to-wordpress-2-1024x229.png)
FAQS
What is Google Analytics, and why do I need it for my WordPress site?
Google Analytics is a free tool from Google that tracks and reports website traffic. It shows detailed data about who visits your site, how they got there, what pages they view, how long they stay, and much more. With this information, you can make smarter decisions about your content, improve user experience, and grow your site’s potential audience.
Is it better to use a plugin or manually add Google Analytics to WordPress?
This depends on your preference and comfort level with code. For beginners, using a plugin like Site Kit by Google or MonsterInsights is the easiest and safest option. Plugins handle all the setup without editing any code, and they also offer extra features, like seeing Google Analytics data in your WordPress dashboard. If you want a lightweight site with fewer plugins, adding the code manually can be a good choice, but you’ll need to be comfortable working with WordPress theme files.
Can I add Google Analytics to multiple websites under the same account?
Yes, you can track multiple websites with a single Google Analytics account. In Google Analytics (GA4), you can create a new Property for each website you want to track. Each property has a unique tracking ID and can be managed under the same account. This setup is useful for people who manage several websites, as it allows you to track them all from one place and easily switch between different properties.
Do I need to add Google Analytics to each page of my WordPress site?
No. Once you add the Google Analytics tracking code to your WordPress site’s header or use a plugin to set it up, it will automatically track all pages on your site. The tracking code will load on every page where the header section is present. You don’t need to add the code to individual pages or posts; it will work site-wide.
Will adding Google Analytics slow down my WordPress site?
Generally, adding Google Analytics won’t slow down your website noticeably. Google Analytics is designed to load quickly and run in the background. If you’re concerned about site speed, using Google Tag Manager or local hosting for the analytics script can help optimize performance. Additionally, keeping plugins to a minimum and optimizing images and scripts on your site will ensure it runs smoothly with Google Analytics tracking in place.
Other Related Tutorials & Blogs:
– xmlrpc.php In WordPress: What It Is And Why Disable It
– WordPress Taxonomy Overview and Custom Taxonomy Creation
– How To Create A 301 Redirect In WordPress: 4 Easy Ways
– How to Fix the WordPress 500 Internal Server Error
– WordPress Malware Removal: Manual & Automatic Methods