How To Add Google Analytics In Html

If you have a website, it is vital to monitor its traffic and user behavior for its development. Google Analytics is a robust tool that enables you to achieve this. In this blog post, we will assist you in incorporating Google Analytics into your HTML website.

Step 1: Create a Google Analytics Account

If you haven’t done it already, the first step is to create a Google Analytics account. Visit and follow the prompts to set up a new account.

Step 2: Get Your Tracking ID

Once your account is created, the next step is to get your Google Analytics Tracking ID. This will typically be in the format of UA-000000-2. You can find this by going to the ‘Admin’ section of your Google Analytics account, then clicking on ‘Tracking Info’ and then ‘Tracking Code’.

Step 3: Add the Google Analytics Tracking Code to Your HTML

With your tracking ID in hand, now it’s time to add the Google Analytics Tracking code into your HTML code. The tracking code should be added to every page that you want to track. It is typically placed in the head section of your HTML document.

The standard Google Analytics tracking code looks like this:

  <script async src=""></script>
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('js', new Date());

    gtag('config', 'YOUR_TRACKING_ID');

In the above code snippet, replace ‘YOUR_TRACKING_ID’ with the actual tracking ID you obtained from your Google Analytics account.

Step 4: Validate Your Setup

After adding the tracking code to your HTML, it’s important to validate whether Google Analytics is functioning properly. A simple way to do it is by checking your website’s real-time analytics. Open your website in a new browser tab and then go back to your Google Analytics account. Navigate to the ‘Real-Time’ section. If everything is set up correctly, you should see at least one active user on your website- that’s you!


And there you have it! You’ve successfully added Google Analytics to your HTML website. You are now ready to start tracking and analyzing your website’s traffic. If you run into any issues during setup, Google’s support page is a great resource. Happy analyzing!