Adding Google Analytics to WordPress using “Header and Footer Scripts” plugin

So, you just created your new WordPress site. Next, you need to track your visitors with Google Analytics. You are at the right place. This article explains how to add Google Analytics to WordPress using the “Header and Footer Scripts” plugin. (No Google Analytics Plugin needed. Just copy and pasting code.)

Step 1: Get the Tracking Code

Log in to your Google Analytics account and choose your website. If you haven’t registered an account already, check out this guide. Then, go to the Admin section at the bottom left, then Tracking Info, finally Tracking Code. Copy the code given which might look like follows.

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src=""></script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'YOUR_ANALYTICS_ID');

Step 2: Add it to the footer using the plugin.

In this tutorial, we will be using the Header and Footer scripts plugin. You can easily install it from the WordPress admin panel (Plugins -> Add new).

Then, go to Settings -> Header and Footer Scripts. In the Scripts in Footer section, paste the copied code and save.

That’s all! You have just successfully installed Google Analytics on your WordPress website. If anything went wrong, please let us know via comments at the bottom of this article.

Adding Google Analytics to WordPress

FAQ on Adding

The rest of this article is just some optional FAQs.

Q: Is there any disadvantage of using this method?
If you ever plan to add more advanced tracking methods like event tracking, much work will be needed in the future compared to using another Analytics plugin available.

Q: Will I lose the code if I change the theme?
No, as we used an external plugin to add the code, it will survive even if you change the plugin.

Q: Why do you add the code to the footer instead of the header?
Good question. No reason. If you like, you can add it to the header. The code already has an async attribute. So, the script will load asynchronously and won’t affect the load time. Therefore, it doesn’t affect your on-page SEO performance. If you find a script that doesn’t have a async tag, it’s better to add it to the footer where all the page content has finished loading.

Need a privacy-focused commenting platform for your website?