How to Add Google Analytics to Website: A Complete Setup Guide

how to add google analytics to website

Learning how to add Google Analytics to website is one of the first things any site owner should do — without it, you’re running a business or blog with zero visibility into who’s actually visiting, what they’re clicking, or where they’re dropping off.

Google Analytics 4 (GA4) is the current version of Google’s free analytics platform, and it replaced the older Universal Analytics, which stopped collecting new data back in mid-2023. This guide walks through the complete setup process step by step, whether you’re adding it to a custom-coded site, a WordPress blog, or a site builder like Shopify or Squarespace.

What Is Google Analytics, and Why Add It to Your Website?

Google Analytics is a free tool that tracks visitor behavior on your website — how many people visit, which pages they view, how long they stay, and what device or location they’re browsing from.

Once installed, it answers questions like:

  • Which pages get the most traffic?
  • Where are visitors coming from (search, social media, direct links)?
  • What percentage of visitors leave without taking any action?
  • Which marketing campaigns actually drive results?

Without this data, you’re making decisions about your website based on guesswork instead of real visitor behavior.

Before You Start: What You’ll Need

  • A Google account (a business Gmail account is recommended over a personal one, if you have one)
  • Admin access to your website’s backend (WordPress dashboard, Shopify admin, or direct code access)
  • A few minutes — the core setup takes less than 15 minutes for most sites

Step 1: Create a Google Analytics Account

  1. Go to analytics.google.com and sign in with your Google account.
  2. If this is your first time using Analytics, you’ll be prompted to create an account directly. If you already have an account, click the Admin gear icon in the bottom-left corner.
  3. Click Create, then choose Account.
  4. Name the account after your business or organization (for example, “Bright Horizon Media”).
  5. Review the data-sharing settings — the defaults are fine for most users unless you have a specific compliance reason to change them.

An account in Google Analytics is the top-level container — you can have multiple websites (properties) organized under a single account.

Step 2: Create a GA4 Property for Your Website

A property represents one specific website or app you want to track.

  1. Still in the Admin section, find the Property column and click Create Property.
  2. Enter a property name — typically your website’s name (for example, “adhurl.com – Main Site”).
  3. Set your reporting time zone and currency. This matters more than it seems: changing it later can affect how your historical data gets grouped into reporting periods.
  4. Click Next, and answer the short business details questions (industry category, business size).
  5. Select your business objectives, or choose “Get baseline reports” to keep things simple if you’re just getting started.
  6. Click Create to finish setting up the property.

Step 3: Set Up Your Web Data Stream

A data stream is the specific source sending data into your property — in this case, your website.

  1. After creating the property, you’ll be prompted to set up a data stream. Choose Web.
  2. Enter your website URL and give the stream a clear name (for example, “Main Website”).
  3. Under Enhanced Measurement, review the toggles — this feature automatically tracks common interactions like scrolls, outbound clicks, and file downloads without extra setup. Leave it on unless you have a specific reason to disable certain events.
  4. Click Create stream.

Once the stream is created, you’ll land on the Web stream details page, showing your Measurement ID — a code starting with G- followed by letters and numbers. This ID is what connects your actual website to this specific GA4 property, so keep this page open or copy the ID somewhere safe.

Step 4: Add the Google Analytics Code to Your Website

This is the step that actually connects your live website to the property you just created. The right method depends on how your site is built.

Option A: Using a Website Builder or CMS (Easiest)

Many platforms — including WordPress, Shopify, Wix, and Squarespace — have a dedicated field for your Measurement ID or built-in Google Analytics integrations.

  1. Find your platform’s Analytics or Tracking settings (usually under Settings or Marketing).
  2. Paste your Measurement ID (the G-XXXXXXX code) into the designated field.
  3. Save your changes.

This is the simplest path since the platform handles inserting the tracking code correctly across every page for you.

Option B: Manually Adding the Gtag Code

If you’re working with a custom-coded website, you’ll add the Google tag (gtag.js) — the direct tracking snippet — into your site’s code.

  1. On the Web stream details page in Google Analytics, click View tag instructions, then Install manually.
  2. Copy the provided code snippet, which looks similar to this:

<!– Google tag (gtag.js) –>

<script async src=”https://www.googletagmanager.com/gtag/js?id=G-XXXXXXX”></script>

<script>

  window.dataLayer = window.dataLayer || [];

  function gtag(){dataLayer.push(arguments);}

  gtag(‘js’, new Date());

  gtag(‘config’, ‘G-XXXXXXX’);

</script>

  1. Paste this code into the <head> section of every page you want to track — ideally through a shared header template or layout file, so you don’t have to add it manually to each individual page.

