How to Install Google Analytics on Your WordPress Site

Understanding your website visitors and how they use your website is crucial for your business. There are plenty of tools that allow you to do that. However, the most important one is probably Google Analytics. It allows you to see where your visitors are coming from, what they do on your site, which content is popular, and so on. In this article, I will show you how to install Google Analytics on your WordPress site.

Signing Up for a Google Analytics Account

First thing you need to do before installing Google Analytics is to sign up for the service. Google Analytics is available for free, all you need to do is to visit Google Analytics and sign up with your Google account.

Google Analytics Page

In the upper right hand corner there will either be two links to sign in or create a new account for gmail, or the button shown in the picture above to access Google Analytics. If you do not have a gmail account you will need to create one to use analytics. When you have signed in Google will take you to a page asking you to sign up for the service and you can either track a mobile app or a website so ensure you choose the correct tracking.

Google Analytics Signup

Should you choose, you can edit if you want your site to share data with different aspects of Google for services like technical support and account sprcialists. With the information on this page filled out I will be given a Google Analytics tracking code. This code is important as it will need to be added to my site in one of a few ways.

Installing Analytics

There are a few ways to add this code depending on how you want it to be added and how knowledgeable you are about WordPress.

Installing Google Analytics Code Using a WordPress Plugin

The easiest way to install Google Analytics tracking code on your WordPress site is by using a plugin. To do that you would need to install and activate Insert Header and Footer plugin. Upon activation, go to Settings » Insert Headers and Footers and place the code into the plugin’s settings.

Insert Header and Footer

Manually Adding Google Analytics Code in header.php

A slightly more complex way would be to open your theme’s header.php and place the code right after the <body> tag.

Please note that if you add the code to your main theme, then it will be overwritten whenever you update your theme. Using a child theme is the best way to add customizations like this to your WordPress site.

Manually Adding Google Analytics Code in functions.php

If you feel confident in your knowledge of php you can open your theme’s functions.php and add the following code replacing the fourth line with your Google analytics code.

add_action(‘wp_footer’, ‘add_googleanalytics’);
function add_googleanalytics() { ?>
// Paste your Google Analytics code here
<?php }

Using any of those methods you should have added Google Analytics to your site.

Please note, that you will not immediately start seeing information on your Google Analytics dashboard. It will Google Analytics 12 to 24 and sometimes even 48 hours before you can see any data in your Analytics account.

I hope this article helped you install Google Analytics on your WordPress site. Its a great way to optimize your website, plan your content, and grow your business.

If you liked this article, then join ThemeLab on Twitter and Google+.


About the editorial team

Editorial Team at IsItWp is a team of WordPress experts led by Syed Balkhi.