Home / Fix guides / Analytics, cookies and GDPR

How to install Google Analytics 4 on your website

If GA4 shows no data, the tracking code is probably missing from your pages. Create a GA4 property, copy its Measurement ID (it starts with G-), and add it to every page using your platform's setting, a code snippet or Google Tag Manager.

GA4 can only report on visits it can see. If the tracking code is not on your pages, your reports stay empty: no visitors, no page views, no enquiries. Installing it takes about 15 minutes once you know which method your website uses.

What the problem is

GA4 tracking code is a small piece of JavaScript, called the Google tag, that loads on each page and sends visit data to your Google Analytics account. When it is missing, you will usually see one of these:

  • The Realtime report shows zero users even when you are browsing your own site.
  • Reports stop at a certain date, for example the day you redesigned the site.
  • Under Admin, then Data streams, GA4 says data collection is not active.
  • Your site only has old Universal Analytics code (IDs starting with UA-), which stopped processing data in July 2023.

Common causes are that Analytics was never set up, the code was lost in a redesign, theme change or migration, it was added to only some pages, or a cookie banner or privacy plugin blocks it for everyone.

Why it matters

Without analytics you are guessing. You cannot see which pages bring visitors, whether Google search, social media or email sends the people who actually enquire or buy, or whether money spent on ads is worth it. GA4 does not directly change your Google rankings, but it is how you find out what is working.

There is also a trust and legal side. For visitors in the EU and UK, analytics cookies generally need consent before they are set. So the goal is not just to get GA4 installed, but installed so it respects the visitor's choice.

How to check if your site has it

All of these are free:

  1. View the page source. Open your site, press Ctrl+U (or right-click and choose View page source), then search for G- and googletagmanager.com. A line containing gtag/js?id=G- means the Google tag is there. Only UA- or analytics.js means old code. A GTM- ID means Google Tag Manager is installed and GA4 should be set up inside it.
  2. Use the Realtime report. Open your site in a private window, accept the cookie banner if there is one, then open GA4 and go to Reports, then Realtime. You should appear within a minute or two.
  3. Use Tag Assistant. Go to tagassistant.google.com, enter your address and see which Google tags it finds.
  4. Check the Network tab. In your browser's developer tools, filter by collect. A request to google-analytics.com/g/collect means data is being sent.

Ad blockers and privacy browsers can hide GA4 from your own tests, so switch them off while checking. Check more than the home page: a product page, a blog post and the contact page.

How to fix it

First create the property. Sign in at analytics.google.com, open Admin, create a GA4 property, then add a Web data stream with your site address. Copy the Measurement ID, which looks like G-XXXXXXXXXX.

Then add it to your site using one method only. Using two at once usually double counts every visit.

Option 1: your platform's built-in setting. This is the easiest route. Menu names change between versions, themes and plan levels, so look for something called Google Analytics, Integrations, Tracking or Custom code:

  • WordPress: the Site Kit by Google plugin, or an analytics or header setting in your theme.
  • Shopify: usually under Online Store, Preferences, or through the Google and YouTube sales channel.
  • Wix: usually under Marketing integrations or Settings, then Google Analytics.
  • Squarespace: usually under Settings, then Developer tools or Marketing integrations. Availability can depend on your plan.
  • Webflow: usually under Site settings, then Integrations. Custom code needs a paid site plan.

Option 2: paste the Google tag. If you can edit the <head> of every page, paste the snippet from your data stream's tag instructions. It looks like this, with your own ID in place of the X characters:

<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>

In a theme or template, put it in the shared header file so it appears on every page.

Option 3: Google Tag Manager. If your site already uses Tag Manager, or you expect to add more tracking later, add a Google tag (called a GA4 Configuration tag in older containers) with your Measurement ID there and publish the container. Our Google Tag Manager guide walks through it.

If you have visitors in the EU or UK, make sure the tag waits for consent. That usually means connecting your cookie banner to Google consent signals. See Google Consent Mode v2 missing for what to look for.

How to confirm the fix worked

  1. Open your site in a private window and accept cookies if asked.
  2. Browse two or three pages.
  3. In GA4, open Reports, then Realtime. You should see yourself, and the pages you visited.
  4. Run Tag Assistant again and check that the GA4 tag fires once per page, not twice.

Realtime updates quickly, but the standard reports can take 24 to 48 hours to fill in. If Realtime stays empty after you have checked the ID and the placement, read GA4 not showing any data for the next things to try.

How to stop it coming back

Most tracking problems return after a change to the site, not by themselves. A few habits help:

  • Write down your Measurement ID and which method installs it (plugin, theme setting, snippet or Tag Manager).
  • Re-check Realtime after every redesign, theme switch, platform migration or major plugin update.
  • Keep one installation method, and remove old UA- code and duplicate snippets.
  • Make sure at least two trusted people have access to the Analytics account, so it does not depend on a former developer's login.
  • Look at your reports monthly. A flat line is easy to spot early.

SiteMonday checks this in week 38, the analytics setup check, and the written report ranks what it finds. It finds and explains the problem. Adding the code is up to you or your developer.

Step by step for your platform

Questions

Where do I find my GA4 Measurement ID?

In Google Analytics, go to Admin, then Data streams, and click your web stream. The Measurement ID is shown at the top right and starts with G-.

Do I need a developer to install GA4?

Often not. Many platforms and plugins let you paste the Measurement ID into a settings page. You only need a developer if you must edit theme or template files directly.

Is my old Universal Analytics code still working?

No. Universal Analytics (IDs starting with UA-) stopped processing data in July 2023, so you need a GA4 property and its G- ID.

How long until data appears after installing?

Your own visits should show in the Realtime report within a minute or two. The standard reports can take 24 to 48 hours.

Can I use both Google Tag Manager and a GA4 snippet?

You can have both on the site, but only one should send GA4 data. Two GA4 tags firing on the same page will count visits twice.

Do I need a cookie banner for GA4?

If you have visitors in the EU or UK, analytics cookies generally need consent before they are set. The exact rules depend on where your visitors are, so check your local requirements.

Related problems