Option C: Using Google Tag Manager (Best for Long-Term Flexibility)

Google Tag Manager (GTM) is a separate free tool that lets you manage multiple tracking codes and events through one dashboard, without editing your website’s code every time you make a change.

  1. Create a GTM container for your site at tagmanager.google.com.
  2. Inside GTM, create a new tag, choosing Google Tag as the tag type.
  3. Paste your Measurement ID into the tag configuration.
  4. Under Triggering, select All Pages, so the tag fires on every page load.
  5. Publish the container.
  6. Add the GTM snippet itself (provided when you create your container) into your site’s code — this is typically the only manual code change you’ll need to make going forward, since future tracking updates can be managed inside GTM without touching your site’s code again.

This method takes slightly longer to set up but pays off if you plan to add more tracking (button clicks, form submissions, conversion events) later.

Comparing the Installation Methods

MethodBest ForSetup DifficultyFlexibility Later
Website builder/CMS fieldBeginners, WordPress, Shopify, SquarespaceVery easyLimited to built-in options
Manual gtag.js codeCustom-coded websitesModerateRequires code edits for changes
Google Tag ManagerAnyone planning to add more tracking laterModerateHigh — manage everything from one dashboard

Step 5: Verify the Tracking Is Working

After adding the code, confirm data is actually coming through before assuming everything’s connected correctly.

  1. In Google Analytics, go to Reports, then Realtime.
  2. Open your website in a separate browser tab.
  3. Check whether your visit appears as an active user in the Realtime report within a minute or two.

If nothing shows up, double-check that the Measurement ID matches exactly, and that the tracking code is placed correctly in the page’s <head> section, not somewhere it might get blocked or stripped out.

Common Mistakes to Avoid

  • Pasting the tracking code in the wrong place. The code needs to be in the <head> section of every page, not just the homepage.
  • Using the wrong Measurement ID. If you have multiple properties or streams, it’s easy to accidentally copy the wrong G-XXXXXXX code.
  • Forgetting to verify with the Realtime report. Many people assume setup worked without ever confirming data is actually flowing in.
  • Setting up multiple conflicting tracking codes. Installing GA4 through both a CMS plugin and a manual code snippet can create duplicate or conflicting tracking.
  • Changing the reporting time zone after data collection has started. This can cause confusing gaps or shifts in how existing data is grouped into daily or monthly reports.
  • Expecting instant data. New properties typically need up to 24 hours before reports outside the Realtime view populate fully.

Best Practices for a Clean Google Analytics Setup

  • Use a business Google account for Analytics access, rather than a personal one, especially if multiple team members need access later.
  • Set up Google Tag Manager from the start if you expect to track more than just basic page views — it saves significant time later.
  • Test on a staging or sandbox version of your site first if you’re technically comfortable doing so, to confirm tracking works before rolling it out to your live audience.
  • Review your Enhanced Measurement settings once traffic starts coming in, and disable any specific automatic events that aren’t relevant to your site.

Frequently Asked Questions

How do I get Google Analytics for my website for free? Google Analytics 4 is free for standard use. Simply create an account at analytics.google.com, set up a property and web data stream for your site, and add the provided tracking code — no payment is required for the core features most websites need.

How long does it take for Google Analytics data to show up after installation? The Realtime report typically shows activity within a minute or two of a valid visit. Standard reports outside of Realtime can take up to 24 hours to fully populate with data.

Do I need Google Tag Manager to use Google Analytics? No. You can add the Google tag (gtag.js) directly to your site’s code, or use a built-in field in your website builder. Google Tag Manager is optional but useful if you plan to track additional events beyond basic page views.

Can I add Google Analytics to a WordPress site without coding? Yes. Most WordPress themes and plugins offer a dedicated field where you paste your Measurement ID, avoiding any direct code editing.

Is Google Analytics 4 the same as Universal Analytics? No. Universal Analytics (the older version, sometimes called GA3) stopped processing new data in mid-2023. GA4 is the current version and the only one actively collecting new website data today.

How do I know if Google Analytics is correctly installed on my site? Open your website in a browser tab, then check the Realtime report inside Google Analytics. If your visit shows up as an active user within a minute or two, tracking is working correctly.

Final Thoughts How to Add Google Analytics to Website

Learning how to add Google Analytics to website setup comes down to four core steps: creating your account and property, setting up a web data stream to get your Measurement ID, adding that tracking code to your site through whichever method fits your platform, and confirming it’s working through the Realtime report.

Once installed, resist the urge to check obsessively during the first 24 hours — give the data time to populate, then come back and start exploring where your real traffic is actually coming from.