WPLift is supported by its audience. When you purchase through links on our site, we may earn an affiliate commission.

How to Add Google Analytics to WordPress (2021)

Last Updated on July 8th, 2021

Tags: , , ,

Are you having a hard time looking for a quick and easy way to add Google Analytics to your WordPress website? Some individuals are afraid of the phrase analytics, but it doesn’t have to be! Google Analytics is one of the most effective tools for collecting information about your website’s visitors.

Don’t be afraid of Google Analytics if you’ve ever been scared by it. We’ll be there to assist you every step of the way. We’ll look at Google Analytics and its advantages in this post. Then we’ll go through different ways on how to add google analytics to your WordPress site, including ways that don’t require any coding. Let’s get started!

What is Google Analytics?

Google Analytics is a web analytics software that you can use to track and evaluate your website or app’s performance. Google Analytics gives you access to a wealth of information and statistics on website traffic and visitor behavior. Anyone with a Google account may use the platform, which comes in both premium and free versions.

How Does Google Analytics Work?

You’ll need to add a piece of JavaScript code to your website’s pages if you want to track it with Google Analytics. 

When a visitor views a website containing this code snippet, the code begins monitoring data and sending it to Google Analytics using a JavaScript file. 

Google Analytics will fill the reports inside GA after it has collected enough data from your site.

Why Do You Need to Add Google Analytics to Your WordPress Site

Google Analytics provides data on user activity that might be extremely useful to your company. You should use Google Analytics for a variety of reasons. 

Here are a few of its advantages: 

Analyze User Behavior

Knowing as much information as possible about your audience can help you better understand how to service and target them.

As a result, Google Analytics offers statistics such as the number of visitors to your website, the number of sessions each user completes, the number of pages users see each session, and the average session time.

Article Continues Below

The audience page also includes graphs that show the ratio of new vs returning visitors to your site, as well as how traffic varies over time. 

Google Analytics also includes audience demographics to assist you to learn more about your website’s visitors.

These broad, surface-level demographics are valuable, but Google Analytics also provides statistics on the lifetime value of your users, cohort analysis, and other capabilities that may help you understand even more about your audience.

You can also look into your audience’s interests, their activity on your site (which includes things like interaction), what sort of mobile device they use, and more using the audience tab.

Help You Improve Your Online Advertising

You must know how your advertisements work on your target website to be effective in online advertising, and having Google Analytics installed before pursuing online marketing is critical. 

Individual campaigns and their links may be tracked in GA to monitor how your advertisements work in real-time. 

You can observe that one campaign performs better on the website using Google Analytics, and you can now adjust your other efforts to match the higher-performing campaign.

Maintain a high standard of content

If content marketing is a component of your plan, you know how difficult it can be to figure out what material resonates with your target audience. When you develop content that people like, you need to know exactly how well it worked and why it succeeded so you can keep the momentum going. It’s simple thanks to analytics: just check which of your pages receives the most traffic, conversions, and outcomes. This provides you a decent sense of what people find useful, and you can plan what material you’ll generate or change to keep your audience interested.

Cost of Google Analytics

The most important advantage of Google Analytics is that it is free to use for businesses, and every website can have its own account if necessary. Because Google Analytics is completely free. Because it’s simple to set up, it won’t take much time, lowering the cost of Google Analytics even further.

How to Sign Up for Google Analytics

Google Analytics is a completely free service. To sign up, all you need is a Google or Gmail account.

Article Continues Below

  • The first step is to register for a Google Analytics account. If you already have a Google account, you’re already going ahead to the next step. When you sign in using your Gmail account, you’ll get a screen similar to the one below. With your Gmail account, you’ll sign up for Google Analytics here.
how to add Google Analytics to WordPress
  • After that, you’ll be prompted to choose a username for your account. This name will only be used internally, therefore it may be anything similar to your company name.
how to add Google Analytics to WordPress
  • You will be given the option to pick between a web, applications, or apps and web on the following screen. Make sure you choose the ‘Web’ option.
  • Following that, you must input the website’s name, URL, country, and time zone.
  • Click the Next button once you’ve finished entering this information. You’ll be provided with Google Analytics’ terms and conditions, which you must accept by clicking the “I Agree” button.
  • Your Google Analytics tracking code will now be displayed. You can copy this tracking code because depending on the technique you select below, you’ll need to paste it into your WordPress site. 

