How to Add Google Analytics Code to Your WordPress Website?

Como adicionar o código Google Analytics a seu site WordPress
Shares

Even the best content on the most well-optimized website is worth very little if we’re not tracking user behavior. As we all know, Google Analytics is the best solution for analyzing traffic on WordPress. Below, I’ll show you how to add the Google Analytics code to your WordPress site easily.


Why Google Analytics?

Google Analytics is free and easy to use. While these arguments strongly appeal to a large percentage of users, they are not the main advantages of GA. The features that speak to the power of this software are its features. It is a powerful aid for monitoring website traffic and analyzing user behavior.

Thanks to this tool, you can gather many valuable pieces of information, such as the number of visits to your site, traffic sources, popular pages, average time spent on the site, conversion rates, and many other pieces of information that can help you understand who is visiting your site and how users are using it.

Google Analytics can help you tailor your content and functionality to the needs of your users. This is possible by analyzing which subpages are most popular and by examining conversions. It means evaluating which actions are efficient and whether users are doing what you expect of them.

Of course, these are not the only possibilities – there are many more; let’s say that these mentioned ones are the most useful.


Installing Google Analytics on WordPress

WordPress is the most popular content management system on the market, while Google Analytics is the most popular tool for analyzing website traffic. Installing Google Analytics on WordPress can be done in various ways. You can add the tracking code manually to your site, use plugins, or Google Tag Manager.

Regardless of the option, adding the Google Analytics script to your site is relatively easy. However, I would like to emphasize that if you do not feel confident editing WordPress files, you can use a plugin to perform this task.


If you feel alone in managing your WordPress, change your provider to UltaHost. As part of Managed WordPress USA Hosting, you will receive the support of experts who will help you manage your WordPress website. They will also help you connect your WordPress site with Google Analytics.


Below are two methods: manual and using a plugin.

At the end of 2020, Google introduced the Google Analytics 4 service, which is expected to eventually replace Universal Analytics. Therefore, when installing Google Analytics on your website, consider using the new version, which is Google Analytics 4.

Another tool for marketing analysis created by Google is Google Trends. It is worth using both Google Analytics and Google Trends to achieve the best results in marketing activities. Read our article about Google Trends to see how you can use it in your day-to-day work.


Creating a Google Analytics Account

Before installing Google Analytics on your site, you must create a Google account or use an existing one that you use to log into Gmail and other Google services. Then you can go to the Google Analytics service page and configure your account.

Configuring Google Account

At the very beginning, you must choose the name of your Google Analytics account. It can be general; if you run a business, you can name your GA account after your company. Then, grant Google permission to access your site’s data.

Granting these consents is recommended by Google but voluntary. However, it is recommended to agree because Google will provide useful information about your website, such as comparing it with competitors or sending you technical tips. After entering the account name and checking the checkboxes, press the blue “next” button.

Service configuration

In the next window, enter the name of your service, preferably something like “My website” as well as the country of your business and currency. Once again, click the blue “Next” button.

Information about your company is the final step in creating a Google Analytics account. In this window, provide basic information about your company. Select the industry your company operates in from the drop-down menu. If your category is not listed, choose a similar field.

Check the appropriate company size and goals you intend to achieve with the help of Google Analytics. After clicking the blue “Create” button, you must accept the terms of use of the service. After accepting the terms of use, you will be redirected to the Google Analytics account panel.

Data stream configuration

Firstly, after logging in to the Google Analytics panel, it would be necessary to make initial account settings, such as setting up IP address filtering, so that your visits to the website are not taken into account when analyzing traffic. To do this, provide information about your website and create a stream, checking the option “Global Site Tag (Gtag.js)”.

Then the field will expand, containing the tracking code to be uploaded to your website. Add it as the first element in the head section on each page. Below you will see how to add the GA code in WordPress to make it available on every subpage.


Manually adding Google Analytics tracking code to WordPress

So far, regardless of whether you are adding the tracking code using a plugin or manually, the list of steps looks the same. Now, in the case of manual code addition, go to edit the header.php file. You can do it in two ways:

  • Editing via FTP server (e.g., using FileZilla);
  • Editing in the WordPress panel (Appearance -> Theme Editor -> header.php).

The final effect of editing the header.php file should look as follows:

<!doctype html>
<html <?php language_attributes(); ?>>
<head>
    <meta charset="<?php bloginfo('charset'); ?>">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title><?php wp_title(); ?></title>
    
    <!-- Google Analytics tracking code -->
    <?php
        $ga_id = 'UA-XXXXXXXXX-X'; // Replace with your Google Analytics ID
    ?>
    <script async src="https://www.googletagmanager.com/gtag/js?id=<?php echo $ga_id; ?>"></script>
    <script>
        window.dataLayer = window.dataLayer || [];
        function gtag(){dataLayer.push(arguments);}
        gtag('js', new Date());
        gtag('config', '<?php echo $ga_id; ?>');
    </script>
    
    <?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>

Make sure to replace “UA-XXXXXXXXX-X” with your own Google Analytics ID. You will find the header.php file in the primary directory of your WordPress site.


Adding Google Analytics tracking code to WordPress using a plugin

Adding Google Analytics tracking code to WordPress using a plugin is remarkably straightforward. Just install a plugin that allows you to add code to the head section from the WordPress panel and paste the tracking code into the appropriate field.

Installing additional plugins can increase the risk of security vulnerabilities in WordPress. Before installing an extra plugin, check the ones you already have. Maybe you already have one that allows you to place the GA code on the site.

Examples of plugins that support Google Analytics

MonsterInsights: This is one of the most popular plugins for tracking traffic in WordPress, which allows the easy addition of Google Analytics tracking code to the website. This plugin also offers many other features such as tracking internal links, tracking events, a Google Analytics browser extension, and many more.

Google Analytics Dashboard for WP (GADWP): It offers a simple and convenient interface for tracking website traffic with Google Analytics. GADWP also offers features such as tracking internal links, tracking events, and many more.

Analytify: This is another popular Google Analytics plugin that offers the uncomplicated addition of Google Analytics tracking code to the WordPress website. This plugin has features such as tracking internal links or tracking events.

ExactMetrics: This plugin offers easy addition of Google Analytics tracking code to the WordPress website. This plugin also offers to track internal links and tracking events. It has a Google Analytics browser extension.

WP Google Analytics Events: This plugin allows for effortless event tracking in Google Analytics. This plugin offers many different types of tracking, such as button clicks, page scrolling, video playback, and many more.

Insert Headers and Footers: This simple plugin allows you to paste the Google Analytics tracking code. You can do this in the “Scripts in Header” section. To confirm if Google Analytics is working properly, log in to your Google Analytics account and go to the “Reports” section. You should see traffic to your WordPress website in Google Analytics reports.


Conclusion

That’s it. Now you can go back to your Google Analytics account dashboard and check if the behaviors on your website are being counted. You’ll agree that adding tracking code on WordPress isn’t difficult, right?

Editing WordPress files can be a bit daunting for some people, but there’s no need to worry. Just make a backup of your site before making any changes. That way, if anything unexpected happens, you’ll be able to restore your website from the backup. 

Fast and Secure WordPress Hosting

In addition to focusing on creating compelling content and monitoring traffic, you cannot underestimate the issue of choosing the right hosting that will provide you with automatic backups, security, and performance and protect your website from hackers.

WordPress websites are often targets of hackers who look for vulnerabilities in the code, themes, and plugins. While adding more plugins can increase the risk of security vulnerabilities, it is important to choose well-vetted plugins and keep them up-to-date to minimize the risk. Without proper security measures, your website can be vulnerable to various forms of cyber attacks, including malware, ransomware, and phishing attacks. 

Secure WordPress hosting implements robust security measures to ensure that your website is protected from these attacks and helps you to make your website compliant with GDPR by implementing necessary security measures such as encryption, data backups, and access controls.


The best provider of secure WordPress hosting is UltaHost. Security is an absolute priority for UltaHost and its foundation is based on ensuring the integrity of protection and stability of systems. Next-generation hardware, NVMe SSD disks, and multi-layer protection systems against various threats make UltaHost a leader in security.


The proper WordPress Hosting also provides better website performance and uptime. A slow-loading website can negatively impact your website’s user experience. It can lead to a decrease in traffic and conversions. 

A secure and fast WordPress hosting provider uses state-of-the-art infrastructure, including caching, content delivery networks, and server-level optimizations, to ensure that your website loads quickly and remains accessible at all times.

By choosing a fast WordPress hosting, you can ensure that your website is protected from risks while enjoying better performance and uptime. Get 24/7 support from our support team. Our powered infrastructure focuses on auto-scaling, performance, and security. Let us show you the difference! Check out our hosting plans!   

Previous Post
VDS - the best solution

Why is VDS the best server solution for your company?

Next Post
How to Build a Solid Reputation With Google Maps Reviews?

How to Build a Solid Reputation With Google Maps Reviews?

Related Posts
 25% off   Enjoy Powerful Next-Gen VPS Hosting from as low as $5.50