SEO check

How to Add Google Analytics to Website: GA4 Guide

Install the GA4 tag on every page, confirm data arrives and see exactly how our free report decides whether Google Analytics is detected.

Free to use 14 min read Updated Oct 2026

Add Google Analytics to your website: the quick answer

Quick answer: To add Google Analytics to website pages, you put the Google tag, a short script that carries your Measurement ID (G- followed by letters and digits), on every page so each visit is sent to your GA4 property. Our report passes the site when it finds window.gtag, window.ga or window.dataLayer once the page HTML has been parsed.

  • Pass: at least one of window.gtag, window.ga or window.dataLayer exists once the page HTML has been parsed, so the row turns green.
  • Fail: none of the three exists at that moment, either because no tag is installed or because it is added too late for the check to see.
  • Fix: paste the tag high in the head of every page, or type the G- ID into the tracking field of your site builder.

Check my website

One honest timing note before you panic. Google says data collection can take up to 30 minutes to begin after a new install, so open the Realtime report and look for your own visit before you decide the setup failed.

What it means to add Google Analytics to a website

Three separate pieces make up a working setup: a Google Analytics account that holds a GA4 property, a web data stream inside it that represents your domain, and the Google tag running on your pages. Visitors' browsers only ever see the last piece.

Keep the three ID formats apart, because people mix them up. The G- ID is the GA4 Measurement ID, and it is the one you paste into the tag or into a builder field. A GTM- ID belongs to a Google Tag Manager container, which is a different product. A UA- ID belonged to Universal Analytics, whose standard properties stopped processing hits on July 1, 2023, so an old UA snippet on a standard property collects nothing today.

You can paste the Google tag (gtag.js) yourself, or install a Tag Manager container once and manage every tag from its web interface.

In the browser, two inline lines create window.dataLayer and window.gtag, the library loaded from googletagmanager.com reads that queue, and each page view is sent to Google. By default GA4 also sets a first party _ga cookie that lasts two years.

Why add Google Analytics (and what it will not do for rankings)

Analytics shows which pages draw visits, which channels send them and where people leave. Before you rewrite titles or change content, you need a baseline to compare against, and the cheapest way to start collecting one is to install Google Analytics now, before anything else changes.

It will not move your rankings. Google publishes a ranking systems guide that lists the systems it uses to order results, such as link analysis and RankBrain, and analytics data is not among them. The tag changes what you can measure, not where you appear.

The standard version is free, and the one real cost is a little extra JavaScript on each page, which is why the steps below keep the async loader exactly as Google ships it.

How SEO Site Checker tests for Google Analytics

This is not an HTML scan. Our audit opens your URL again in headless Chromium, waits only until the DOMContentLoaded event and then asks the page one question. If that navigation fails, it retries once with the full load event, allowing 15 seconds per attempt.

The exact rule: after navigation, the report evaluates whether any of window.ga, window.gtag or window.dataLayer is set. It does not read your HTML source, watch network requests, inspect cookies or check the ID.

A normal GA4 tag passes, and so does a Tag Manager container with no Analytics tag inside, an old analytics.js stub with a UA ID, or an empty dataLayer array made by an unrelated script. Timing is where the check turns strict. In our fixture tests a tag defined in the head or on DOMContentLoaded passed, while one added by a two second timer failed, so a consent tool, delay JavaScript plugin or late Tag Manager trigger can fail a site that does track visitors.

Matomo and Plausible failed because they define none of the three globals. A page with only the async gtag.js script tag and no inline lines also failed, because the library was still loading when DOMContentLoaded fired. That setup is a race, not a sure fail.

What is on the pageDetected by our report
GA4 tag in the headYes
Google Tag Manager containerYes
Old analytics.js with a UA IDYes
Empty dataLayer array onlyYes
Tag added after 2 secondsNo
Async gtag.js script tag onlyUnreliable, failed in our test
Matomo or PlausibleNo

