Know your visitors : setting up Google Analytics with WordPress

As website owners, you want to know more about your readers and their behaviors. This is usually called the Web Analytics. It is this data about your visitors that will help you make critical marketing and design decisions for your website. 


Web analytics is the  measurementcollection, analysis and reporting of web data for purposes of understanding and optimizing web usage. Web analytics provides information about the number of visitors to a website and the number of page views. It helps gauge traffic and popularity trends which is useful for market research.

source : Wikipedia

The most comprehensive and free tool that gives you an understanding of the people who visit your site is  Google Analytics.

Any web anayltic software will need to add a javascript tracking code snippet on each page of your website to record your visitor's behavior.

The following documentation will describe :

  1. How to grab the tracking code from Google Anaytics
  2. How to install this code on your website with a plugin or manually.

Setting up your Google Analytics tracking code

If you haven't done so already, head to the  Google Analytics site and sign up for an account. If you've never heard about Google Analytics before, you'll want to read this introduction.

To find the code, login to your account, set up your website for a new account by giving your site's url and other details. You can choose Universal Analytics, which has more features, but is in beta or Classic Analytics. Once you have added your site, go to your Google Analytics dashboard, click on Admin > Property > .js Tracking Info > Tracking Code

Once you click on Tracking Code, a screen like below appears with your unique tracking id. You can also see a JavaScript tracking code below. Copy this code.

Now that you have your code, you need to use it on your WordPress site. Google Analytics can be added to your WordPress site in several ways. If you are using a theme like Customizr Pro, you'll simply need to copy it in the live customizer as documented here. If you're using another theme that does not have this feature, it is advisable to use a plugin. There are a few  different free plugins available for this purpose.

Developers will also be able to add with a code snippet example provided at the end of this documentation.

Adding your tracking code with a plugin

1. Google Analytics by Yoast

Installation is the usual drill. Click on Plugins > Add New from WordPress admin dashboard and search for Google Analytics by Yoast. Click on Install Now against the plugin from the results. Activate the plugin.

Once activated, go to the Settings page of the plugin and in the General tab, click on Authenticate with your Google account. Login with your Google account. You will be given a Google code, which you have to copy and paste in the input box provided. Now, choose the analytics profile that you want to use.

Alternately, you can also check against Manually enter your UA code and type the tracking id in the input box provided.

Do not forget to click on Save Changes.

2. Google Analyticator

This is another Google Analytics plugin by SumoMe which allows you to not only set up Google Analytics by also view the statistics from inside WordPress.

Installation is as usual. Click on Plugins > Add New from WordPress admin dashboard and search for Google Analyticator. Click on Install Now against the plugin from the results. Activate the plugin.

After activation, go to Settings and authenticate with Google Authentication Code. You may also choose not to authenticate through Google. In this case, only tracking happens and you cannot view the statistics from inside WordPress.

Once you do this, you are taken to a Basic Settings screen when you have to enable Google Analytics logging, give your tracking id and also choose whether you want Universal Analytics or Classic Analytics.

This is followed by a whole lot of advanced settings to tweak what you want to track.

3. WP Google Analytics

Yet another Google Analytics plugin is the WP Google Analytics. Install it the usual way by clicking on Plugins > Add New from WordPress admin dashboard and search for WP Google Analytics. From the results, click on Install Now against the plugin. Activate the plugin.

After activation, go to Settings. This plugin has a single screen of a whole lot of options starting with the tracking id. Enter the tracking id and click on Update options. You are done.


These are not the only Google Analytics plugins available. There are more and each comes with unique advantages and disadvantages. Our personal preference is the Google Analyticator. Except for the slightly irksome name (what is an analyticator?), it scores in many other features. Here are a few:

  • It is very easy to set up (and so is it with a few other plugins).
  • Logged in users can be excluded from statistics.
  • The options for statistics are many.
  • The ads are few and though there is a link for donation to developer, it does not overdo the ads part.

How to add it manually (for developers)?

If you are even slightly savvy with code and you do not want to burden your WordPress with yet another plugin for this simple Google analytics tracking, you can choose to add the tracking manually. Here is what you do:

  1. Do you still have the copy of the tracking code that you copied in the "Where to find the code?" section? If not, make a copy of the code.
  2. Go to your Child theme's functions.php file and add the following code. Between <!-- START OF TRACKING CODE --> and <!-- END OF TRACKING CODE -->, paste the code that you copied in the previous step.
  add_action('wp_head','my_analytics', 20);
  function my_analytics() {
        (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
        ga('create', 'UA-XXXXXXXX-X', 'auto'); /* CHANGE THE TRACKING ID HERE */
        ga('send', 'pageview');
      <!-- END OF TRACKING CODE -->

Save and Exit. That's it. You're done.

How to check if it has been correctly implemented ?

Login to your Google Analytics dashboard. Click on Admin > Property > .js Tracking Info > Tracking Code

Right on top, next to the tracking ID, you can see the Status. This should be Receiving Data. Typically, after you add a new website, it takes a few hours before Google Analytics starts receiving data. If it is Tracking Not Installed or Not Verified, then something is wrong. If it is Waiting for Data, wait for a few more hours before you strike the panic button. If it is Receiving Data, all is well and you can rest assured that your website data is getting collected.

Doc created by: Menaka S.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.