how to add google analytics tracking code to your wordpress blog

Posted on February 5, 2012June 4, 2016bybarkeep

Google Analytics is a tracking service from Google which can be used to track your blog’s popularity, user behavior, user interaction among many other features. Understanding what your users do when they are on your website and what they read will help you increase the popularity of your blog. It allows you to understand what the reader’s respond to most, find out which of your blog posts are the most popular and how the readers find your blog posts etc etc.

There are mainly two different ways you can add the Google Analytics tracking code to your WordPress blog. You can add it manually into your website or you can use a plugin that will do it automatically for you. It is quite unlikely that you might want to add it manually to the blog, but if you are technically inclined and wish to add more custom tracking properties to the blog then it might be useful. Most people would want to stick with the plugin.

You will have to sign up for the Google Analytics service first, if you haven’t already done so. After you have signed up you will get access to the tracking code that needs to be inserted. If you are using a plugin, then you do not have to worry about it as the plugin will do this for you. Otherwise, if you plan to insert it manually into the theme, then you will have to get the relevant code from the Google Analytics web interface.

Adding tracking code using plugins

WordPress has several plugins that will add the appropriate tracking code to all your webpages. This is a compilation of the some of the popular WordPress plugins that you can use to install analytics on your blog.

Adding tracking code manually using the header

Every blog, including WordPress blogs are essentially websites just like every other website. That means you can install the tracking code just as you would install on a regular website. Being a WordPress blog, you need to enter the tracking code into the header file so that it appears inside the header tag of each and every webpage in the site.

In the WordPress install directory, find a file named header.php

Open header.php in a text editor

Look for the end of the head tag in the file. It should be something like </head> towards the end of the file.

Insert the tracking code just above the </head>

Save the file

Some themes recommend that the wp_head be the last piece of code in the head tag in which case you can insert the GA code just above it. It does not really matter whether you put the code before or after the wp_head, it works in both cases.