How to add Google Analytics to WordPress

If you run a website, especially for business, you need to keep track of where your visitors are coming from. The best way to do this is by using Google Analytics, which involves placing a small piece of code on your website. Google can then record anyone who lands on your web property. How to add Google Analytics to WordPress.

Continue reading: What is WordPress and should you be using it?


You can add Google Analytics to WordPress either by using a plugin or by editing the WordPress theme itself in WordPress head section of the page. In any case, you must first sign up for a Google Analytics account and meet all of Google’s requirements.


Using a plugin

The easiest way to add the Google Analytics code to your WordPress website is to use a plugin. There are quite a few options in the WordPress plugins directory, so we’ll only look at two of them. You don’t have to think of others. These keep life simple.

Google Site Kit

Google Site Kit Plugin

It makes sense that the easiest plugin to use would be Google’s. Site Kit is a plugin that allows you to connect your website to your Google account and use services like Analytics, Adsense, Search Console and many more.

Head, footer and post injections

Header WordPress code

If you think Site Kit is a bit overkill for your purposes, you can install head, footer, and post injections instead. Once you have copied the analytics code from your Google account, this plugin makes it effortless to paste the code into it head section on every page of your website.

Editing the WordPress theme

Adding the analytics code to the WordPress theme yourself is usually not worthwhile. Quite simply because the code is overwritten every time the theme is updated. You can avoid this by creating a subtopic that is not affected by updates, but subtopics are well beyond the scope of this article. However, for the sake of completeness, let’s explain how to manually add analytics code to a WordPress theme.

Using an FTP program (like FileZilla, Cyberduck, or WinSCP), open your website files, go to Theme and locate a file called header.php.

WordPress theme header.php

open that header.php File with a Notepad app and look for the area between and .

WordPress header code

Paste the analytics code anywhere between these two head tags. Save the file and upload it to your website, overwriting the older one header.php File.

However, as I said before, you must do this every time your theme is updated unless you have a child theme created. You are really much better off using one of the plugins mentioned in this article.

Continue reading: How to create a WordPress website

frequently asked Questions

Yes, Google Analytics is free for WordPress.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button