Is It Best to Add Google Analytics With or Without a Plugin?
You might think that the fewer plugins you use on your site the better, but that’s not always necessarily true.
It’s true that badly coded plugins could add bloat and slow down your site.
But a well-made, lightweight plugin can save you a lot of time and hassle, without any ill effects.
In fact, the number of plugins on a WordPress site has actually next to no direct correlation with your site’s speed and performance. It’s all about the quality of the plugins installed. The larger plugins for WordPress, like MonsterInsights, which have millions of installs, are more tested and optimized for speed. They have no impact on site load speed whatsoever.
Add Google Analytics in WordPress Without a Plugin
Before we get started, make sure to backup your WordPress theme, so in case something goes wrong, you can easily revert it back.
You’ll be directly editing the code that outputs your site, so a mistake as small as a misplaced comma could bring down your whole site. Be sure to make a backup just in case.
Step 1: Get Your Google Analytics Tracking Code
Log into your Google Analytics account and select the website for which you need the tracking code.
Click on Admin in the left taskbar or Setting Icon.
In the property column, click Tracking Info, and then Tracking Code.
Now you can get the tracking code under the Website tracking section. Just copy it.
Step 2: Add the Tracking Code to the header.php file
Log in to your WordPress dashboard and navigate to Appearance » Editor. Now click the header.php file on the right-hand side below the Templates section.
Paste the tracking code you just copied from your Analytics profile before the closing </head> tag.