How to Add Google Analytics to WordPress
If you run a website, especially for business, you need to know where your visitors are coming from. The best way to do this is to use Google Analytics, which involves placing a small piece of code on your site. Google can then log everyone who lands on your web property. Here’s how to add Google Analytics to WordPress.
Read more: What is WordPress and should you use it?
You can add Google Analytics to WordPress either by using a plugin or by modifying the WordPress theme itself in the head part of the page. Either way, you must first create a Google Analytics account and meet all of Google’s requirements.
ACCESS KEY SECTIONS
Using a plug-in
The easiest way to add Google Analytics code to your WordPress website is to use a plugin. There are quite a few possibilities in the WordPress plugin directory, so we’ll just take a look at two of them. You don’t need to consider any others. These make life easier.
Google Site Kit
It makes sense that the easiest plugin to use is that of Google. Site Kit is a plugin to connect your website to your Google account and take advantage of services like Analytics, Adsense, Search Console and many more.
After installing the plugin, go to settings and log in with your Google Analytics account. It will then detect the Analytics code associated with your account and link it to your site. It’s so simple. You don’t even have to copy and paste the Analytics code.
Header, footer and post-injections
If you think Site Kit is a bit overkill for your needs, you can install Head, Footer, and Post Injections instead. Once you have copied the Analytics code from your Google account, this plugin will allow you to easily paste the code into the head section on every page of your website.
Editing the WordPress Theme
Adding the Analytics code to the WordPress theme yourself is usually not worth it. Simply because with each update of the theme, the code will be overwritten. You can avoid this by creating a child theme that won’t be affected by updates, but child themes are beyond the scope of this article. However, for the sake of completeness, let’s see how you can manually add Analytics code to a WordPress theme.
Using an FTP program (such as FileZilla, Cyberduck, or WinSCP), open your website files, navigate to the theme, and find a file called header.php.
Open the header.php file using a notepad application and find the area betweenand .
Paste the Analytics code anywhere between these two head tags. Save the file and upload it to your website, overwriting the old header.php case.
As I said, however, you will need to continue doing this every time your theme is updated, unless you have a child theme created. It is really better to use one of the plugins mentioned in this article.
Read more: How to Create a WordPress Website
Yes, Google Analytics is free for WordPress.