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

  1. Go to analytics.google.com and sign in with a Google account.
  2. Click Admin (bottom-left).
  3. Under Account, create an account if you don’t have one. Name it after your business.
  4. Under Property, click Create Property. Give it your site’s name and set the time zone and currency.
  5. For Industry and Business size, answer honestly — it only affects reporting comparisons.
  6. Click Create, then accept the data collection terms.

Analytics creates a data stream for you.

Step 2: Get your Measurement ID

  1. Choose Web as the platform.
  2. Enter your website URL and a stream name.
  3. Click Create stream.
  4. 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:

PlatformWhere to paste it
WordPressInstall a GA plugin (MonsterInsights, Site Kit) or paste via your theme’s header settings
SquarespaceSettings → Developer Tools → External API Keys → Google Analytics
WixSettings → Advanced → Marketing Integrations → Google Tag
ShopifyInstall the Google & YouTube app, then connect your GA4 property
WebflowSite 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.

  1. Open your site in a browser.
  2. In Analytics, go to Reports → Realtime.
  3. You should see 1 active user (you) within about 30 seconds.
  4. 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

ProblemLikely cause
Realtime shows 0Snippet missing, or on some pages only
Data appears then stopsThe snippet was removed in a theme update
Only some visitors appearAd blockers and consent banners suppress tracking — this is normal
Two properties, doubled numbersSnippet 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:

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.

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.