The Ultimate Google Analytics in WordPress Setup: How to Accurately Track Your Website Metrics

20/05/2023 2128 words 10 min. reading time

Google Analytics in WordPress (or GA) is the tool of choice for tracking and analyzing all kinds of numbers about your website’s visitors. The tool is so extensive and comprehensive that we can’t do without it.

In this article, we look at how to install GA in WordPress, both with a plugin and directly in the WordPress code.

If you do not want to work with Google (analytics), you can use alternatives like WP Search Insights.

What is Google Analytics? Google analytics and WordPress

Google Analytics is the reference par excellence when it comes to data of visitors to your website. As mentioned above, we can’t do without it anymore.

We all create content that we think is worth putting on our website. That might be a description of a service. Or maybe an informative post about a product you have on sale. Or just a short guide to using a product.

But is that content interesting? That, of course, is the key question.

With GA, we can answer that question. You can see which pages are the most popular, how long visitors to your website stay on a particular page, and whether those pages generate price requests.

So it’s not just a question of how many visitors. Through GA, you can also look at the quality of your visits.

In technical terms, we talk about bounce rate (the percentage of visitors that leave your website after 1 page), pages per session (the number of pages a visitor views per session), session duration (how long the session lasted), and returning visitors (the number of website visitors that still return to your website).

The above indicators mainly provide insight into the quality of visits.

At Mailbox, we mainly create action-oriented websites. Thereby, another parameter of GA is very important: the conversion rate.

This factor measures the percentage of visitors that show a desired behavior.

For example, if you have an e-book on your WordPress website, a conversion could be that someone downloaded the e-book. Suppose that out of 100 visitors, two people download the e-book; then the “conversion rate” (or conversion ratio) is 2%.

You can easily see the above factors in the numbers Google Analytics tracks. But how to install google analytics for WordPress?

How can WordPress bloggers use Google Analytics to gain insights into their audience demographics, interests, and behavior?

  • Set up Goals: Define goals in Google Analytics to track specific actions on your WordPress blog, such as newsletter sign-ups, content downloads, or purchases. Goals provide insights into user behavior and conversion rates.
  • Enable Demographics and Interests Reports: In Google Analytics, navigate to the “Admin” section, select your website’s property, and go to the “Tracking Info” tab. Enable the “Demographics and Interests Reports” to gain access to data about your audience’s age, gender, and interests.
  • Analyze Audience Overview: In the Google Analytics dashboard, go to “Audience” > “Overview” to get a snapshot of your blog’s audience. Explore metrics like sessions, users, pageviews, and average session duration to understand general user behavior.
  • Explore Demographics: Under the “Audience” section, click “Demographics” to access detailed information about your audience’s age and gender. This data can help you tailor your content and marketing efforts to better resonate with your target demographic.
  • Discover Interests: In the “Audience” section, select “Interests” to gain insights into your audience’s affinities and categories they are interested in. This information can help you identify popular topics and create content that aligns with your readers’ interests.
  • Use Behavior Reports: Navigate to the “Behavior” section to understand how users interact with your WordPress blog. Analyze metrics like pageviews, bounce rate, and average time on page to identify popular content and areas for improvement.
  • Implement Custom Dimensions: Use the Google Analytics custom dimensions feature to collect additional data for your WordPress blog. For instance, you can track user engagement by defining custom dimensions for comments, social shares, or user-generated content.
  • Create Segments: Create segments in Google Analytics to compare different groups of users based on specific criteria. For example, you can create segments for new visitors, returning visitors, or users from different locations to understand their behavior and preferences.

GA4 or Google Analytics4

Google Analytics 4 (GA4) is the latest version of Google’s web analytics platform. It is designed to give businesses a more comprehensive and holistic view of user interactions across various digital channels. GA4 utilizes an event-based data model, allowing businesses to track and analyze user behavior and engagement across websites, mobile apps, and other digital platforms.

