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
- A self hosted WordPress website or blog (not wordpress.com)
- A Google Account
How to sign-up with Google Analytics
- Visit Google Analytics sign up page and create your account
- If you already have an gmail account, use it to sign in
- 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 ;-)
- On the next screen, make sure the Website tab is selected
- Choose the Universal Analytics radial
- Enter your account and website name (any name of your choice), Web site’s URL, country, and the time zone, etc.….
- Click Get Tracking ID button
- Accept the terms
- The code to paste in your site is generated
- 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.
- Log in to WordPress admin panel
- Go to Appearance > Editor (theme editor)
- Select the footer.php or index.php
- Find the </body> html tag
- Place your cursor immediately before the </body> tag
- Press enter to create an open line
- Copy/paste the Google Analytics code on the open line, before the </body> tag
- 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
- Log in to your Analytics account
- Click the Admin tab
- Select the appropriate account
- Select your web property
- 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
- Download and install the Header-Footer plugin
- Go to Settings > Header-Footer
- Cut/paste the Google tracking code in the bottom footer textbox
Where do I find my UI tracking code ?
- Log in to Google Analytics at http://www.google.com/analytics.
- From the Overview page, select the appropriate account (the code is profile-specific).
- Select the profile from the accounts Overview page.
- From that profile’s Actions column, click Edit.
- At the top right of the ‘Main Website Profile Information’ box, click Check Status.
- 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.