Easy Ways on How to Install Google Analytics on Your WordPress Website

If you have a WordPress page or blog and want to monitor the traffic and statistics of your site, surely you have wondered: How can I install Google Analytics on my website? Where do I insert the code? Are there WordPress plugins for Google Analytics?

Overtime, I have been seeing a lot of queries on how to install Google Analytics on a WordPress website. And although there are a lot of guides on how to do it, I found them to be a little bit short of technical explanation.

In this post I will explain how to install Google Analytics on your website or blog in two different ways, one simple and one a little more advanced:

Mode 1: WordPress Plugins for Google Analytics

There are WordPress plugins to install Google Analytics on your site quickly and easily, without knowing HTML code. You just need to have a Google Analytics account for your website or blog, and have the UA code that the tool gives us. In most cases, just enter this code and you already have it.

Advantages: It’s quick to set up and you don’t need to be an expert. Simply enter the UA code or synchronize your web page with your Google Analytics account.

Disadvantages: You are using a plugin for something you could do using HTML code. Whenever you can do it in another way, avoid installing a plugin, since in this way you optimize the loading times of your web page and the space on your server, in addition to avoiding possible incompatibilities between plugins when you have many installed.

Remember that Google takes into account the loading times of your website for SEO positioning. If you want to measure and optimize the performance of the plugins installed on your site, I recommend the P3 plugin (Performance Profiler Plugin).

Here are my most recommended WordPress plugins for Google Analytics installation:

Google Analytics by Yoast

Created by Joost de Valk, author of the acclaimed SEO Yoast plugin, this plugin allows you to quickly synchronize your website or blog with your Google account to start recording traffic data. You can also do it manually, by entering the UA code of your website.

Yoast Google Analytics Configuration
Image Source

Once installed and activated, in Settings you can adjust a series of advanced options, such as tracking outbound links and downloads, type of download files to track, activate the universal tracking option, enable demographic and interest reports, monitor subdomains, debug mode , etc… In addition, you have a Dashboard where you can consult the analytical reports within the administration panel of the site.

An excellent option and with the seal of quality of the Yoast Team.

Google Analyticator

With Google Analyticator, as in the previous case, you can synchronize your website with your Google account and access an advanced dashboard in which to monitor your traffic data and configure various options such as outbound link tracking with enhanced functionality, downloads by types of files downloaded, obtain remarketing, demography and interest reports, etc.

In addition, you even have the ability to track your Google Adsense account statistics Entering the ID If you are not interested in using the internal Dashboard functionality in your WordPress panel you can choose to do a simple site crawl to see the statistics in the Google Analytics panel simply by entering the UA code, as in the previous case.

Another fantastic tool to install Google Analytics on your website or blog.

Mode 2: HTML Code in the Header

If you are a bit more advanced user and know some HTML code you have another alternative: paste the Google Analytics code directly into the <head> tag of your website.

If you have designed HTML web pages, you will know that in the code of each HTML page you have an opening <head> tag and a closing </head> tag at the top. Between the two opening and closing tags there are a series of lines of code where the links to the site’s style sheet, sources, javascript files, etc. are usually inserted.

In the case of WordPress, it is a PHP-based system and the pages are dynamically constructed, that is, to create each page the tool takes portions of code from various files and thus builds them intelligently. Normally, among the files of the site, there is one called header.php which includes all the HTML code that you will add to all pages of the site so that they all have the same header.

Therefore, to implement the Google Analytics code, you just have to access the editing area of ​​the WordPress panel and then go to the header.php file, where you will find at the top all the HTML code of the site header : <head><meta> <title> tags, etc. What you have to do here is paste the Google Analytics code into a line between the <head> and </head> tags. Once you’ve done this, Google Analytics can now start tracking your website or blog statistics.

Advantages:  You save the installation of plugins, thereby optimizing the speed of the site. Remember: plugins are a wonderful help and one of the strengths of WordPress, but if you abuse them (and if you do not document well and do not test them before) they can become the Achilles heel of your website and ballast their performance, cause incompatibilities and anomalous behavior of the page, etc. Therefore, in general, whenever you can do it without plugins, do it without plugins.

Disadvantages: It requires more advanced knowledge, knowing some HTML code and getting to edit an .php file with the risk that this entails if you are not at all expert. If you do not enter the code in the right place or if you delete or modify lines of code of the subject you can spoil its correct operation and finally have to reinstall everything again.

Apart from this, by doing it through code you are simply enabling the tracking of your web page or blog by Google Analytics, but you are missing all the monitoring and configuration possibilities in an internal WordPress Dashboard offered by some of the plugins mentioned above .

Therefore, before making the decision, I will explain in detail  how to insert the Google Analytics code between the <head> and </head> tags of the HTML code of your website in WordPress.

Access the WordPress file editing area

To access the area where you can edit your files you must go to Appearance> Editor in your main WordPress Dashboard menu.

Locate the header.php file

On the right side of this section you have a list with all the files that you can edit in your theme or template. Find the header.php file and click to display all the code in the central zone.

Locate the <head> and </head> tags and enter the code

Search inside the code for the <head> and </head> tags and anywhere between the two tags press enter to open a new line. Then paste the code provided by Google Analytics for the manual installation of the tracking functionality of your website or blog.

Once you have pasted the code, click on the Update file button in the lower left. Now you have the Google Analytics crawl running for your site.

How to get the Google Analytics code to insert into your website?

You get the Google Analytics code or tracking code by logging into your Google Analytics account. Next, you have to click on the Administrator tab, and in the first column (Account) you select the web page for which you want to obtain the tracking data.

Once the web page is selected (you can have several websites tracked with Google Analytics), you go to the second column (Property), and click on Tracking Information. Then, in the drop-down, click on Tracking code.

Once inside this section, the tool shows you a code that you must enter between the <head> and </head> tags of your web page or blog.

Once you copy the code, go back to the editor and paste it between <head> and </head>. Once done the right way, it will immediately reflect in your source code and will start to record traffic on your website.