Add Google Analytics to your WordPress Website (with GeneratePress)


Learning about the users who visit your website is an incredibly important aspect of running a website/blog. By connecting Google Analytics to your WordPress site, you can learn how many visitors you get, how they get your website, how long they spend on each page and much much more. Let's look at why you want to avoid using Google Analytics plugins, and how you can connect your WordPress website, (specifically one built with GeneratePress), to your Google Analytics account so that you can start collecting valuable data.

Why not to use a Google Analytics Plugins

There are many plugins that you can install on your WordPress website that will connect your website to Google Analytics, but I advise against that for 2 main reasons:

  1. Plugin security issues - badly coded plugins are one of the main sources of WordPress website hacks and security issues. You don't usually know what's going on in the background of a plugin, and you have to trust the creators to keep them up-to-date. The more plugins you can avoid, the more secure your website will be.
  2. Speed issues - the more plugins you have installed, the more bloat your WordPress website will have and the slower that it will load for your users. Again, keeping plug-ins to a minimum is the best approach.

Luckily, Google Analytics is easy to connect to your site, and inject a small peice of code that will start collecting data.

How to Connect Google Analytics to your WordPress site

As per my previous guides, we'll now look step-by-step how to register a new Google Analytics account and connect it to your WordPress website. This guide follows along if you have built your site using the GeneratePress theme, but can be used for any site built with WordPress.

Connect Google Analytics to your Website Banner

Steps to collect data using Google Analytics:

Step 1 : Create a new Google Analytics account

Access the Google Analytics website and login using a previously created Gmail or Google account. Once logged in, select the "Create Account" button.

1 - Login to Google anayltics
Step 2 : Fill in the Account details

Provide an account name (usually the name of the site you are tracking data for) and review the Data Sharing Settings. I usually allow all of the data sharing, but it's up to you. Now click the "Next" button at the bottom.

2 - Create a new account
Step 3 : Select the type of application you want to measure

There are three different types of accounts you can measure. If you are only working with a WordPress website, that doesn't have associated apps, then you can stick with the "Web" option. Select web, then click "Next".

3 - Select your account type for your Google Anayltics account
Step 4: Fill in your property details

The Property details include your specific website name and URL. Fill these out and update the industry category and reporting time zone. For industry category, it can be hard to find an exact match, so just do the best you can.

4 - Input your property details
Step 5: Accept the terms of service

Make sure that you review the terms of service. It's always good to know what you are actually agreeing to share and adhere to.

5 - Accept the terms of service
Step 6: Copy your Google Analytics tracking code

Now that your Google Analytics account has been created, you will now be provided your tracking code. This is code that you can put on your website that will then send the necessary data from your website to Google Analytics so that GA can track your users and the important data you need to know to better understand your website. Copy this snippet and put it in a textpad document.

6 - Copy your Google Analytics Tracking code
Step 7: Access your WordPress website

Now that you've got your GA code snippet, it's time to find where to put it on your website. Again the following steps assume that you have built your website with a GeneratePress theme. If you haven't, you can still add the GA code snippet, but it will depend on the theme you have. You can also install plugins such as the "Insert Headers and Footers" plugin, which will allow you to add the code snippet across the site.

Continuing as if you have GeneratePress installed, login to your WordPress admin, go to the Appearance menu, select Elements, and then click Add New Element.

7 - Login to your WordPress dashboard
Step 8: Add a new Hook

A Hook is a snippet of code that can be injected into various places on your WordPress website. Select Hook as your element type, and click Create.

8 - In the GeneratePress Elements menu, add a new element
Step 9: Paste your Google Analytics code snippet

Name your new hook something related to Google Analytics so that you can find it easily in the future. You can now copy the snippet of code that Google Analytics provided you, and put it into the code area for your new hook.

9 - Paste your google analytics trakcing code
Step 10: Applying the Hook across your website

In the Display Rules menu, select Entire Site for the location of the hook. This means that Google Analytics will be able to collect data form every page on your website. Then, make sure you click the Publish button on the right.

10 - Display code across the entire site
Step 11: Test your website

Google Analytics has now been installed on your website. To make sure that it's working properly, logout of your WordPress website (being logged in as admin can affect your Google Analytics, as tracking admin users is not helpful). Access your website on a browser, and open the Google Analytics website. Select the Real Time report, and you should see yourself as the active user!

11 - Testing Google Analytics on your GeneratePress website

Google Analytics Successfully Installed on your GeneratePress Website!

And as easy as that, you are now collecting data for your WordPress website built with the GeneratePress theme. Knowing how many people access your website, which pages are the most popular, how users access your website is incredibly important in planning future content that will resonate with your users! Future guides will also show how to expand upon this, and track important events that users participate with on your website.

This site may contain affiliate links to products talked about. I only recommend products and tools that I use myself and that were used in the creation of this website and other websites that I have built.

Leave a Comment