Google Analytics is something you should get sorted out right at the very beginning time period of having a WordPress website or a blog. This is to ensure that you are not missing out on useful statistics that will help you grow your WordPress website or blog.
There are two ways to link your WordPress website or blog with Google Analytics. The first way requires no plugin at all. You will need to copy and paste the Google Analytics tracking code into your WordPress website’s header.php file, right before the closing </head> tag.
However, there are some downsides to the first way of doing things. One of the downside is that if you paste the tracking code wrongly into the header.php file, it will not work and in some cases, it might cause your WordPress website or blog to crash. The other downside is that even if you manage to paste the tracking code the right way, you will need to redo it if you change your WordPress theme. This is because the header.php file is part of the WordPress theme files. Changing the overall WordPress theme will also change the header.php file. Therefore, your tracking code will be gone with the old theme files.
Using a plugin to link Google Analytics to your WordPress website or blog on the other hand will keep you safe from the above-said downsides. I’ll explain to you how it avoids the downsides while guiding you on how to use a plugin to link Google Analytics to your WordPress website or blog below.
For this guide, I will be using the Insert Headers and Footers plugin developed by WPBeginner.
This plugin is very simple and straightforward to use.
Upon installing and activating the plugin, you can head over to the settings section of the plugin which looks like the following screenshot.
As you can see from the screenshot above, there’s a text area that says Scripts in Header and there is a text area that says Scripts in Footer. These Scripts in Header and Footer is basically a direct link to your WordPress theme’s header.php and footer.php file.
So when you paste a code snippet here, it’s 100% similar like pasting a code snippet into your theme’s files. In other words, you don’t need to go looking for the header.php or footer.php file under the Theme Editor and you don’t need to squint your eyes to paste the code into the <head> section.
In this case, if you want Google Analytics to be linked to your WordPress website or blog, it’s just a matter of pasting the tracking code into the Scripts in Header section. And followed by saving the changes.
Just like that, Google Analytics will be linked.
On top of that, whenever you change your WordPress theme, you don’t need to worry about losing the tracking code and you don’t need to redo the whole process. That’s because inserting the tracking code this way will sort of like tattoo it into your WordPress website or blog’s core header.php file.