How to install Google Analytics in WordPress

Whenever we start with a new web project sooner or later we will need to install Google Analytics in WordPress, and the reason is simple: we need to measure everything that happens on our website.

Although it is such a widespread and necessary process, it is very common not to be clear about how to carry it out and to know the different options, especially the most appropriate for your website.

Throughout this post we are going to try to help you better decide how to install Google Analytics in your WordPress in the most optimal way.

Can you come with us?

What is Google Analytics and why do you need it for your website?

What is Google Analytics

Google Analytics is without a doubt the most important and most used web analytics tool to obtain valuable statistical information from your website.

There are several reasons for its success that we will list below:

  • Enormous potential to obtain a lot of information on a huge number of metrics to measure on your website
  • Google property: if what we are interested in is positioning for Google (it will be yes) there is no more reliable tool to obtain information that helps us to obtain success with our website
  • His gratuity: this is another differentiating factor for which it is such a widespread tool

Now, why do you need Analytics for your website?

As we said before, you need it to know in depth what is happening throughout your website, or in other words, not to go blind without knowing what is happening on it.

Although we could summarize Analytics in a tool that helps us measure the visits we have on our website, it would be too simple a statement.

This tool is key to:

  • Define the success of your content strategy: knowing which content is working the best.
  • Analyze, measure and improve the number of conversions: if you have an ecommerce or simply offer some type of product or service, you can measure the conversions you are obtaining and extract information to also implement improvements.
  • Know more about the user profile Who visits your website: you can better know if the profile you have defined to address you matches the type of user who visits your website, all thanks to the measurement of their behavior.
  • Fixes design and structure of a website: through this tool we can also analyze if the structure that we have defined for our website is the most appropriate thanks to the information we obtain.

And what do I need for Google Analytics to start measuring and offering me this valuable information?

Of course the first thing you need to do is create an account.

In the process of creating your first Google Analytics 4 property, you will be provided with a global tracking tag in order to connect your website and start receiving data.

The operation is simple, once this tag is installed, every time an interaction is generated on your website that tag identifies it as a event type.

For example if someone visits a page an event is triggered page_view.

So, the key is to know how we install that tag in our WordPress, for this we have several options that we are going to see now.

Ways to install the Google Analytics tracking tag in WordPress

Among the different methods to use to insert that tag You will have to take into account what type of web project you have, as well as the plugins and themes that you already have.

Take this into account as they condition a more adequate installation.

Without going any further, if you already have a plugin that allows you to insert this tag in it, why are you going to install another plugin that does the same (unless you want more information that that other plugin does not provide)?

Therefore, choose well depending on your needs.

So we go with all the options and then you choose the one that suits you best.

Manual installation of the Google Analytics 4 tag directly in the “Head” of your website

This is the most direct way to connect your website and your GA account, just copy the complete code from your label and insert it directly in the “head” of your website.

The code provided is available by selecting “Global Website Tag (gtag.js)” and we get something similar to this code from a test property that we created:

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-QC1BRNVH9R"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'G-QC1BRNVH9R');
</script>

For its insertion we have several ways.

  • If we have a “theme child” we can directly paste this code inside from the file header.php right between the labels «head», specifically before the closing of the tag so that it is loaded correctly in the header of the web and in all the pages.
  • It is possible that our theme has a section in which to insert code that is directly embedded in the header. This is a feature that themes like Generate Press have.
Manual installation of the Google Analytics 4 tag directly on the "Head" of your website with Generate Press

As you can see, this is the simplest method of all, which does not require installing anything else, although it is also true that if you do not have some knowledge regarding how your theme works or editing these files it may not be easy.

On the other hand, you will not have any information regarding the data obtained on your desktop, contrary to what happens with other options.

Install your Google Analytics 4 tag using Google Tag Manager

Install your Google Analytics 4 tag using Google Tag Manager

This is a very interesting option if your web project is more advanced and you are also using Google Tag Manager.

Google Tag Manager is a very complete tag management tool that allows you to quickly and easily update various tracking codes and code snippets on your website.

The best thing about this tool is that once you have connected it to your website, you will never need to manually insert a tag on your website again.

So Google tells us that we must carry out the following steps in Google Tag Manager:

  1. Open the Google Tag Manager container that is implemented on your page.
  2. Click on Labels > New.
  3. Click on Label Settings and select GA4 Configuration.
  4. Enter this measurement ID: G-QC1BRNVH9R (Important, this ID is ours for testing, you must replace it with yours)
  5. Choose whether you want to enable the label on All Pages or only on the subset of pages that you want to measure.
  6. Save and publish the tag settings.

The advantage of using this method is that we do not have to “touch” anything on our website and we will also have the full potential of a tool like Tag Manager.

Install your tag using a plugin

Install your tag using a plugin

This is the easiest option to use for non-advanced WordPress users.

Google makes it very easy for us with its official plugin «Site Kit Google», a plugin that allows us to connect very easily basic google services for our web project such as:

  • Google Analytics
  • Google Search Console
  • Google Adsense
  • Google Page Speed Insight

With this plugin we will also have visual access to the main metrics and the most relevant information of each service directly on our WordPress dashboard.

This in the case of Analytics is very useful for from our own WordPress dashboard to have a simple look at metrics such as number of users or channels from which your visits are coming.

One of the advantages of this plugin is how simple it is to configure, you only need to follow the steps that the plugin indicates and you will have your services connected.

We tell you more about this plugin in this guide that we have published on our blog.

Other plugins that may also be useful to you

Apart from the official plugin, for many years we have had so many other plugins that have made it easier for us to connect Analytics with WordPress and that today are still a good option if what you want is not to complicate too much.

It may interest you: What are the best WordPress plugins in 2021?

These are the ones we recommend:

Google Analytics for WordPress

Google Analytics for WordPress

This MonsterInsights plugin is one of the most interesting that you can install to track your metrics, not only for the simplicity of its installation but also for the amount of extra information that it offers us in our WorPress desktop.

We highlight:

  • Audience report
  • Behavior report
  • Most viewed content report
  • Customization of the dimensions to show in the reports

If these features are a bit short for you, this plugin also has a paid version with many more interesting features.

Rank Math

Rank Math

If you have already installed this SEO plugin on your website, you have a section where you can connect this plugin with all Google services.

Once connected you can easily configure your property and dispense with other specific plugins for this task.

As simple as that!

GA Google Analytics

GA Google Analytics

This plugin is one of the veterans in the repository, it also has very good ratings and a large number of downloads.

We like this plugin for its good performance and ease of use.

Conclusions.

We have already reached the end of this post with the main methods to be able to track all the analytics on your website.

As you have seen, the options are varied and your choice will depend on your level of knowledge as well as the needs for your project.

In any case, whether you choose one or the other option, we recommend that you do not leave your WordPress connected to Analytics.

Finally, we do not advise you to use several different methods to connect your website, choose and use only one.

Now it’s up to you to choose how to connect Google Analytics to your WordPress!