Add Google Analytics to WordPress

How to add Google Analytics to WordPress

Introduction

You will love Google Analytics, it’s FREE and a must have for every WordPress website. Discover how quick and easy it is to implement.

Note: This is tutorial by AoxoA is only for self-hosted WordPress.org sites. Free WordPress.com sites cannot use Google Analytics.

Why Add Google Analytics to WordPress

Once your self-hosted WordPress site or blog is set up, you may want to see:

  • Who visits
  • When they visit
  • What they do on your website
  • How they arrive to your site
  • How many visitors
  • How long they stay
  • Which pages they visit
  • …and much more

This information (called stats) will help you understand how your audience interacts with your website.  Plus, advertisers and potential advertisers (if you are looking for that) will want to know the information.

Things you will need

  1. A self hosted WordPress website or blog (not wordpress.com)
  2. A Google Account

How to sign-up with Google Analytics

  1. Visit Google Analytics sign up page and create your account
  2. If you already have an gmail account, use it to sign in

How to add Google analytics image

  1. Once you sign-in, you will be directed to the Google Analytics Sign-up.  If you are not directed to the Sign up (see image below), go to the Google Analytics page and look on the upper right for links. You’ll get there ;-)

2-analytics-sign-up

  1. On the next screen, make sure the Website tab is selected

Add analytics to WordPress image

  1. Choose the Universal Analytics radial
  2. Enter your account and website name (any name of your choice), Web site’s URL, country, and the time zone, etc.….

4-enter-account-info

  1. Click Get Tracking ID button
  2. Accept the terms
  3. The code to paste in your site is generated

Wordpress Tips Image Google Analytics

  1. Select the entire snippet of tracking code. Copy/paste this code in word, notepad or a HTML editor (you will need it later).

Add Google Analytics to WordPress

You may add the Google Analytics tracking code to you site either manually or with a plugin.  I’m not a fan of unnecessary plugins because they slow down your site.

Solution 1: manual entry

Manually copy and paste the code into your theme’s footer.php file right before the </body> tag.

Note:  Other people recommend putting it in the header.php after the <body> or even before the </head> tag.  Each way has its merits and you can click to read a discussion about it.

However, the tracking code is designed to read data from your page after the content for the page has finished loading. For this reason, the snippet should be located just before the closing </body> tag for your web page.

  1. Log in to WordPress admin panel
  2. Go to Appearance > Editor (theme editor)
  3. Select the footer.php or index.php
  4. Find the </body> html tag
  5. Place your cursor immediately before the </body> tag
  6. Press enter to create an open line
  7. Copy/paste the Google Analytics code on the open line, before the </body> tag
  8. Click Update File to save changes.

It takes Google up to 12 – 24 hours to start providing you with the site stats.  To view your site’s statistics, log into your Google Analytics account.

The only problem with the manual installation is that if you update or change themes, you have to re-enter the code.

How to make sure your Google code is installed properly

  1. Log in to your Analytics account
  2. Click the Admin tab
  3. Select the appropriate account
  4. Select your web property
  5. Click the Tracking Info tab and then click Tracking code

If you see Status: Receiving Data you’re good.

If you see Status: Tracking Not Installed or something similar here are a few things you can do:

  • Wait a minute or two and refresh
  • Complete the process again making sure you are copying and pasting the entire snippet of code. Make sure you save after pasting.
  • If you have a cache plugin (like WP Super Cache or W3 Total Cache), empty the page cache.
  • Depending on the theme you are using, it may not have the default wp_head(); or wp_footer(); functions in place.

Solution 2:  use a plugin

I prefer the manual solution as I’m not a fan of unnecessary plugins.  But if you’re desperate, consider a plugin.

Add Google Analytics to WordPress with the Header-Footer plugin

  1. Download and install the Header-Footer plugin
  2. Go to Settings > Header-Footer
  3. Cut/paste the Google tracking code in the bottom footer textbox

Where do I find my UI tracking code ?

  1. Log in to Google Analytics at http://www.google.com/analytics.
  2. From the Overview page, select the appropriate account (the code is profile-specific).
  3. Select the profile from the accounts Overview page.
  4. From that profile’s Actions column, click Edit.
  5. At the top right of the ‘Main Website Profile Information’ box, click Check Status.
  6. Your tracking code can be copied and pasted from the text box in the Instructions for adding tracking section.

Did you find this post useful?

Please share it with your friends on twitter and Facebook using the social share buttons below.