A failed row counts against the score, which is the share of passed checks among all counted checks, and the status is never a warning. A page that does not finish loading within 15 seconds on either attempt fails too. A login wall, geo block or bot challenge fails because the checker sees that other page, which has no tag.

  • Pass: one of the three globals exists when the check runs.
  • Fail: none exists, or no usable page loaded.
  • Not tested: the ID itself, whether hits reach your property, and duplicate tags.

Why a pass is not proof that data arrives

A typo in the ID, or a tag that belongs to the wrong property, still turns the row green. Only the Realtime report shows whether hits really arrive.

Run the free SEO report

How to add Google Analytics to your website step by step

These steps show how to add Google Analytics to website pages the way Google documents it, so you can set up Google Analytics cleanly. If a screen in your account looks slightly different, trust Google's own wording, because the interface changes more often than the underlying tag.

  1. Create the property. Open analytics.google.com, create an account if you have none, then add a GA4 property with a name, time zone and currency. Choose Web as the platform and enter your domain, which creates the data stream.
  2. Copy your ID and snippet. In Admin, open Data streams and select your web stream. The Measurement ID sits in the stream details, and under Google tag, View tag instructions, then Install manually, Google shows the full snippet.
  3. Paste it into the head. Place the snippet, which is your tracking code, immediately after the opening head tag on every page. A shared header template is the safest single location, because you edit one file instead of fifty.
  4. Publish and clear caches. Purge the cache plugin, the CDN and any server cache so visitors and our test receive the new HTML.
  5. Confirm the data. Visit the site in another tab and look for yourself in the Realtime report, as described below. If your visit appears in Realtime, the tag works and every page that shares the template is covered. If it does not, check the cache step and the ID before touching anything else.

Google's GA4 setup guide covers the property and data stream screens and the Install manually path.

Option A: paste the Google tag yourself

This route needs access to your HTML or theme files, and the inline script is what makes the globals exist early. On a static HTML site, put the snippet in the shared include or layout. On PHP or template driven sites, add it to the header partial that every page uses, so a single edit covers the whole site.

Keep exactly one copy of the Google tag per page, with the async attribute on the loader line, because two GA4 copies count every page view twice. Delete any old UA analytics.js block instead of leaving it beside the new tag. It collects nothing today, it adds weight, and it keeps our check green even if the new tag is broken. On a single page app, put the snippet in the root index or layout, then check in the web stream that the Enhanced measurement toggle is on and that page changes based on browser history events are enabled. Click through two routes and watch Realtime.

Option B: use Google Tag Manager

Create a web container (the GTM container) and paste its snippet as high in the head as you can, with the noscript part right after the opening body tag. Container IDs start with GTM-, which is not your G- Measurement ID. Inside the container, add a Google tag that carries your G- ID and fire it on the Initialization All Pages trigger, which runs earlier than the plain All Pages trigger (All Pages also works). Test in Preview mode, then publish.

Our check passes the moment the container loads, even before the Google tag inside it is published, so confirm in Realtime too.

The GA4 snippet explained line by line

This is the standard structure of the Google tag, with a placeholder where your own ID goes. Copy the current version from your own install page rather than from this article, because Google may change it.

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

The async script loader fetches the library from googletagmanager.com without blocking the page. The dataLayer array is the queue, and the gtag function pushes whatever you give it into that queue. The config call starts measurement for your ID and records the page_view event.

Notice why our check passes. The inline lines define window.dataLayer and window.gtag while the HTML is still being parsed, before DOMContentLoaded and before the remote library finishes downloading. That is also why a partial paste is dangerous: copy only the first line and nothing defines the globals early. Google describes the placement on its Google tag install guide.

Add Google Analytics to WordPress, Shopify, Wix and other platforms

Most site owners who add Google Analytics to website builders never touch code, so the route depends on the platform. Google lists the steps for each content management system on its own setup page, which beats any menu path quoted here, because those labels change. Whatever the route, the goal is the same: the Google Analytics 4 tag must load on every page.

