How To Add Google Analytics On WordPress- Easy Way 2023

How To Add Google Analytics To WordPress?

If you want to successfully run a website, you need to get to know the visitors and what they expect from your site. The best way to do this is to analyze your website traffic. And this is exactly what Google Analytics does.

This free software from Google makes it easy for you to track website visitors, and analyze their habits, sources of traffic, social metrics, and even various statistics.

By analyzing statistics, you can plan and create better content for site visitors. This tutorial will show you some steps or ways that you can register and add Google Analytics to the WordPress website.

Why is Google Analytics Needed on Your WordPress?

Wouldn’t everything be easier if you knew the wants and needs of users as well as what they want from your website and services? The only way to keep visitors interested in visiting your website is to offer and provide what they want. This is what Google Analytics does, and the service is free!

Here are some reasons why you should add Google Analytics to WordPress and why every WordPress blog must have this software:

1. It helps know the behavior of visitors and users of your site.
With Google Analytics, you can continue to track the behavior patterns of site visitors virtually. You can also check the pages that are visited the most, the average time users spend on a particular page, the page with the best performance, pages that are not interesting so that users leave the website, and much more.

A glance is not enough for you to get information on optimizing your website to be better. When a particular blog attracts many visitors, of course, you will write more posts related to the topic and increase traffic.

2. It helps you analyze the time of the most active site visits.
You will easily find out what time your site is most visited. If most users are active at night, then to attract them, the post should be published at these times.

3. It helps you check important details.
Google Analytics provides very detailed details – from the user’s geographical location, the language they apply, the browser they are using, the screen resolution, to the likes. These details help you understand site visitors.

Although there are many web analytics services that you can use, Google Analytics has a variety of exclusive features. Let’s see at a glance what the features are:

  • Display Custom Reports easily.
    The best step to analyze the behavior patterns of your site users is to use facts and figures. This can be done by displaying Custom Reports which have a system interface that is easy to understand. You can add various parameters and metrics to display useful reports.
  • Install Custom Alerts.
    This is a very beneficial feature of Google Analytics because you can send custom alerts in the form of text messages or e-mails whenever traffic decreases or a drastic change occurs in the bounce rate (the percentage of visitors who leave the site). Thus, you no longer need to continue to monitor the dashboard to find out important updates.
  • Integrate Search Console.
    Continuously monitoring and monitoring the status related to SEO and numbers is very important. Search Console is a tool that provides information related to search engine optimization. Integrating Search Console with Google Analytics makes it easy for you to access information under one roof for quick analysis.

The three features above are just a few of the many features of Google Analytics that make the whole process very easy when you handle a WordPress website!

How does Google Analytics work?

You might think that Google Analytics is the right choice. However, does it just stop there? We understand that having a basic knowledge of how software works are very helpful when you want to run the software. Broadly speaking, Google Analytics consists of:

  • JavaScript code.
    When a visitor visits your website, JavaScript code is run to collect all important information about the website itself, about visitors (for example, the browser used to search for your website), operating system, screen resolution, and so on.
  • Data collection service (data collection service).
    After being collected by JavaScript code, all information is sent to Google’s servers to be processed into a small package format called hit. This hit will be sent every time a visitor opens your website.
  • Data processing (data processing).
    During data processing, the Google Analytics server converts the data into useful information. For example, your site visitors will be categorized by location, language, screen resolution, type of device, and so on.

This is how Google Analytics works. It looks easy on the surface, but all functions and processes are running behind the scenes.

Hopefully, this information helps you in deciding whether you want to add Google Analytics to your WordPress website. Without the need for further rambling explanations, you just learn this short tutorial to find out and understand how to register and add Google Analytics to your WordPress website.

What do you need?

Step 1 – Create a Google Analytics Account

The first thing you need to do is create a Google Analytics account to get the tracking code. Here’s how to register for Google Analytics:

  • Go to the main Google Analytics page. Click the Sign In button at the top of the page, then select Google Analytics
  • You will be directed to the Login page. Enter your Google email address and click the Next button. If you don’t have a Google account, create one by clicking the Create Account button.

google analytics sign up

  • On the next page, enter your password and click the Sign In button.

analytics sign up

  • Click the Sign-Up button to process.

Sign-Up button to process

  • To create a new account, you must enter the following information:
  • Account Name ( Account Name )
  • Name of the website ( Website Name )
  • Website URL ( Website URL )
  • Category Industry ( Industry Category )
  • Time Zone ( Reporting Time Zone )

