How to Add Google Analytics to WordPress in 4 Steps

How to Add Google Analytics to WordPress in 4 Steps

New WordPress webmasters are often dismayed to learn that the core platform doesn’t let you see anything about what your visitors are doing on the site, nor does it tell you how many people have visited it. To analyze your website traffic, you’ll want to make use of Google Analytics, one of the most popular and powerful tools for tracking visits and gaining insights into how your site is being used. It is not only a full-featured traffic stats viewer but also a complete marketing research tool that helps you track the performance of your online marketing campaigns.

In order to add Google Analytics to WordPress, all you need is administrator access to the site to either edit your theme files manually or install a plugin. Several methods for adding the Google Analytics tracking code to your site, along with some details about Google Analytics are presented below by our team at wpDataTables.

The Benefits of Using Google Analytics

The main purpose of any website is to attract people and make them interact with you or your business, whether by sending you their contact details or buying a product. Google Analytics can help website owners to take better decisions, based on genuine data and easy-to-read stats. With this tool, you can gain more information about:

  •       The people who visit your site

Google Analytics for WordPress can tell you more about the geographical location of your audience or even technical details like what type of devices they are using to access your site.

  •       What people are doing on your site

Once you add Google Analytics to WordPress, you will be able to learn more about your website’s bounce rate (how many visitors are leaving the website without interacting with it in any way), as well as identify the most accessed and effective pages.

  •       What is the peak hour of your site

Google Analytics can show you the exact moment when people accessed your site, thus giving you the chance to see when it’s the best time to publish something imperative.

  •       Where the traffic is directed from

This tool can analyze whether people accessed your site through a search engine, a social media hub, an external link, or other sources. It can also figure out if the website was accessed by the user typing in the site’s address directly.

  •       How people interact with the site

Google Analytics can tell you more about how users interact with your site – what links they usually click on, what CTAs they use, how many people are converted and so on.

  •       Other tiny, but useful, details

The information you receive won’t stop there. Google Analytics can provide details that you didn’t even think about before, like what language your visitors speak, what browser they use, or what resolution their screen has. These small things can influence their experience with your site and can help you make better decisions in the future.

The 4 Steps for adding Google Analytics to WordPress Manually

Before editing any theme files whatsoever, remember to make a backup of your WordPress first. You never know when things might go wrong and it always pays to have a backup on hand.

After you’re done with the backup, get ready to edit the code behind your WordPress site. Insert one wrong character and the entire website can be affected, so pay great attention when editing the code.

Keep in mind that Google Analytics works best with WordPress Child themes. Downloaded themes that need frequent upgrades will require altering the code each time on every upgrade, and you will lose your previous Google Analytics info. Create a Child theme from your original theme to avoid losing any changes like this in the future.

Step 1: creating the account

First of all, you need to set up a Google Analytics account. This tool is free, and you only need a Google/Gmail account to make it work. Visit the Google Analytics sign up page and follow the listed instructions to create your account. If you already have a Google account, log in directly with those credentials. If you don’t have one, you’ll be redirected to a page where you can create a new account.

Step 2: finding the tracking code

Once you have the account ready, select the website that you want to track and copy the code you are provided with. Notice the Admin button in the left taskbar and click it. A Tracking Info window will pop up and there you will find your Tracking Code.

Step 3: uploading the tracking code

To upload this tracking code in WordPress, you will need to follow these instructions. The standard themes that WordPress comes with have a header.php file. This file is meant to display the header section of your WordPress site on all pages. To add Google Analytics to WordPress, you can simply paste your tracking code here.

You can do that by logging in to your WordPress dashboard. Then, navigate to Appearance, and Theme Editor. In the right sidebar called Theme Files, find the header.php file, click it, and edit it accordingly. Paste the code right above the </head> tag. Click Update File and you’re set. Another option would be to use a plugin that can do this for you, which we’ll cover at the end of this article.

Step 4: access Google Analytics

This is the last step and it’s meant to make sure that the tracking code was successfully inserted. Go to Google Analytics and navigate to Real-Time and then Overview. Now, access your website from your browser and see if the Google Analytics stats are changed in any way. If yes, then your site is connected to Google Analytics and you are good to go.

Other methods you can use


You can also use a Google Analytics WordPress plugin to add the tool to your site without worrying about the manual process explained above. Most plugins of this type are free and very easy to install. The only “catch”is that they are packed with features that you won’t probably use. The most common Google Analytics plugin is MonsterInsights, but you can also use: Insert Headers and Footers; GA Google Analytics; Analytics Cat. Check them all out and choose the one that fits your needs best.

Google Tag Manager

You can also add Google Analytics to WordPress using the Google Tag Manager, which is a system that helps users update their tracking tags and code snippets without all the effort involved in doing this manually on your site for each new snippet. You can use the Google Tag Manager for WordPress plugin to manage your Google Analytics tags and snippets from one place. It has a friendly user interface and doesn’t require much tech knowledge, which means you won’t have to hire a developer to configure your website’s code.

How to make the most out of it

Google Analytics is extremely powerful on its own. Finding your way around this tool won’t require much effort from you, as it is intuitive and easy to use. Even so, it’s best to combine Google Analytics with Google’s Search Console, formerly known as Webmaster Tools. This is the safest way to make sure that you get the absolute best out of Google Analytics and the data it gives you access to.


Developing a website that pleases users from the get-go is never easy. All your efforts of making your website the best it can be will be in vain if you don’t know whether it meets the goals and expectations of your users. The only way to gain these insights is to add Google Analytics to WordPress and track these aspects over time. No matter how much traffic you receive, using Google Analytics will helping guide you towards making better, data-driven decisions in the future.

If you enjoyed reading this article about adding Google Analytics to WordPress, you should read these as well:

Up Next:

How to Stop a DDoS Attack on Your WordPress Website?

How to Stop a DDoS Attack on Your WordPress Website?