It offers advanced features such as machine learning-driven insights, cross-device tracking, and enhanced privacy controls. GA4 provides businesses with valuable data and insights to optimize their marketing strategies, improve user experiences, and drive better business outcomes in the evolving digital landscape.

google analytics4 (ga4)
The Ultimate Google Analytics in WordPress Setup: How to Accurately Track Your Website Metrics

Another crucial aspect of GA4 is privacy. With increasing concerns around data privacy and regulations like GDPR and CCPA, GA4 offers enhanced privacy controls and anonymization features. It ensures that businesses can collect and analyze data while respecting user privacy preferences and complying with data protection regulations.

How to add google analytics to WordPress without a plugin

How to set up google analytics on WordPress?

Of course, step 1 is always to open a Google Analytics account first. You can do that for free if you register a new or existing Google (Gmail) account.

Through the interface of GA, you get enough possibilities to install a little javascript on any website that tracks your visitors. And then forwards the data to Google’s database.

Caution. We only track visitors anonymously. You get general profile data but no personal data.

You click “Administrator” at the bottom of your GA account (if you create a GA account, you’re already automatically on this page).

Here are four reasons why you should consider adding Google Analytics to your WordPress site:

  • Gain insight into your audience.
  • Optimize your marketing strategies.
  • Monitor the quality of your site’s content.

Because GA allows you to see which pages and links get the most visitors, you can create better content to meet your audience’s and target audiences’ needs and preferences.

google analytics wordpress tracking code
The Ultimate Google Analytics in WordPress Setup: How to Accurately Track Your Website Metrics

As you can see from the image above, you can integrate the tracking code in different ways on your website :

  • You can embed that javascript on EVERY page of your website
  • Or you can use Google tag manager (but that’s not that simple !!!).
  • If you have a webmaster, you can send this information via email. He or she will then implement that code.

If everything goes well, 5 minutes later, you will have access to your statistical data.

However, installing this tracking code is very easy in WordPress. You don’t need any programming knowledge. We do this the WordPress way: via a plugin.

Google analytics WordPress plugins: how to use them

If you search for “google analytics” on wordpress.org, you will see plenty of choices to find an excellent plugin.

Remember: to find a good plugin, it’s best to check if it has been updated recently. That is often an indication of a plugin’s quality. In addition, users of WordPress plugins can also give so-called “ratings.” Or “asterisks,” if you will. These also give a good indication of the quality of a plugin.

A plugin we have used for years is “go google analytics.” Not because of the many bells and whistles. But just because it is a decent plugin that and easy to use.

GA Google Analytics

After installing the plugin, look for the specific plugin menu of this plugin. It is located after installation in “settings > google analytics.”

The nice thing about this plugin is that you must enter 1 code to be “up and running,” namely the “tracking id.”

That code is structured as follows: UA-000000-0 and should be perfectly recognizable in the GA interface (copy-paste). For GA4 (Google Analytics 4), the workflow is exactly the same: During account creation, you’ll get a tracking (measurement) ID; add this tracking ID to the plugin setting, “GA Tracking ID.” and
select “Google Tag” for the plugin setting, “Tracking Method,” and you are ready.

Save changes and done. Wait 24-48 hours before viewing the collected data in your GA account.

Verifying that Google Analytics is working

Once you think GA is properly installed, it is also time to take a moment to test whether everything is working properly. You can easily do that by going to the “Realtime” menu item in GA and seeing if anyone (you can also test yourself) is on the website. Real-time Google Analytics is really fun to watch. 👍

google analytics real-time visitors
The Ultimate Google Analytics in WordPress Setup: How to Accurately Track Your Website Metrics

WordPress Google analytics plugins

The best google analytics WordPress plugin?

By time-honored custom, dozens of plugins do the same thing as the “ga google analytics” plugin.

Again, I refer to this page: Google analytics.

