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.
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.
On the left-hand side click on “ADMIN” tab as above image. Next, you’ll see 3 options
- Create Account
- Create Property
- 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.
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.
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.
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.