How to Add Google Tracking Code Using PHP in cPanel

How to Add Google Tracking Code Using PHP in cPanel

To scale your website’s growth, you need to monitor it. Analysing your readers is one of the most important things you must adapt.

And everyone knows that Google analytics is one of the best free tools we have on the market. Although people are using many other means, everyone is familiar with Google Analytics.

The problem occurs when newbies have to add the tracking code to their WordPress websites. Most of the people try to find a plugin.

After installing a plugin, they complain of having a slow website speed. It’s because you don’t need a plugin merely to add a tracking code.

There are many other ways. You can use an existing plugin which allows you to add multiple codes to your website’s header and footer; you can directly copy and paste the code to the footer.php file.

Today, you’re going to learn a unique method, which requires the use of cPanel. You may be wondering if there is something techie involved.

Well, to avoid a plugin, you must go through a few things which aren’t familiar to you. Don’t worry; I will walk you through.

Learn to Add Google Tracking Code Via cPanel

Now and then, you may require the use of cPanel. If you look closely, almost every web hosting offers cPanel, even to its starter plan users.

The color, design, and options may be a little bit different, but you can easily find the essential functionalities. Let me start the process.

Step 1:

Log into your cPanel account and open the file manager, you can find it under Files’ section. Many companies provide the File Manager separately.

How to Add Google Tracking Code Using PHP in cPanel

Take some time, do some research, and open the file manager.

Step 2:

As always, you may see the home directory, you have to make sure you’re in the public_html directory. The data of your website resides in the root directory.

If you host multiple websites on the same web hosting server, depending on your domain, you have to find its folder. The primary domain always resides in the public_html directory.

How to Add Google Tracking Code Using PHP in cPanel

Now, you have to create a new file. Click on the File option from the main horizontal navigation menu.

Step 3:

A popup appears where you have to fill in the name of the file. Here, you need to create a text file, choose .txt as the extension.

How to Add Google Tracking Code Using PHP in cPanel

In this example, I am choosing “analyticsone.txt” as the new file name. Click on the Create New File button.

Step 4:

Refresh the page, and you can see your new text file. Right-click to edit or use the common Edit link from the navigation menu.

How to Add Google Tracking Code Using PHP in cPanel

Step 5:

A popup appears to authenticate, click on the Edit button.

How to Add Google Tracking Code Using PHP in cPanel

A new page appears where you have you to paste the Google Tracking code you have copied. Click on Save Changes from the top-right corner.

There is one more thing; you need to complete. You have created a new file, pasted the code, but to make WordPress aware, you have to edit its homepage index file, typically, it’s index.php.

Step 6:

If you have modified the index file, then search for it. Otherwise, index.php is there.

How to Add Google Tracking Code Using PHP in cPanel

Right-click to edit and a popup appears, click on the Edit button and authenticate. You can see tons of coding lines, scroll down and add this code.

<?phpinclude_once"analyticsone.txt";?>

Note: Don’t forget to replace the name of the text file.

Click on Save Changes, and you’re good to go. Google Analytics will start monitoring your website, and within a few weeks, you can see the results.

Congrats, you have learned a new method to enable Google Analytics on your WordPress website.

I Hope You Can Easily Add Google Tracking Code

I know, most of the WordPress users aren’t so techie, and they need someone to help them. Well, if you go through any WordPress forum, you can quickly notice people complaining about poor page loading time.

And if you read any guide to enhance your website’s performance, you can find a WordPress expert suggesting to reduce the use of plugins.

More plugins lead to increase the chances of getting your website slow. Taking a necessary step can save you. You can either use this tutorial or you can learn to add custom code to the header and footer areas of your site.

Conclusion

No doubt that Google Analytics can help you find out the correct audience to target. Most of the marketers use such a tool.

Enabling Google Analytics on a website can be challenging to many. I am sure, you can easily follow the steps mentioned above.

Check out these top 3 WordPress hosting services:

A2 Hosting
$2.99 /mo
Starting price
Visit A2 Hosting
Rating based on expert review
  • User Friendly
    4.5
  • Support
    4.0
  • Features
    4.5
  • Reliability
    4.8
  • Pricing
    4.0
IONOS
$1.00 /mo
Starting price
Visit IONOS
Rating based on expert review
  • User Friendly
    4.5
  • Support
    4.0
  • Features
    4.5
  • Reliability
    4.5
  • Pricing
    4.3
HostArmada
$2.49 /mo
Starting price
Visit HostArmada
Rating based on expert review
  • User Friendly
    4.5
  • Support
    4.5
  • Features
    4.5
  • Reliability
    4.5
  • Pricing
    4.0

How to Add a Google Analytics Tracking Code to Your WordPress Site

This is a how-to article which will have two different methods to enable Google
3 min read
Avi Ilinsky
Avi Ilinsky
Hosting Expert

How to Configure PHP Versions and Options on cPanel

This guide will show new webmasters about switching to different PHP versions an
2 min read
Avi Ilinsky
Avi Ilinsky
Hosting Expert

How to Install Google Analytics on Your WordPress Site

Want a better insight of your website stats? This is a step-by-step guide on ins
2 min read
Eliran Ouzan
Eliran Ouzan
Web Designer & Hosting Expert

How To Logout All Users In WordPress At Once

What will you do if your WordPress site has been hacked or want all the users to
2 min read
Eliran Ouzan
Eliran Ouzan
Web Designer & Hosting Expert
HostAdvice.com provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.
Click to go to the top of the page
Go To Top