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.
- Very easy to install and configure
- Google authentication to verify and configure the analytics account
- Ability to configure custom variables in the tracking code
- Choose where you would like to place the tracking code in the webpage. It is recommended that you place it in the header of the page
- Lots and lots options that can be configured
- Local hosting of the tracking code rather than serving from the google servers
- Ability to ignore logged in users or users based on roles from being counted in the stats
- Easy to install and configure
- Includes a summary widget which shows some of the statistics right on the dashboard
- Ability to either track or ignore admin users
- Easy to install and configure
- Very Simple plugin with a very minimal options
- Have to manually enter the Google Analytics ID
- Not a Google Analytics specific plugin
- Lots of tools for search engine optimization
- Advisable if you already use this plugin for other SEO features
- Not a lot of configurable options which are google analytics specific
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.