X

How to Add Google Analytics to WordPress (With & Without a Plugin)

Do you want to add Google Analytics to your WordPress site?

Adding Google Analytics to your WordPress website is the best way to track how your visitors are interacting with your site. In this article, we’ll show you how to install Google Analytics on your WordPress site in 2 simple steps.

Before we jump into installing Google Analytics in your WordPress site, we should mention that by July 2023, Google Analytics is retiring Universal Analytics which is what this guide is all about. If you want to set up Google Analytics 4, follow our guide: How to Set Up Google Analytics 4 in WordPress.

If you still want to set up Universal Analytics, first, let’s examine what Google Analytics is, why it’s important, and how it works.

If you’d rather cut straight to the chase then go ahead and dive into the step-by-step Analytics installation process.

Google Analytics for WordPress – The Complete Set Up Guide

Take a look at the table of contents…

What Is Google Analytics?

google analytics for WordPress

Google Analytics is the most comprehensive tracking tool for your website that allows you to see where your visitors are coming from, what they do on your site, which content is popular, and so on.

It gives you a better understanding of your marketing impacts by providing easy-to-understand stats. Whether you’re a publisher, small business owner, or an eCommerce merchant, Google Analytics provides you with everything you need to know about your visitors.

Aside from basic visitor engagement stats, some of the Google Analytics tracking features you’ll find useful are:

  • Ads tracking
  • Enhanced eCommerce tracking
  • Events tracking
  • Online forms tracking
  • And a lot more

Why Use Google Analytics in WordPress?

Understanding your website visitors is the key to growing your traffic, subscribers, and revenue. By installing Google Analytics on your WordPress site, you can gather all your website data, which provides actionable insights to grow your business. That way, you can eliminate guesswork and start making informed decisions based on the data you’ve gathered.

Also check: Alternatives to Google Analytics.

Below are a few benefits of tracking your website visitors using Google Analytics:

Get to Know More About Your WordPress Visitors in Analytics

google analytics wordpress dashboard

You can collect and track visitor information such as geographical location, demographics and interests, devices and browsers they used while viewing your site, and a lot more. This data help you better understand your audience, so you can better craft your marketing messages in a way that best resonates with them. But make sure you are displaying data collection disclaimer as per GDPR rules. This can be easily displayed by using WordPress GDPR plugins.

For example, if you find that most of your website visitors are females based in the US, you can curate content addressing the needs of that specific user base.

Understand How Visitors Interact with Your WordPress Website

google analytics report

You can also track details like what your visitors do while they are on your website, how long they stay on your site, etc. With the help of this data, you can come up with strategies to make them more engaged, keep them longer, and even convince them to make purchases on your site.

Understand Where Your Site Visitors Arrive From

google analytics wordpress traffic source

Google Analytics gives you the breakdown of different traffic sources such as search engines, social, referrals, direct traffic, etc. By analyzing your traffic sources, you can understand which source contributes the most visitors to your site.

It can also give you insights into how to increase your website visitors.

For example, if your top referral source is an external website, then you might want to consider having a partnership with that website such as submitting guest posts.

How Does Google Analytics Work?

To be able to track your visitors’ data, you’ll need to implement a piece of tracking code on your website that you obtain from your Analytics account. The tracking code must be added on every page on your website. This can be done by adding the code right into the header section of WordPress.

Whenever someone arrives at your site, they are tagged by the tracking code in their browser and then their session on your website begins.

Installing Google Analytics on your WordPress website is pretty easy. All you have to do is install a Google Analytics plugin, such as MonsterInsights, and configure it with Analytics. Alternatively, you can manually add the tracking code on your site but the downside is that it will limit your ability to enable enhanced Google Analytics tracking features.

In this article, we’ll explain how to add Google Analytics tracking to WordPress both via MonsterInsights and manual methods.

How Do I Use Google Analytics in WordPress? (Step-by-Step Guide)

Let’s take a look at how to set up Analytics on your site, step by step. We’ll also explain how to set up Analytics with and without using a WordPress plugin.

Step 1: Sign Up for a Google Analytics Account

The first thing you need to do before installing Google Analytics is to sign up for the service. Google Analytics is available for free, so all you need to do is to visit Google Analytics and sign up with your Google account.

In the upper right-hand corner, you can click on Sign in to Analytics or Start for free.

sign into google

This will direct you to a page where you’ll be asked to sign in with your Google Analytics account or sign up for a new Google Account.

