How to Add Google Analytics to WordPress

How to Add Google Analytics to WordPress

Posted June 25, 2019 by Lee

Google Analytics is one of the most useful tools that any website owner can have in their arsenal. It allows you to collect and analyse all kinds of data about your visitors, including where they came from, what they searched for, and which pages they browsed in which order.

You can use this information to optimise your website, create a sales funnel that works, and to continuously improve the way your website works. But to do all of that, you first have to connect Google Analytics with your website to start collecting the data.

Here’s how to do that with WordPress – whether you want to use a plugin, or do it manually.

Using a plugin

Using a plugin can make it very easy to set up your Google Analytics. There are a number of plugins out there, the most popular of which is MonsterInsights. It’s used by over one million sites, so you can be sure that it is one of the best options out there.

Whether you’re an expert or a beginner, you can use this plugin to get Analytics up and running. There is both a free and a premium version, but the process of setting them up is the same either way.

First, install MonsterInsights on your WordPress site as a plugin. When you have done this, you will see a menu item labelled ‘Insights’ appearing that wasn’t there before. Click on it, and you will launch the setup wizard, which will guide you through the whole process.

This should guide you through everything, including when and where to put in your Google Analytics key. You can set up a few different settings if you like, so make sure to go through everything carefully.

When you have it all set up, you will be able to access the same tab in order to view your reports, which is a lot easier than going off-site.

Using code snippets

If you want to access your Google Analytics reports through Google’s own dashboard after adding the link manually, you can do this by adding a snippet of code to your theme’s files. This is a more complex method as you can easily destroy the code of your site, and it can also be deleted if you update your theme later, so it’s not as recommended.

Go into your WordPress theme’s manual code editing interface and find the header.php file. Go ahead and paste the code from Google Analytics (which you can find by following the steps to connect your account) into this file, right after the <body> tag.

Save the changes and reupload the file to your server so that everything is live on your site.

Another way to do this is through your WordPress functions file. The advantage here is that the tracker will be added to every page of your site automatically.

Paste this code into the functions.php file on your theme:


add_action('wp_head', 'wpb_add_googleanalytics');

function wpb_add_googleanalytics() { ?>

// Paste your Google Analytics code here

<?php } ?>

This will then allow you to view your reports.

Viewing data

No matter which method you use, it will take a short while for WordPress to update Google with your data, and more time still for useful data to be returned.

Once everything is up and running, you can always view data from your Google Analytics dashboard. This can be very interesting and potentially sales-boosting!

It’s easy enough to add Google Analytics to WordPress, even if you don’t know what you are doing with code. There’s always a useful plugin that will do the job for you.


Categories: WordPress

About The Author

Lee is a Website Developer at Unlimited Web Hosting UK Limited.

You may also like...