You may also leave this browser tab open and return to it when you need to copy the code. Once you’ve put the code on your WordPress site, you may need to go through it again.

Now that you have set up a Google Analytics account, let’s take a look at how to install Google Analytics in WordPress.

How to Add Google Analytics to WordPress Using Plugins

Using the OrbitFox plugin

How to Add Google Analytics to WordPress Using Plugins?

OrbitFox is a user-friendly plugin with a simple administration interface. It has a large feature set including Gutenberg blocks, a site optimizer, menu icons, and much more. It’s perfect for WordPress users who seek an all-in-one solution to improve their website.

Steps to add Google Analytics to your WordPress Site: 

  • Install the Google Analytics plugin in your WordPress dashboard to get started with OrbitFox’s Google Analytics capabilities. 
  • After it’s been turned on, go to OrbitFox > General Settings:
  • Toggle the Activate switch next to Analytics Integration from the list of choices. A new Authenticate with Google button will appear when you scroll down the page.
  • Pick your Google account from the popup and agree the requested permissions.
  • You’ll be returned to the OrbitFox settings page, with a new section at the bottom.

Try OrbitFox

Using MonsterInsight plugin

The finest Google Analytics plugin for WordPress is MonsterInsights. It allows you to set up Google Analytics in just a few clicks, and it does it without requiring you to modify any code. Furthermore, the plugin comes with a variety of advanced tracking capabilities that are activated instantly after installation. 

You no longer have to rely on guessing to figure out what content your visitors are interested in or which methods are effective and producing results with MonsterInsights. 

It aids in the discovery of visitor insights, centralizes key data in easy-to-understand reports, and offers data for business choices. 

It’s no wonder that over 2 million professionals use MonsterInsights because it’s so user-friendly and has so many features.

Article Continues Below

Steps to add Google Analytics to your WordPress Site:

  • Begin by installing MonsterInsights, the best Google Analytics WordPress plugin available. You must first connect to your MonsterInsights account and then download the plugin zip file. 
  • Once you’ve downloaded the zip file, go to the WordPress admin dashboard on the site where you wish to install MonsterInsights. 
  • Then go to Plugins » Add New and click the top-right Upload Plugin icon.
  • On the next page, pick the zip file you just downloaded by clicking the Choose File option. Then, to submit the file and install the plugin on your site, click the Install Now option.
  • You may activate the plugin on your site by clicking the Activate Plugin button when it has been uploaded and installed.
  • After you’ve activated the plugin, the plugin setup wizard will appear, guiding you through the procedure step by step.
  • At first, you’ll get a notice that says “Welcome to MonsterInsights!” and choices to select your website’s category. There are three choices: a business website, a publisher (blog), or an e-commerce store. Choose the category that best represents your website, then hit the ‘Save and Continue button. 
  • For the time being, you may bypass the setup wizard by clicking the ‘Exit Setup’ option at the top. By entering your license key on the following screen, you’ll be able to connect the MonsterInsights plugin to your website.
  • When you input your license key, it will authenticate your account, and then you can choose to connect MonsterInsights. 
  • After that, you’ll have the option of connecting your MonsterInsights and Google Analytics accounts. To continue authentication, choose your account.
  • To finish the connection, you’ll need to choose a profile. If you have multiple websites linked to your Google Analytics account, you must pick the relevant website property.
  • Click the ‘Complete Connection’ button after you’ve chosen your profile. 
  • It will next take a few seconds to finish the login process before returning you to your MonsterInsights setup page. 
  • The suggested settings for the Google Analytics plugin may now be viewed.This page contains some of the most essential options, such as: 
    • Events tracking 
    • Enhanced Link Attribution 
    • File Download Tracking — By default, the most often used file formats are included.
  • There will be additional options:
    • Affiliate Link Tracking – It comes with two affiliate link pathways by default and allows you to add more. 
    • Access to MonsterInsights Reports — You have complete control over who has access to MonsterInsights reports. 
    • Automatic Plugin Updates — The ability to install updates automatically can be enabled or disabled.
  • After reviewing and configuring these recommended options, click the ‘Save and Continue’ button to finish. It will suggest that you install a few of extras on the following screen.
  • The following are the two addons you need to install: 
    • MonsterInsights Forms – With MonsterInsights Forms, you can track your form views, conversions, and submissions. Works great with WPForms, whether you’re using it for a basic contact form, a multi-step form, or an order form. 
    • MonsterInsights Page Insights – In your dashboard, keep track of stats for specific articles and pages.
  • There will be a recommendation for the WPForms plugin in the following step. It was built by the same team that created MonsterInsights and is the most beginner-friendly WordPress form plugin. 
  • If you wish to utilize WPForms, click the ‘Continue & Install WPForms’ option. Otherwise, you may skip this step by clicking the ‘Skip this Step’ option. 
  • After that you’ll see the next screen with the words “Awesome, You’re All Set!” on it. It indicates that the installation procedure is complete and that Google Analytics has been successfully installed on your WordPress site.

