Home ยป Where To Put In Google Analytics Code – Quick Tip

Where To Put In Google Analytics Code – Quick Tip

Where To Put In Google Analytics Code - Quick Tip
Where To Put In Google Analytics Code – Quick Tip

You may have come across various tutorials on where to put Google Analytics code in your website, whether it’s blogger or WordPress.

But this one is different.

Because I will be covering both WordPress and static HTML websites.

A lot of people face problems while messing up with the code. They want some easy solutions. That’s why I constantly work for those new to blogging and want to pursue this as a career.

FYI: Want to Earn money from Facebook? or want to know about Free SEO tools for beginners? I have got everything for my beloved readers.

Lets’s Get started with the basic points & detailed explanations:

  1. Using a plugin if you are using wordpress
  2. Using a code snippet to add code manually in wordpess
  3. Adding Code Snippetts in static HTML website.

A detailed description for all the steps above is provided below:

Using a plugin if you are using WordPress

A Plugin is one of the easiest ways to add google analytics to your WordPress website. Now what I personally don’t like about using the plugin is:

  • They clutter your website code unnecessarily.
  • They cause additional requests to web servers which significantly increase load time for even a light webpage.
  • A plugin can break your website functionalities with theme update, wordpress core update or with its own update.
  • Unintalling a poorly coded plugin can be difficult. Because plugin create entries in wordpress database and not properly uninstalling it can do unnecessary database cluttering.

However, there are also many advantages like:

  • Click-and-run system
  • Instant results and
  • Handy

Some of the well-known plugins which are tested up to WordPress v5.8 for adding Google Analytics to WordPress are:

Site Kit by Google

As the name suggests, this plugin is developed and maintained by Google. Site kit by Google is the best option to have all google services in one place on your website.

This plugin has the ability to connect Google Analytics, Search Console, AdSense, and Google PageSpeed Insights together.

However, According to my, Google Site Kit is not recommended for those running their website or blogs on a shared hosting plan as this is a heavy plugin. It can negatively affect your page speed.


MonsterInsights is currently the top-rated plugin for adding Google Analytics to WordPress. Once you installed this plugin, you just have to authorise this with your Google account. The plugin will do the rest.

MonsterInsights also set up a quick menu at your WordPress dashboard where reports directly from Google Analytics are shown in a customised way.

WooCommerce Google Analytics Integration

It’s the official plugin for the website using WooCommerce from the company. It will integrate your Google Analytics and WooCommerce together.

Google Analytics and Google Shopping plugin for WooCommerce

This is an Add-On plugin from WooCommerce, which automates end-to-end Google Shopping with dynamic remarketing tags. It’s free to download by visiting the link above.

GA Google Analytics

Again a Google Analytics plugin. This plugin is different from other plugins because it supports legacy GA4 analytics, global site taggtag.js, and analytics.js. You may choose from any of the three to start tracking.


Analytify is a less popular but useful plugin. This has both WooCommerce integration and legacy tracking feature, so you can use any of the options.

Let me know if something is wrong or this list is missing something or having something unnecessary.

Using a code snippet to add code manually in WordPress

A code snippet is the best option to use when it comes to using plugins on your WordPress site. For this, I will tell you about Minimal Analytics.

You all know that Google Analytics works only when the script is loaded completely. But the script itself is so long that it takes minutes to load, which is not good for SEO.

So here I am sharing a script with you, which is called Minimal Analytics which tracks how many visitors visited your website:

  (function(a,b,c){var d=a.history,e=document,f=navigator||{},g=localStorage,
  h=encodeURIComponent,i=d.pushState,k=function(){return Math.random().toString(36)},
  l=function(){return g.cid||(g.cid=k()),g.cid},m=function(r){var s=[];for(var t in r)
  r.hasOwnProperty(t)&&void 0!==r[t]&&s.push(h(t)+"="+h(r[t]));return s.join("&")},
  n=function(r,s,t,u,v,w,x){var z="https://www.google-analytics.com/collect",
  A=m({v:"1",ds:"web",aip:c.anonymizeIp?1:void 0,tid:b,cid:l(),t:r||"pageview",
  sd:c.colorDepth&&screen.colorDepth?screen.colorDepth+"-bits":void 0,dr:e.referrer||
  void 0,dt:e.title,dl:e.location.origin+e.location.pathname+e.location.search,ul:c.language?
  (f.language||"").toLowerCase():void 0,de:c.characterSet?e.characterSet:void 0,
  sr:c.screenSize?(a.screen||{}).width+"x"+(a.screen||{}).height:void 0,vp:c.screenSize&&
  a.visualViewport?(a.visualViewport||{}).width+"x"+(a.visualViewport||{}).height:void 0,
  ec:s||void 0,ea:t||void 0,el:u||void 0,ev:v||void 0,exd:w||void 0,exf:"undefined"!=typeof x&&
  !1==!!x?0:void 0});if(f.sendBeacon)f.sendBeacon(z,A);else{var y=new XMLHttpRequest;
  y.open("POST",z,!0),y.send(A)}};d.pushState=function(r){return"function"==typeof d.onpushstate&&
  a.ma={trackEvent:function o(r,s,t,u){return n("event",r,s,t,u)},
  trackException:function q(r,s){return n("exception",null,null,null,null,r,s)}}})

Additional Steps to Add Analytics code above to your WordPress Website:

  1. Login to your WordPress Dashboard

  2. Go to Appearance

  3. Go to Theme Editor

  4. Select the Active theme from the right side

    If possible, use a child theme to customise your parent theme. Otherwise, your next theme update will override this setting.

    We will discuss setting up a child theme in some other post

  5. Select header.php file

  6. Search for a <head> tag in header.php

  7. Paste the script above right after <head> opening tag

    This is necessary to paste the script here because Analytics works only when the script is loaded completely.
    Once you paste it in the head, the browser will first parse this script.

  8. You’re done now.

    You have to replace XX-XXXXXXXXX-X from the script with your analytics ID, which you can find in your Google Analytics account.

Adding Code Snippetts in static HTML website.

Adding a Code snippet is the same as copying and pasting the script above. Steps for the same are given below:

  1. Go to source code your static html content.
  2. Find <html> tag.
  3. Paste the same script just below <head>.
  4. Save page.
  5. You are Done!

So that was for today. I hope you really enjoyed it. Let me know your suggestions in the comment box. Have fun. Bye.

Leave a Comment

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