sign into analytics

After you’ve signed into your Google account, you’ll need to sign up for Google Analytics. Click the Start measuring button on the next screen to get started.

click start measuring

Next, you’ll need to enter the settings for the site you want to start tracking. Make sure the Website option is selected at the top.

GA track website

After that, enter in an account name for your Google Analytics account and make sure to check all of the boxes in the Account Data Sharing Settings section.

data sharing settings

Now you need to add the property details of your website like the name, reporting time zone, and currency.

When you’re finished, click on Show advanced options.

add property details and click show advanced options

Then, enable the Create a Universal Analytics property option.

enable create universal analytics property

Now, enter the URL of your website and be sure to select the Create a Universal Analytics property only option. This ensures that you’re able to use other tracking platforms and measure ad performance accurately.

create a universal analytics property only

In the next step, enter in your business information such as the industry and the size of your company, and check all of the ways you intend to use Google Analytics for your business.

business information google analytics

When you’re finished, click the Create button.

In the popup window that appears, you can review and accept the terms of service.

accept google analytics terms of service

After accepting the terms, you’ll be taken to a screen where you can see your Tracking ID and tracking code. Make a copy of these because you’ll need them later.

google analytics tracking code and tracking id

That’s it! You’re now signed up for Google Analytics.

Step 2: Add Google Analytics to WordPress

Now that you’ve signed up for Google Analytics, the next thing you need to do is to add Analytics to your WordPress site. There are many ways to add Google Analytics to WordPress. Let’s take a look at them below:

  1. Install Google Analytics on your site using MonsterInsights (Recommended)
  2. Add the raw tracking code to your WordPress site’s header with a plugin
  3. Manually add the tracking code in header.php
  4. Manually add the tracking code in functions.php

MonsterInsights vs. Manual Installation of Google Analytics in WordPress

Before we dive into the Google Analytics installation process, it’s worth taking a moment to examine why using the MonsterInsights plugin is recommended over manual Analytics installation.

For some users, installing Google Analytics might seem like a “no brainer” task. For that reason, they manually add Analytics tracking code to their site without using any plugins.

While manually installing Google Analytics allows you to gather basic traffic stats like sessions, pageviews, bounce rate, etc., the downside is that it doesn’t allow you to leverage the full potential of Google Analytics.

For example, if you need to make use of more Analytics tracking features like download tracking, link tracking, forms tracking, eCommerce, tracking, and more, you’ll have to manually customize the code for every instance. Without a doubt, this can be tedious especially if you’re not a developer or an Analytics expert.

Chances are, even a slight mistake can skew your entire Analytics tracking, meaning you get incorrect data from your Analytics account, which will lead you to make wrong decisions for your business.

monsterinsights

On the other hand, MonsterInsights makes it super easy to install Analytics with just a few clicks. MonsterInsights is the most popular Google Analytics plugin for WordPress in existence. To enable enhanced tracking features, all you have to do is to make a few clicks or install the respective addons.

As you’d never need to touch a single line of code, it saves your precious time during the entire installation process.

Get started with MonsterInsights today to easily set up Google Analytics on your site.

Want to start with the free version instead? Try MonsterInsights Lite.

Method #1. Adding Google Analytics to Your Site Using MonsterInsights (Recommended)

To set up Google Analytics on your site, subscribe to a MonsterInsights plan and download the plugin. If you’d rather start with the free plugin, head over to Plugins » Add New. Search for MonsterInsights and, when the plugin shows up, click Install Now and then, Activate.

install monsterinsights in wordpress

Head over to Insights » Settings to authenticate your blog with Google Analytics. Click the Connect MonsterInsights button.

connect monsterinsights

On the next screen, select your Google account.

choose a google account for analytics

Next, allow MonsterInsights to manage your account.

monsterinsights to manage analytics in wordpress

Finally, select the correct website profile for your blog and click Complete Connection.

choose the website profile for monsterinsights

After authentication, you can easily find how your website is doing by visiting Insights » Reports.

wordpress google analytics with monsterinsights

If you have both a Universal Analytics property and a Google Analytics 4 (GA4) property, you can also set up dual tracking with MonsterInsights.

This lets you keep your historical data and reports from Universal Analytics and get the benefits of the new GA4 features at the same time.

To set up dual tracking, go to the main Settings page in MonsterInsights. Scroll down to the Google Authentication section and find the Dual Tracking Profile box. Here, you can input either your Universal Analytics Tracking ID or your GA4 Measurement ID, whichever one you didn’t authenticate in the initial setup.

