How to Add Google Analytics to Your Website (GA4)
To add Google Analytics to your website, create a GA4 property, copy the Measurement ID (it looks like G-XXXXXXXXXX), and paste the tracking snippet into your site’s <head> on every page. Then check the Realtime report — if you see yourself, it’s working.
Step 1: Create the property
- Go to analytics.google.com and sign in with a Google account.
- Click Admin (bottom-left).
- Under Account, create an account if you don’t have one. Name it after your business.
- Under Property, click Create Property. Give it your site’s name and set the time zone and currency.
- For Industry and Business size, answer honestly — it only affects reporting comparisons.
- Click Create, then accept the data collection terms.
Analytics creates a data stream for you.
Step 2: Get your Measurement ID
- Choose Web as the platform.
- Enter your website URL and a stream name.
- Click Create stream.
- Copy the Measurement ID — it looks like
G-XXXXXXXXXX.
You’ll also see a “View tag instructions” link with the full snippet. Keep that tab open.
Step 3: Install the tag
You have three realistic options. Pick by what your site runs on.
Option A: A plugin or platform setting (easiest)
Most website platforms have a field for exactly this:
| Platform | Where to paste it |
|---|---|
| WordPress | Install a GA plugin (MonsterInsights, Site Kit) or paste via your theme’s header settings |
| Squarespace | Settings → Developer Tools → External API Keys → Google Analytics |
| Wix | Settings → Advanced → Marketing Integrations → Google Tag |
| Shopify | Install the Google & YouTube app, then connect your GA4 property |
| Webflow | Site settings → Integrations → Google Analytics |
Paste the Measurement ID, not the whole snippet, in these fields. The platform adds the code itself.
Option B: Paste the snippet into your theme
For a custom site, add the snippet just before </head> on every page. Most themes have a way to inject header code — or edit the template directly.
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXXXXX');
</script>
Replace G-XXXXXXXXXX with your own ID — twice.
Option C: Google Tag Manager
If you already use GTM, add a GA4 Configuration tag with your Measurement ID, set the trigger to All Pages, and publish. This keeps all your tracking in one place.
Step 4: Verify it’s working
This is the step people skip — and then wonder why the data is empty.
- Open your site in a browser.
- In Analytics, go to Reports → Realtime.
- You should see 1 active user (you) within about 30 seconds.
- Click into it — your country and the page you’re on should appear.
If Realtime shows nothing after a couple of minutes, see the troubleshooting table below.
Troubleshooting
| Problem | Likely cause |
|---|---|
| Realtime shows 0 | Snippet missing, or on some pages only |
| Data appears then stops | The snippet was removed in a theme update |
| Only some visitors appear | Ad blockers and consent banners suppress tracking — this is normal |
| Two properties, doubled numbers | Snippet installed twice (once in theme, once in plugin) |
| Data takes days to appear in reports | ✅ Expected — Realtime is instant, standard reports process over 24–48 hours |
Ad blockers and consent are not bugs. A meaningful chunk of visitors — especially in Europe — will never be counted. Google Ads clicks will often exceed GA4 sessions for exactly this reason. Don’t chase the gap.
What to look at once it’s running
Reports → Realtime for instant proof. Then, after a day, the useful reports are:
- Acquisition → Traffic acquisition — where visitors come from
- Engagement → Pages and screens — which pages get read
- Reports → Engagement → Overview — how long people stay
Don’t over-read the numbers early. A new site with 20 visitors a day can’t produce meaningful patterns yet — you need a few hundred sessions before the data says anything reliable.
For what to do with that traffic next, see what is SEO and how to get more traffic to your website.
Before you install: the legal bit
Google Analytics uses cookies and records IP addresses, so in the EU/EEA and UK you generally need consent before it loads. The common fix is Google Consent Mode, which defaults to “denied” and only tracks after the visitor accepts.
If you serve European visitors, handle this — a privacy policy alone isn’t enough if tracking loads unconditionally.
FAQ
How do I add Google Analytics to my website?
Create a GA4 property, copy your Measurement ID (G-XXXXXXXXXX), and paste the tracking snippet into your site’s <head> on every page — or enter the ID in your platform’s built-in Analytics field.
Where do I put the Google Analytics code?
Immediately before the closing </head> tag, on every page. Most platforms and plugins have a dedicated field, which is safer than editing templates.
How do I know if Google Analytics is working?
Open your site and check Reports → Realtime in Analytics. You should see yourself as an active user within about 30 seconds.
Why does GA4 show fewer visitors than my ad platform?
Because ad blockers and cookie-consent rejections stop the tracking script loading. It’s expected — not a tracking bug.
How long until I see data in Google Analytics?
Realtime works instantly. Standard reports can take 24–48 hours to fully process.
Related guides
EmDash vs WordPress (Which Should You Use in 2026?)
EmDash vs WordPress compared — Cloudflare’s Astro-based CMS (now at 1.0) versus the 20-year-old giant. Security, plugins, migration, and who should switch.
How to Build an Online Store (Beginner's Guide)
Start an online store step by step — pick a platform, add products, set up payments, and launch. Shopify, WooCommerce, and free options.
How to Choose a Domain Name (10 Rules for a Great One)
Choose the best domain name — short, brandable, and easy to say. Rules, tools, and mistakes to avoid, plus what to do if yours is taken.