Affiliate links on Android Authority may earn us a commission. Learn more.
How to add Google Analytics to WordPress
If you are running a website, especially for business, you need to keep track of 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 record everyone who lands on your web property. Here is 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 through the use of a plugin, or by editing the WordPress theme itself in the head section of the page. In all cases, you must first sign up for a Google Analytics account and satisfy all of Google's requirements.
JUMP TO KEY SECTIONS
Using a plugin
The easiest way to add the Google Analytics code to your WordPress website is by using a plugin. There are quite a few possibilities in the WordPress plugins directory, so we will just take a look at two of them. You don’t need to consider any others. These ones keep life simple.
Google Site Kit
It makes sense that the easiest plugin to use is Google’s own. Site Kit is a plugin to connect your website to your Google account and take advantage of services such as Analytics, Adsense, Search Console, and many more.
After installing the plugin, go to the settings and log in with your Analytics Google account. It will then detect the Analytics code associated with your account and link it to your site. It’s that simple. You don’t even need to copy and paste the code from Analytics.
Head, Footer, and Post Injections
If you think that Site Kit is a bit overkill for your purposes, then you can instead install Head, Footer, and Post Injections. Once you copy the Analytics code from your Google account, this plugin will make it effortless to 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 generally not worth it. Simply because, every time the theme is updated, 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 way outside the scope of this article. However, for the sake of completeness, let’s go over how you can manually add Analytics code to a WordPress theme.
Open the header.php file using a notepad app and look for the area between <head> and </head>.
Paste the Analytics code anywhere between those two head tags. Save the file and upload it to your website, overwriting the older header.php file.
As I said, though, you will have to keep doing this every time your theme is updated, unless you get a child theme made. You’re really much better off using one of the plugins mentioned in this article.
Read more: How to build a WordPress website
Yes, Google Analytics is free for WordPress.