Add Google Analytics On WordPress | WordPress 101

Welcome to the WordPress 101 series. We’ve already learnt how to install a new WordPress theme, plugins, configure the homepage, create navigation menus, and so on. We should be able to start our website using this information. It is now time to prepare our website for traffic analysis so that we can make better judgments and have a clear picture of what is happening with our website.

Once your website is functioning and contains high-quality content, search engines will begin directing traffic to it. The number of visitors and engagement develops in tandem with the amount of content on the website. For knowing where your visitors came from, how much time they spent on a specific page, the links they clicked, and much more detailed information that can help you develop a better user experience and provide better results.

If the website is an eCommerce store, the analytics system can be incredibly beneficial in terms of increasing sales. You may track campaigns on social media as well as using an analytics solution such as Google Analytics.

Traffic Analysis Solutions

Google Analytics & Statcounter

There are innumerable analytics solutions available on the Internet, but Google Analytics and Statcounter are two of the most widely used. Whereas Statcounter provides a straightforward glance at your website visitors, Google Analytics delivers a wealth of information about them.

Integrate Google Analytics with WordPress site

It is simple to add Google Analytics on WordPress. Let’s begin by creating a Google account; if you already have one, continue ahead and login. Go to Google Analytics and it will walk you through a basic setup.

Type the account name and check or uncheck data sharing. Press Next.

Setup Google Analytics Account

Next, enter the property information. A website or an Android/iOS app might be considered a property. In this example, I’ll host a test website. So I enter the property name as the website’s URL. Click Next after selecting the reporting timezone.

Google Analytics Property setup

Enter your business information. It is not required, so you can leave it blank and click Create.

Business information

Lastly, select your country, read the terms & conditions, and accept it. The initial setup is over.

Read and accept terms & conditions

Now select the type of property you want to integrate Google Analytics with. In this case, I want to setup Analytics on the WordPress site, I select Web.

Analytics add property

Enter the URL of the website, name of the website, and toggle on/off enhancements. You can capture Page views, Scrolls, Outbound clicks, etc. So you can toggle them all on or off or select the specific ones you want and click Create stream.

Analytics add website
Add remove features

And that’s about it from Google side. Now Google will create a Global site tag which essentially is javascript code that you need to paste on each page’s header of your website.

Now there are two easy ways to paste this code into your website header. First, copy the code and paste it into the header of your website or use Google Tag Manager. I will explain both methods in this article.

Google global site tag

Let’s start with the first one. Copy the code and paste it into the header. Here is how to do it –

Login to your WordPress site and paste the above code so that it is distributed on each page of your website. Many WordPress themes provide a simple setting for adding custom code or scripts in the header.

In case your theme does not have this feature, you can use a plugin that allows adding code to the header and footer. You can install Insert Headers and Footers. More on how to install WordPress plugins is discussed here.

Once the plugin is installed, from the admin sidebar, go to Settings > Insert Headers and Footers. Now paste the Google site tag or gtag.js in the header. That’s all! You have successfully integrated Google Analytics with your WordPress site.

Using Google Tag Manager

The process described above is straightforward, but if you add additional services to your WordPress site, it will become more complex to manage third-party scripts. Google Tag Manager is a service that allows you to simply apply tags across multiple sites from a single platform. Go to the website, sign in with your Google account, and then select Create Account (Google Tag Manager).

Enter the Account Name, country, website URL, platform, and click Create.

setup Google Tag Manger

It will now display the code to be placed into the header and footer of your WordPress site. You’re probably wondering why not just copy and paste the analytics code. As previously said, you can control many websites from the GTM platform, as well as individual scripts, which is not possible with the preceding WordPress plugin.

Google Tag Manager code

Your website is integrated with your site once you enter the above GTM code into the header and body of your website. Click OK to return to the GTM tab. You will now view the GTM dashboard. As shown below, click New Tag.

Add new tag

Now, it will slide in the following window.

Enter the tag’s name here. The second option is crucial. Using established templates, Google Tag Manager enables you to effortlessly combine various in-house products such as Analytics and third-party products. So we can choose Google Analytics: GA4 Configuration, which will allow you to integrate Google Analytics with your website. However, for the purposes of this tutorial, we shall utilize gtag to integrate Analytics.

GTM tag configuration

So select Custom HTML from the tag type list. Paste the Google Analytics code (gtag.js) in the HTML box.

GTM tag type

Now scroll down and click the Triggering box. This is why GTM is useful. With GTM you can control when a particular script should load and where. I select All Pages out of the three predefined triggers. It means the script will load on all the pages. You can also create your own trigger by clicking the + icon on the top right corner.

GTM Trigger

Select the trigger and click Add. Click Save to save the tag settings.

It’s not finished yet. Your tag has been added, but it will not be visible until you click Submit. You can preview how the website would look with the script before submitting modifications to the site. Click Preview, then input the URL of your website and click Connect. If your GTM code is on the site, your website will be connected, and you will be able to apply all of your changes by hitting the Submit button on the GTM dashboard.

When a user hits any page on your website, GTM will now load the Google Analytics script. Similarly, you can include any other tags you want, such as Statcounter, Google Adsense, Google Search Console, and so on.

Many themes offer their own methods to add Google Analytics into a WordPress site. It is not possible to cover all of the themes in this tutorial and demonstrate how to connect Google Analytics. However, if you are having problems with your theme and the theme developers are not assisting you, let me know in the comments area below or join our Discord Server. I’ll do my best to assist.