Skip to content

How to install Google Analytics in WordPress

Installing Google Analytics in WordPress is one of the best ways to analyze the traffic of your website.

This powerful tool will let you know, among other things, the number of users that visit you, the duration of each visit, the origin of these visitors and the channel they used to reach your website. If used wisely, this information can become a very valuable asset to optimize your site and improve the quantity and quality of traffic.

However, it is very important that the tracking code is correctly implemented or it is possible that not all the information will be recorded.

In this article we will see 4 ways to install Google Analytics in WordPress. To implement any of the methods that we will show you below, you must have your tracking code at hand. You can find it within the administration panel of your Google Analytics account, in the “Monitoring information” section.

Install Google Analytics in WordPress using a plugin

Possibly it is the most common method of all. If you have any experience with WordPress, you will know how easy it is to install plugins and there are many options for this purpose. When choosing one we recommend you look at the following aspects:

-Number of active facilities

The plugins that are used for common purposes like this usually have more than 10,000 active installations. Therefore, this is usually a good indicator of its proper functioning.

-Best reviews

Similarly, the best plugins have a high number of ratings with 4 or 5 stars. Read the ratings of the users and if you find many negatives, better look for another option.

-Recent date of the last update

If a plugin has been updated recently, it means that there is a team behind it that supports it. This is also a factor to take into account because it is not advisable to have plugins without updating that may cause a malfunction of our site or a security threat.

-Compatibility with your WordPress version

It is essential to have our version of WordPress updated, but it is quite common for new versions of plugins to arrive with a little delay. Although this does not mean that they will stop working automatically, it is recommended that at least at the time of installation they are compatible with our current version.

From here, the choice of one or the other is to the consumer’s liking. Some plugins to install Google Analytics in WordPress show you very complete statistics in the own WordPress desktop and others only allow you to install the code, but they work perfectly. Take your time to try several until you find one that you feel comfortable with.

The main advantage of using this method is that even if you change your template, at no time will you lose tracking information.

Install Google Analytics in WordPress using a template

Many WordPress templates, especially Premium ones, already include a specific box to paste the tracking code. In this way, installing Google Analytics in WordPress is the easiest thing in the world and you will not have to worry about some pages being left out of analytics. The template will be responsible for you to implement the code correctly in all posts and pages that are generated.

Therefore, it is clear that the main advantage of choosing this method is simplicity. However, you should bear in mind that if one day you decide to change the template and you forget that the code was saved in the options of the topic, you may lose the tracking information from that moment.

Install Google Analytics in WordPress manually in the header of the topic

If your template (Premium or free) does not include the option to insert the tracking code in the theme options, then you may have to insert it manually. For this you will have to edit the header.php file of your WordPress theme to paste the Google Analytics code.

The most common ways to access the edition of the files are the following:

-With the file manager of your hosting panel (eg cPanel).

-By means of the WordPress file editor that is on the Desktop> Appearance> Editor.

-At FTP access and using an external file editor.

In any of the three cases, you must navigate to the header.php file of your theme and paste the tracking code inside the tag. Normally the file is located in the path /wp-content/themes/mitema/header.php

In this way, the tracking code will be replicated correctly, since the header.php file is common to all pages of the website.

Like the previous method, you should keep in mind that if you change the theme, the modifications you have made manually will be lost with the change. You just have to perform this same operation on the new theme that you install and everything will continue to function normally.

NOTE: This method can also be implemented by pasting the tracking code into the functions.php file of the WordPress theme instead of the header.php file

Install Google Analytics in WordPress manually with a call to a * .php file

In this method, instead of pasting the tracking code directly into the header.php file of the WordPress theme, we will make a call to an external file that contains the code to insert it into our pages.

Using an administrator or file editor, create a new file in the root folder of your server called analyticstracking.php and paste the tracking code into this file.

Next, edit the header.php file and within the tag include a call to the file you created using the following syntax:

This method works very similar to the previous one. Each time a page is generated in WordPress, the tracking code will be included in the header.

Conclusion

As you have seen we offer you 4 methods that go from the simplest to the most complicated, each with its pros and cons. We hope you have been useful and if you need help, do not hesitate to leave us your query in the comments. We will respond as soon as possible.

Published inApps
%d bloggers like this: