Manually install Google Analytics for WordPress without any plugins

Last updated on June 26th, 2022 at 11:41 am

There’s a big variety of plugins that can help you add Google Analytics code to a WordPress site. Google Analytics for WordPress by MonsterInsights and Awesome Google Analytics are just two of them.

But some webmasters prefer to have as fewer plugins as possible on their sites. In order to implement a Google Analytics code for your site without the help of any plugins, just follow the steps below.

Where to find my unique Google Analytics code

If you wonder what is your Google Analytics code and if you’re not sure where to find it, follow these steps.

    Log in to your Google Analytics Account. You have to find a code that looks like this:

    Click on Admin > select your preferred account from the menu, then select your site from Property and click on Tracking Info. On the next screen, you will find your unique Analytics tracking ID.

    Copy the Analytics code and be ready to paste it in the code of your WordPress site.

    There are two options. The first one is to paste the unique tracking code from your WordPress site’s backend. The second one is to paste the Analytics tracking code from your hosting account via cPanel or via FTP.

Manually add Google Analytics to the header.php file from wp-admin

Before making any changes to your header.php file, please make sure that you backed up your site prior to the change. We’re going to make changes only to the header.php file, so making a copy of your current header.php file would be enough.

    Log in to your site’s backend as administrator and go to Appearance > Editor and click on the header.php file as shown below:

    Search for </head> or just scroll down and find </head>. Now paste your Google Analytics code before the </head> tag as show on the screenshot.

    Click on the Update File Button in order to save the changes.

    Google advises to paste the Google Analytics tracking code in the header of the site. However, you are free to put the code in any other module of your site such as the footer.php file. You can even put the file as a code in a text widget.

Check if Google Analytics tracking code is working correctly

The tracking code is now added to your site’s header. In order to check if the recently added Analytics code is working correctly, you will have to do the following.

Go to your Analytics account. Make sure that the correct Property was selected and click on Real-Time under the Reports section. Select Overview as show on the screenshot

If there are no visitors currently on the site, it will be showing 0 visitors right now. In order to prove your Analytics tracking code functionality, feel free to visit your site and if everything was set up correctly, you should be able to see your own visit reflected in your Analytics account > Reports > Real-Time > Overview.

Congrats! Your Analytics code should be working perfectly.

Manually add Google Analytics to the header.php file from cPanel

If for some reason the previous method doesn’t work for you, you can add the Analytics code to your header.php file directly from cPanel. Here are the steps for adding an Analytics tracking code from a GoDaddy shared Linux hosting account.

 

Access cPanel and go to File Manager

Then select the folder where your site was installed in. Open the folder called wp-content, open the folder called themes and double click on the folder of the current theme for your site. Find the file called header.php, right click on it and click on Download so that you have a backup copy of your header.php file. The next step is to right click on the file again and select Edit.

Now locate the </head> tag and paste your Analytics code before that tag.

Click on the Save Changes button.

The tracking code is set up successfully. To check if it’s working as normal, just follow the steps for checking if Analytics tracking code is working correctly.

Author: wpbackend

Content creator at wpbackend.com

Leave a Reply

Your email address will not be published. Required fields are marked *