Get MonsterInsight

How to Add Google Analytics to WordPress Manually

The last option we’ll look at is manually adding the required tracking codes to your WordPress site, which is the most basic but also the most difficult to implement. It’s critical to utilize a WordPress child theme if you choose this route. Otherwise, every time you alter your theme, your Google Analytics code would be replaced.

After you’ve created a Google Analytics account, you’ll need to obtain a tracking code to post on your website.

Getting the Google Analytics Tracking Code

The service will redirect you to the place where you can acquire the Google Analytics code once you’ve finished the enrollment procedure. If you wish to retrace your steps, here’s how to manually obtain your tracking code: 

  • After logging into your Google Analytics account, go to the Admin menu in the bottom left corner. 
  • Select the Tracking Info option from the drop-down menu. Then choose the Tracking Code option from the drop-down menu. 
  • Your Tracking ID and Global Site Tag should now be visible. Both of these codes should be saved because we’ll need them later.

After you’ve acquired the tracking code, go to your WordPress dashboard to begin the configuration process.

1. functions.php is a PHP script

Using the code snippet, you may integrate Google Analytics to WordPress in a few different ways. 

The functions.php file is the first place where you may enter the Google Analytics monitoring code. You make a new function with the code snippet in it. 

NOTE: It’s a good idea to make a backup copy of the file before making any changes for safety reasons. 

  • Navigate to the Theme Editor section of the Appearance menu on your WordPress dashboard. 
How to Add Google Analytics to WordPress Manually
  • From the right column, open the Theme Functions(functions.php) file. 
  • In the file, paste the code snippet below. Remember to change the Tracking ID to your own.
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-26575989-48"></script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'UA-26575989-48');
  • To save your changes, click the Update File button after you’re finished.

2. code in header.php

The Google Analytics tracking code can easily be added to the Theme Header (header.php) file. 

  • Return to the Theme Editor and make any necessary changes. 
  • On the right column, open the Theme Header (header.php) file. 
  • Using the WordPress Theme Editor to edit the header.php file 
  • Copy the code snippet and paste it in the header section, specifically above the /head> element. 
  • To save your changes, click the Update File button after you’re finished.

3. header.php code

  • Select Appearance, then Theme Editor from your WordPress dashboard.
  • If you try to change your theme, you will be warned. To proceed, choose I understand. 
  • You may now put the Analytics code you copied before into the box. Make sure it’s above the /header> tag. 
  • Click Update File and you’re done.

Wrapping Up!

That’s all there is to it! You now understand how to add Google Analytics with WordPress.

Google Analytics offers you data and insights that can significantly enhance the status of your website. Integrating it with your WordPress website may help you increase traffic and income. 

You can learn more about what works and what doesn’t for your visitors, as well as who they are, so you can keep tailoring your content to their requirements. Installing Google Analytics on your website is simple and quick with WordPress. You can start gathering the data you need to improve user experience and increase conversions on your WordPress website in minutes.

In WordPress, there are a few different ways to set up Google Analytics. You may utilize a plugin like MonsterInsights or OrbitFox, or take the DIY way and manually add the integration by modifying theme files if you’re using a child theme. In any case, you’ll have access to some of the greatest analytics available, as well as the power of WordPress.

Let us know how you get on this one! :)

Would you like to learn more about WordPress?

Sign up for our Weekly WordPress Newsletter.

Every Friday you’ll receive news, tutorials, reviews, and great deals from the WordPress space.

Invalid email address
A team of WordPress experts that love to test out new WordPress related software, WordPress plugins and WordPress themes.