And as you can see, dozens of plugins will allow you to integrate GA into your WordPress backend.

Some plugins will show basic statistics imported directly from GA on your WordPress dashboard. Now that may be a good idea to view those basic statistics every time you log into WordPress.

However, these plugins use quite a bit of memory. And these plugins might slow down your website.

That is why we prefer the “GA Google Analytics” plugin. It has few bells and whistles. But it also uses less memory which is good for the speed of your WordPress site.

Here are some GA plugins you can use:

How to install Google Analytics without a plugin

Now I hear some people saying you can install a plugin for everything. And that’s true, of course. Some people will install too many WordPress plugins.

If you’re not careful, you’ll already have a dozen additional WordPress plugins installed after a few weeks. We’ve already seen websites with more than 80 (!!!) plugins.

Of course, this will affect your website’s speed, especially if you have a cheap shared hosting account.

Hence, many choose to integrate the Google Analytics code directly into the templates of your WordPress theme.

And, of course, this is technically a bit more difficult but the most efficient solution (since you don’t need an additional plugin).

Step 1 : Log in to Google Analytics and copy the tracking id
Step 2 : Install a child theme
Step 3 : Copy the following in the functions.php file (see PHP code)
Step 4: replace the tracking id with your real tracking id
Step 5: save the changes in the functions.php file
Step 6: check in the live view of google analytics that your tracking code is working !!!

The PHP code

add_action('wp_head','my_analytics', 20);
function my_analytics() {
?>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id='UA-00000000-1'"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'UA-00000000-1');
</script>
<?php

Of course, you can also install the code directly using the “native WordPress” script enqueuing. That means you use the standard way of integrating scripts into WordPress instead of placing the code in the website’s PHP code.

For this, you can use a nice plugin called “Custom CSS and JS” that you can install for free. This allows you to add a custom script to your website without changing the PHP code.

Simple custom CSS and js

Google Site Kit: a special mention

Site Kit is Google’s official WordPress plugin to get more insights into how people find and use your site.

Site Kit is the one-stop solution for implementing, managing, and gaining insights from key Google tools to make the site successful on the web. It provides authoritative, up-to-date insights from multiple Google products on your WordPress site dashboard.

The Site Kit includes powerful features :

  • Easy-to-understand statistics directly on your WordPress dashboard
  • Authoritative statistics from multiple Google tools, all in one dashboard
  • Quick setup for multiple Google tools without having to edit your site’s source code
  • Data for your entire site and individual posts

Monsterinsights plugin

MonsterInsights is a popular WordPress plugin that provides website owners with valuable insights and analytics about their performance. With over 2 million active installations, it has become a go-to tool for WordPress users seeking a deeper understanding of their website’s traffic, user behavior, and more. There is a free and a pro version.

Monsterinsights plugin

The plugin offers a user-friendly dashboard within the WordPress admin area, allowing website owners to conveniently view their analytics data without leaving their website. This intuitive interface makes tracking key metrics, monitoring audience behavior, and identifying trends over time easy.

MonsterInsights also provides powerful features that go beyond basic analytics. For instance, it enables enhanced eCommerce tracking, which allows online store owners to monitor their sales, revenue, and conversion rates effectively. This information helps them make data-driven decisions to optimize their marketing strategies and improve their online business.

Another noteworthy feature is its integration with popular WordPress forms plugins, such as WPForms and Gravity Forms. This integration enables tracking of form submissions, allowing website owners to measure the effectiveness of their lead generation and user engagement efforts.

FAQ

Can I use google analytics with WordPress

Yes, you can use Google Analytics with WordPress. In fact, it is a widely used and recommended practice to track and analyze website data. There are a few different methods to integrate Google Analytics with a WordPress website (see above)

Is Google Analytics free on WordPress?

Yes, Google Analytics is free to use on WordPress. You can create a Google Analytics account and integrate it with your WordPress website without incurring any charges.

Table of Contents