Google Analytics is one of the most useful tools any website owner can have. It lets you collect and analyse data about your visitors, including where they came from, what they searched for, and which pages they browsed in which order.
You can use that information to improve how your website performs, build a sales funnel that actually works, and spot what is and is not connecting with your audience. Before any of that is possible, though, you need to connect Google Analytics to your WordPress site. There are two ways to do it: with a plugin, or by editing your theme files directly.
A plugin is the most reliable route for most WordPress users. The most widely used option is MonsterInsights, which is active on over one million sites. It has a free tier and a premium tier, and the setup process is the same for both.
Install MonsterInsights from the WordPress plugin directory as you would any other plugin. Once it is active, a new menu item labelled Insights will appear in your WordPress dashboard. Click it to launch the setup wizard, which walks you through connecting your Google Analytics account, entering your tracking key, and configuring your preferences.
After setup, the same Insights menu gives you access to your reports directly inside WordPress, without needing to visit the Google Analytics dashboard separately. For most site owners, this is the preferred way to work.
If you would rather not use a plugin, you can add the Google Analytics tracking code directly to your theme files. This method requires a little more care. Editing theme files incorrectly can break your site, and if you update your theme later, any changes you made to those files may be overwritten.
Open your theme’s file editor in WordPress and locate the header.php file. Paste the tracking code you copied from Google Analytics immediately after the opening <body> tag. Save the file and, if you are editing locally, re-upload it to your server.
Tip: If your theme receives updates, edits to header.php will be overwritten. Consider using a child theme to protect your changes, or use the functions.php method below.
A more durable approach is to add the tracking code through your theme’s functions.php file. This hooks the code into every page on your site automatically, without touching header.php.
Paste the following into functions.php, replacing the comment with your actual Google Analytics tracking code:
<?php
add_action('wp_head', 'wpb_add_googleanalytics');
function wpb_add_googleanalytics() { ?>
// Paste your Google Analytics code here
<?php } ?>
Once saved, the tracker will load on every page of your site without any further configuration.
Whichever method you use, there will be a short delay before data starts appearing. Google Analytics needs time to receive information from your site, and a little more time before patterns become meaningful. Do not be concerned if the dashboard looks sparse in the first day or two.
Once data is flowing, you can view it either through the Google Analytics dashboard or, if you used MonsterInsights, directly inside WordPress under the Insights menu. Either way, you will start to see which pages attract the most visitors, where your traffic originates, and how people move through your site.
That information is worth having. Knowing what your visitors actually do on your site is far more useful than guessing, and it gives you something concrete to act on when you are deciding where to focus your efforts next.
If you are running WordPress and want a hosting environment that keeps pace with your site as it grows, take a look at our WordPress hosting plans. For questions about your setup, the UWH support team is available to help.
Lee heads Marketing, SEO, and Web Development at Unlimited Web Hosting UK, with over 17 years of industry experience.
Related articles you might find interesting.
Get fast, secure and reliable WordPress Hosting with optimised for performance with AccelerateWP.
Get WordPress HostingCreate fully isolated individual accounts for your clients and manage them all from one dashboard.
Get Reseller Hosting