How to Add Google Analytics 4 to Website | GA4 Setup Guide

How to Add Google Analytics 4 to Website – Free Code Generator

How to Add Google Analytics 4 to Website

Generate the official Global Site Tag (gtag.js) for your website. Just enter your Measurement ID, copy the code, and paste it into your HTML head.

🆔 Configuration

Don’t have it? Check the guide below.

Placement Visualizer

Where does this code go?
index.html </>
<!DOCTYPE html> <html lang=”en”> <head> <meta charset=”UTF-8″> <title>My Website</title>
<!– Google Analytics 4 –> <script async src=”…”></script> <script> window.dataLayer… </script>
<link rel=”stylesheet” href=”…”> </head> <body>

Paste the code immediately after the opening <head> tag.

gtag.js

1. How to Get Your Measurement ID

Before you can use the generator above, you need your unique Measurement ID from Google. Here is how to find it:

  1. Go to Google Analytics: Log in to your analytics account at analytics.google.com.
  2. Admin Settings: Click the Gear icon (Admin) in the bottom left corner.
  3. Select Property: In the “Property” column, click on Data Streams.
  4. Choose Stream: Click on the “Web” data stream for your website.
  5. Copy ID: You will see a “Measurement ID” in the top right corner that starts with G-. Copy this string.

2. Installing the Code

Once you have generated the code using the tool above, follow these steps to install it on your site:

For HTML Websites

Open your index.html (and every other page you want to track). Paste the generated code immediately after the opening <head> tag. It must be placed before any other scripts or CSS links for the best accuracy.

For WordPress

The easiest way is to use a plugin, but if you want to add it manually without plugins:

  • Go to Appearance > Theme File Editor.
  • Find the header.php file on the right side.
  • Paste the code right after the <head> tag.
  • Click “Update File”.

For Shopify

  • Go to Online Store > Themes.
  • Click the three dots (…) and select Edit code.
  • Open the theme.liquid file.
  • Paste the code after the <head> tag.
  • Save changes.

3. Verifying Installation

After installing, open your website in a new tab. Then, go back to Google Analytics and navigate to Reports > Realtime. If you see “1 user” (yourself) in the last 30 minutes, the tag is working correctly!

https://quickcalculators.in/how-to-create-a-contact-form-in-html-and-css/