WordPress 101

Add Google Analytics To WordPress | WordPress 101

Google Analytics Statcounter

Welcome to the WordPress 101 series. So far in this series, we’ve learned how to install a new WordPress theme, plugins, configure the homepage, create navigation menus, and so on. With this information, we should be able to launch our website. It is now time to prepare our website for traffic analysis so that we can make better decisions and have a complete picture of what is going on with our website.

Search engines will begin delivering visitors to your website once it is operational and has high-quality content. As the amount of material on the website grows, so does the number of visitors and engagement. For understanding where your visitors came from, how much time spent on a particular page, the links they clicked, and a lot more deep information that can help create better user experience and deliver you better results.

If the website is an eCommerce store, then the analytics system is extremely useful as it can help increase sales. You can track campaigns on social media and track each of the campaigns through an analytics system like 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 integrate Google Analytics. 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
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
Google Analytics Property setup

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

Business information
Business information

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

Read and accept terms and conditions
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
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
Analytics add website
Add remove features
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
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
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
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
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
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
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
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.



Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.