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?
QUICK ANSWER
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
![google site kit plugin google site kit plugin](https://www.androidauthority.com/wp-content/uploads/2022/08/google-site-kit-plugin.jpg)
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
![header wordpress code header wordpress code](https://www.androidauthority.com/wp-content/uploads/2022/08/header-wordpress-code.jpg)
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.
Using an FTP program (such as FileZilla, Cyberduck, or WinSCP), open your website files, go to the theme, and find a file called header.php.
![wordpress theme header.php wordpress theme header.php](https://www.androidauthority.com/wp-content/uploads/2022/08/wordpress-theme-header.php_.jpg)
Open the header.php file using a notepad app and look for the area between <head> and </head>.
![wordpress header code wordpress header code](https://www.androidauthority.com/wp-content/uploads/2022/08/wordpress-header-code.jpg)
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
FAQs
Yes, Google Analytics is free for WordPress.