Platform typeUsual routeWhat you paste
WordPressSite Kit by Google plugin, or the theme headerNothing with the plugin, or the full snippet
Wix, Squarespace, GoDaddy, WeeblyAnalytics or tracking field in site settingsOnly the G- Measurement ID
ShopifyGoogle sales channel appUsually a connected account, not an ID field
Webflow and similar buildersCustom code area in project settingsThe full snippet or the ID
Static HTML, Hugo, AstroShared layout or base templateThe full snippet in the head
Next.js, React, AngularRoot layout or index headThe full snippet, then test route changes

On WordPress the simplest path is the official Site Kit by Google plugin, which connects your Google account through a guided setup with no code edit. If you prefer to edit the theme, find out which one you run first with the WordPress theme detector, and use a child theme so an update does not erase your change. Without a plugin, hook a small function onto wp_head in that child theme, so the snippet prints in the head of every page. Pasting it into a parent theme file is the mistake to avoid, because the next update overwrites it.

Hosted builders usually ask for the G- ID alone, so copy it from the data stream details first. Shopify normally connects through its Google sales channel app instead, so follow the prompts there rather than hunting for a paste box.

How to check that Google Analytics is working

  • Look at the source or the Console. Use view page source and search for your G- ID, or run !!(window.ga || window.gtag || window.dataLayer) in the browser Console, which is the same expression our report evaluates and prints true when any of the three exists. A Console run happens after loading finishes, so a late tag can read true there and still fail in the report.
  • Watch Realtime. Open your site in another tab and look for yourself in the Realtime report. Realtime normally shows hits within a few minutes.
  • Use Tag Assistant or the Network tab. Connect your URL in Tag Assistant and look for your ID under Google tags found. In Chrome DevTools, filter the Network tab for collect and look for a g/collect request that carries your ID.
  • Be patient with reports. Standard reports lag behind Realtime, roughly 2 to 6 hours for intraday and about 12 hours for daily data in a typical standard property, so judge only after a day or two. An ad blocker hides your own visits, so test in a clean profile.
  • Finish with the report. Run our free report and look for the green row. It confirms that the globals exist at the moment of the check; it does not confirm the ID, so keep the Realtime result as your proof.

Why Google Analytics is not detected on your site

If the report says Google Analytics was not detected, work down this list. Start with the quickest checks and work toward the slower ones.

  • The tag is on the wrong template. The home page has it, but the URL you tested is a landing page builder page, a subdomain or a checkout with another template, and the check tests exactly the URL you enter.
  • The tag loads too late. Consent tools, delay JavaScript plugins and late Tag Manager triggers push the globals past the check (see the timing note above). Keep the two small inline lines for dataLayer and gtag in the head. If your rules require the library itself to wait for consent, delay only the async loader line until consent is given; the globals still exist, so the check passes, and nothing is sent early.
  • The paste was partial. The async script tag is there but the inline lines after it are missing (see the snippet section).
  • An old UA snippet is installed. It still passes our check but has collected nothing on a standard property since July 1, 2023. Replace it with the Google tag.
  • Cached HTML is being served. A page cache or CDN still delivers the version without the tag. Purge everything and test again.
  • The page sits behind a gate. A login, geo block or bot challenge means the headless browser sees a different page, which has no tag, or never finishes loading within 15 seconds.
  • It passes here but shows no data. If you see Google Analytics not working or no data in Realtime despite a green row, check the ID for typos and confirm you copied it from the right property. Also look for a duplicate tag, as covered under Option A.

Good habits after you add Google Analytics

  • Keep it light. Use one copy and the async loader. If page load time or main thread work grows after the install, check JavaScript execution time and render blocking resources to find the cause.
  • Respect consent. If visitors come from regions with consent rules such as GDPR and the ePrivacy Directive, use a cookie banner together with Google consent mode instead of removing the tag, and ask a qualified adviser about your own duties. This is not legal advice.
  • Do the housekeeping. Add an internal traffic filter so your own visits stay out of the numbers, and link Google Search Console to see the queries behind organic visits. Mark actions that matter, such as a form submit, as key events. Keep a separate staging property so test traffic never pollutes production data.

How to Fix