google analytics new account page

Fill in all the required details and click the Get Tracking ID button (6). On the next page, you will be asked to agree to the Terms of Service. Click the I Accept button.

Done! You have successfully created a Google Analytics account. On the next page, you will see the tracking code for Google Analytics Universal:

<script>
  (function (i, s, o, g, r, a, m) {i ['GoogleAnalyticsObject'] = r; i [r] = i [r] || function () {
  (i [r] .q = i [r] .q || []). push (arguments)}, i [r]. l = 1 * new Date (); a = s.createElement (o),
  m = s.getElementsByTagName (o) [0]; a.async = 1; a.src = g; m.parentNode.insertBefore (a, m)
  }) (window, document, 'script', 'https: //www.google-analytics.com/analytics.js','ga');
 
  ga ('create', 'UA-00000000-1', 'auto');
  ga ('send', 'pageview');
 
</script>

This JavaScript code can be used for all websites. Only tracking ID ( UA-00000000-1 ) is unique. The Tracking ID starts with UA, short for Universal Analytics, then the first number represents the account number ( 00000000 ), then the last number represents the Google Analytics property ID (1).

Step 2 – Add Google Analytics to the WordPress Blog

There is more than one way to add the Google Analytics tracking code to WordPress: use the Plugin, add the tracking script directly to the header.php file, or take a new action in the functions.php file.

Method 1 – Using Plugins

If you are not familiar with WordPress and PHP file structures, then you are advised to use the Plugin method. One of the best plugins for adding Google Analytics is Analytics Code Integration. This plugin will enter the Universal Analytics tracking code automatically – you only need to enter the tracking ID.

Here are the ways to install the Plugin and enter your Google Analytics tracking ID:

  • Log in to the WordPress Dashboard and install the Google Analytics plugin.
  • After the installation process is complete, go to the Settings page and click Google Analytics Code.
  • Copy and move the code to the Google Analytics Code page and click Save.

google analytics code add to wordpress

 

Done! The tracking code has been successfully added to your WordPress blog.

It takes Google Analytics 12-24 hours to update and start displaying results. After that, statistics on the number of site visitors will be provided on the Google Analytics Reporting tab.

google analytics reports

 

Method 2 – Enter the code in header.php

As we know, there are several ways to enter Google Analytics code into a WordPress blog. For example, code can be included in your header.php theme file.

  • Access the WordPress administrator area and open it to Appearance → Editor.
  • Open header.php to start editing.
  • Enter the Analytics tracking code you need in Method 1 before the last tag and click the Update File button.

google analytics tracking code adding to headers

Note: Analytics code will only be entered into the active theme. The code must be added if you change the theme.

Method 3 – Create a New Function in the functions.php file

This third method requires basic knowledge about coding. We recommend that you follow this step only if you already understand and are ready to apply it. Additionally, you must back up the functions.php file or even the entire WordPress installation before this step starts:

  • When you are on the WordPress dashboard, go to the Appearance -> Editor page.
  • Select functions.php from the list of files on the right.
  • The snippet code below will pair the new function and enter the Analytics tracking code right before the last tag on your WordPress site. Copy the following code to the bottom of the functions.php file, but be sure to first change your tracking ID.
    add_action ('wp_head', 'my_analytics', 20);
     
    my_analytics function () {
    ?>
    <script>
    (function (i, s, o, g, r, a, m) {i ['GoogleAnalyticsObject'] = r; i [r] = i [r] || function () {
    (i [r] .q = i [r] .q || []). push (arguments)}, i [r]. l = 1 * new Date (); a = s.createElement (o),
    m = s.getElementsByTagName (o) [0]; a.async = 1; a.src = g; m.parentNode.insertBefore (a, m)
    }) (window, document, 'script', 'https: //www.google-analytics.com/analytics.js','ga');
     
    ga ('create', 'UA-00000000-1', 'auto');
    ga ('send', 'pageview');
     
    </script>
     
    <? php
    }
  • Save the changes that you have made by clicking the Update File button.

google analytics tracking code adding to functions.php

Note: The code will only be entered into the active theme. If the theme is changed, you must add the code again.

Conclusion

No doubt, Google Analytics plays an important role in your WordPress website. With this tool, you can understand the site visitors. Through this tutorial, you have learned how to create a G A account and three different ways or steps to add Google Analytics to your WordPress blog.

Leave a Comment