Add Google Analytics to WordPress without a plugin

How to add Google Analytics to WordPress without a plugin

You ever wonder how can you add Google Analytics to WordPress without a plugin? As you know adding gtag.js (Google Analytics Code)  to your site helps you track your website traffic and gives accurate real-time visitors flow.

Adding Google Analytics to WordPress Without Plugin is a Good Idea?

Every WordPress users think that the fewer plugins on your site it’s always better than a lot of plugins for one small job like adding gtag.js code to WordPress. And that’s true these small jobs should be handled without a plugin. Because badly coded plugins could add bloat and slow down your site.

Before to get started, let’s take a look at why adding Google Analytics to your site without a plugin is a Good idea for only tracking your visitors.

  • Way too easy – Adding Google Analytics to your site without a plugin is easy with the step by step tutorial, stay tuned.
  • No Extra Plugin – No extra plugin, no extra code in backend – Result, the site will load fast.

Or If you’re looking for an easy way to set up Google Analytics with some cool features on your WordPress site, you may install and activate a plugin, named MonsterInsights, instead.

Add Google Analytics in WordPress Without a Plugin

Step 1: Get Your Google Analytics Tracking Code

To get gtag.js code Login to Google Analytics. Once you log in, you’ll see Google Analytics Home. Google Analytics home - add google Analytics code to wordpress

On the left-hand side click on “ADMIN” tab as above image. Next, you’ll see 3 options

    1. Create Account
    2. Create Property
    3. Create View

So for adding a new property (website) click on Create Property that you wish to track visitors. Once you click, complete the below steps as shown in an image and Get Tracking ID.

add Google Analytics to wordpress without plugin

And you’ll get your tracking code as Global Site Tag (gtag.js). So Just copy it. minimize the current tab and go to your WordPress Dashboard.

google site tag code

Step 2: Add the Tracking Code to the header.php file

Before this step, make sure to backup your header.php, so in case something goes wrong, you can easily revert it back. Just in case, it only took hardly 1-2 min.

Once you backup, head towards the WordPress dashboard, navigate to Appearance » Editor.

Every WordPress theme has a header.php. Find this file in the list at right, then click on the file link. It will open the file in the editor.

Next, you have to paste the code that you copied earlier (Google Analytics Code) in the header.php file above the “</head>” tag in the header.php file. See the below image to make sure where.

paste gtag.js in header.php file

Once you did carefully, Click on “Update File” to save the code changes. And done you will track your visitors in Google Analytics. You’ve just added Google Analytics in WordPress without a plugin.


About the Author: admin

You May Also Like

1 Comment

  1. Many thanks to you for sharing this article about adding gtag.js code to WordPress without any plugin. And you right I also don’t like to add a plugin for a such a small job. It should be done without plugin.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.