The short version, the same steps you see when you click How to Fix in your report.

Why this fails: our report found none of window.gtag, window.ga or window.dataLayer once the page HTML finished loading. Either no tracking tag is installed, or it is added too late for the check to see.

It is worth fixing because without a tag you have no record of visits, sources or popular pages. Installing it does not change rankings, so the gain is measurement, and the tag costs nothing.

How to fix it:

  1. Create a GA4 property with a web data stream and copy the Measurement ID, which is G- plus letters and digits.
  2. Open the stream, choose View tag instructions, pick Install manually and copy the snippet.
  3. Paste it immediately after the opening head tag on every page and keep the async attribute.
  4. Publish, then clear every cache layer, including the cache plugin, the CDN and the server cache.
  5. If a consent tool or a delay JavaScript setting loads the tag late, keep the two inline lines for dataLayer and gtag in the head so the globals exist from the start.
HTML
<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>

Platform notes:

  • WordPress: use the Site Kit by Google plugin or add the snippet to the theme header.
  • Site builders: paste only the G- ID into the tracking field.
  • Tag Manager: put the container in the head and the noscript part after the opening body tag, with a Google tag for your ID inside.
  • Frameworks and static sites: add the snippet to the root layout head.

Re-test: visit your site and watch the Realtime report for your own visit, then re-run the free report and look for the green Google Analytics row. If it still fails, the tag is probably added after the page loads, or the tested URL uses another template.

Re-test my website

Frequently Asked Questions

How do I add Google Analytics to my website?
Create a GA4 property with a web data stream, copy the G- Measurement ID, then paste the Google tag right after the opening head tag on every page, or type the ID into your site builder's tracking field. Afterwards, open the Realtime report and look for your own visit. The step by step section above walks through each screen.
Where do I paste the Google Analytics code?
Paste it immediately after the opening head tag of every page, usually through one shared header template. For Tag Manager, the container snippet goes in the head and the noscript part right after the opening body tag. A footer paste with inline lines often still passes our check, but it can miss visitors who leave early.
How long does it take for Google Analytics to show data?
Expect minutes for Realtime and hours for everything else. Google gives these figures as estimates, not guarantees, and says collection may begin up to 30 minutes after install, though Realtime normally shows a visit within a few minutes. Standard reports are slower, roughly 2 to 6 hours for intraday data and about 12 hours for daily data, and Google says full processing can take 24 to 48 hours.
Where do I find my Google Analytics Measurement ID?
Open Admin, then Data streams, then select your web stream. The Measurement ID sits in the stream details and starts with G-. It is not the numeric property ID, a Tag Manager container ID that starts with GTM-, or an old Universal Analytics ID that starts with UA-, so check the prefix before you paste it.
Can I use Google Analytics on any website?
Yes, as long as you can add a script to your pages or your platform offers a Google Analytics field. A site builder without custom code access usually still has a tracking field that takes only the G- ID. A few closed platforms block both, in which case you depend on whatever integration they provide. Also check the consent rules that apply to your visitors.
Should I use Google Tag Manager or paste the gtag.js code?
Either one works. Pasting gtag.js is quicker when you only need a single tag, while Tag Manager pays off when you expect to add more tags later and want to publish changes without editing theme files. Do not run both for the same property, because each visit can then be counted twice.
Why does my SEO report say Google Analytics was not detected?
None of window.gtag, window.ga or window.dataLayer existed once the page HTML had been parsed. Typical causes are a late loaded tag from a consent tool or delay JavaScript setting, a partial paste, a different template on the tested URL, cached HTML, or a page that blocks the checker. Work through the troubleshooting list above.
Does adding Google Analytics help my SEO rankings?
No. Google does not list analytics data in its ranking systems guide, so installing the tag changes what you can measure, not where you rank. The benefit is indirect but real: you learn which pages and channels work, which content earns repeat visits and where people leave, so you can improve them with evidence instead of guesses.

See how your site scores right now

Paste your address into the free report, then use the How to Fix button on anything that needs work.

Free to use. Results in under a minute for most sites.