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:
- 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.
- 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.
Steps to collect data using Google Analytics:
Access the Google Analytics website and login using a previously created Gmail or Google account. Once logged in, select the "Create Account" button.
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.
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".
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.
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.
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.
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.
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.
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.
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.
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!
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.