dual tracking for universal analytics and google analytics 4

Follow our complete guide here: How to Set Up Google Analytics 4 in WordPress.

Method #2. Add Google Analytics Code to WordPress Header With a Plugin

You can add the raw tracking code to your site’s header with the Insert Headers and Footers plugin. After installing and activating the plugin, go to Settings » Insert Headers and Footers and place the code into the plugin’s settings.

insert headers and footers

3. Manually Add Google Analytics Code to WordPress in header.php

add google analytics tracking code to header.php

A slightly more complex way would be to open your theme’s header.php and place the code right after the <body> tag.

google analytics tracking code added

Please note that if you add the code to your main theme, then it will be overwritten whenever you update your theme. Using a child theme is the best way to add customizations like this to your WordPress site.

4. Manually Add Google Analytics Code to WordPress in functions.php

If you feel confident in your knowledge of php you can open your theme’s functions.php and add the following code. Make sure you replace the fourth line with your Google analytics code.

&amp;amp;lt;?php
add_action('wp_footer', 'add_googleanalytics');
function add_googleanalytics() { ?&amp;amp;gt;
// Paste your Google Analytics code here
&amp;amp;lt;?php }
?&amp;amp;gt;

Using any of those methods you should have added Google Analytics to your site.

Google Analytics in WordPress: FAQs

Here are a few frequently asked questions regarding setting up Google Analytics in WordPress.

How long does it take Google Analytics in WordPress to start working?

After the installation, you might not immediately start seeing information on your Google Analytics dashboard. It will take about 12 to 24 hours (or sometimes even 48 hours) before you can see any data in your Analytics account.

How do I know if Google Analytics is working on my WordPress site?

To verify Google Analytics tracking, you’ll need to look at the source code of your website.

Use a keyboard shortcut to view the source code of your site. If you’re on Windows or Linux, press Ctrl + U to view the source code. If you’re on Mac, press Command + U.

Here’s how Google Analytics tracking code looks like:

google analytics tracking code

Bear in mind that if you’re using MonsterInsights for Analytics setup, you’ll need to turn on the incognito mode (private browsing) in your browser to see the tracking code. That’s due to the fact that MonsterInsights doesn’t track your own visits to avoid skewing your Google Analytics data.

What is the best Google Analytics plugin for WordPress?

With over 2 million active installs, MonsterInsights is the most popular and comprehensive Google Analytics plugin for WordPress. Not only does it make Analytics setup easy, but it also lets you enable a lot of Analytics tracking features such as eCommerce tracking, downloads tracking, etc. without touching a single line of code.

We hope this article helped you install Google Analytics on your WordPress site. It’s a great way to optimize your website, plan your content, and grow your business.

If you liked this article, you might also read our other posts:

These posts will help you further explore your website’s data.

Comments  Leave a Reply

  1. Hi there,

    When I test my sites with Google PageSpeed I see that the analytics and google search console data consumes resources.

    What is the best way to collect data to Analytics and GSC without making the site slower?

  2. Hi, thank you for the post. Just tried to add the GA code manually to my GeneratePress free theme and got an error message. The editor won’t let me save the file.

    This is the functions.php file of my child theme before pasting the code:

    <?php
    /**
    * GeneratePress child theme functions and definitions.
    */

    function generatepress_child_enqueue_scripts() {
    if ( is_rtl() ) {
    wp_enqueue_style( 'generatepress-rtl', trailingslashit( get_template_directory_uri() ) . 'rtl.css' );
    }
    }
    add_action( 'wp_enqueue_scripts', 'generatepress_child_enqueue_scripts', 100 );

    Is there something I'm missing?

    Many thanks,
    JM

  3. I use Google Analyticator. You just connect the site to your Google Account, select the Analytics Profile and it does the rest for you, including embedding a graph of your visitors into your Dashboard. Brilliant!

    1. Hi,

      Google Analyticator looks good. I want to try.

  4. Hey Jeremy

    Nice tutorial! You could also use Yoast’s “Google Analytics for WordPress” plugin. It supports most of GA’s features and it’s pretty easy to set up.

    – Andor Nagy

    1. Shahzad Saeed May 17, 2018 at 9:54 am

      The ‘Google Analytics for WordPress’ plugin is now rebranded as MonsterInsights.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!