How to set up Google Analytics (GA4) for your website — Step by step

This complete, practical guide shows you how to create a Google Analytics account using Google Analytics 4 (GA4), add a web data stream, install the tracking tag (both direct gtag.js and Google Tag Manager methods), verify data collection, and configure key settings like conversions, audiences, privacy and integrations.

Why GA4 (short)

Google Analytics 4 (GA4) is the current analytics platform from Google. It uses an event-based model (instead of the older session-based Universal Analytics), supports cross-platform measurement, and offers deeper integrations with Google products. If you previously used Universal Analytics (UA) you should move to GA4 so your website keeps collecting data natively in the new platform.

Quick fact: GA4 is the actively supported analytics platform. When setting up a new implementation you should use GA4 and its measurement ID (a value that begins with G-).

Before you start — quick checklist

  • A Google account (Gmail or Google Workspace) with permission to create Analytics accounts.
  • Access to your website HTML or CMS (to paste the tag) or access to the site's Google Tag Manager container.
  • If you use a CMS (WordPress, Shopify, Wix, etc.) check whether there's a plugin or native integration for GA4.
  • Your organization's privacy requirements (GDPR, CCPA) and decision on Consent Mode / cookie banners.

Step 1 — Create or choose a Google account

  1. If you already have a Google account (Gmail or Google Workspace), you can use it. Otherwise, create one at accounts.google.com.
  2. Tip: For businesses it's common to use a shared Google Workspace account or an email like analytics@yourdomain.com so ownership is not tied to a single personal account.

Step 2 — Create an Analytics account and GA4 property

Open Google Analytics and sign in with the Google account you chose.

  1. In the bottom-left, click the Admin (gear) icon.
  2. Under the Account column, click Create account (or choose an existing account if you want to add a property under an existing account).
  3. Enter an account name, choose data-sharing settings, then click Next.
  4. Under Property setup, click Create property. Give it a descriptive name (e.g., "YourSite.com - Web"), select your reporting time zone and currency.
  5. When prompted, choose the property type: select Web (or configure streams for apps if you measure apps too). This process will create a GA4 Property and allow you to add a Web data stream.

If you're migrating from Universal Analytics, consider keeping the old UA property (for historical data) and create a new GA4 property for future data collection.

Step 3 — Create a Web Data Stream & get the Measurement ID

Each GA4 property uses one or more data streams. For a website create a Web data stream and copy the Measurement ID.

  1. In Admin > Property > Data Streams, click Add stream > Web.
  2. Provide your website URL and a stream name. Click Create stream.
  3. After creating the stream you'll see the Measurement ID in the format G-XXXXXXXXXX. Copy this — you'll use it in your tag. (Keep it private — it identifies the destination of your data.)

Step 4 — Install the Google tag (two recommended methods)

You have two common options to add GA4 to your website:

  1. Direct install with the Global site tag (gtag.js) — simple and quick for plain websites and for developers who edit site HTML.

    To use this option, paste the following snippet into the <head> of every page you want to track. Replace G-XXXXXXXXXX with your measurement ID.

    <!-- Global site tag (gtag.js) - Google Analytics -->
    <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>

    This snippet will send basic page_view events automatically. For more customization you can call gtag('event', ...) or integrate with Tag Manager.

  2. Install via Google Tag Manager (recommended for complex sites) — GTM allows non-developers to add and manage tags without editing site code after initial GTM installation.
    1. Create a Tag Manager account at tagmanager.google.com and make a container (usually for web).
    2. Add the GTM container snippet to your site (one in the <head> and one immediately after <body>), then publish the container.
    3. Inside GTM create a new tag: choose Google Analytics: GA4 Configuration as tag type and paste your Measurement ID (G-...); set Trigger to All Pages and Save & Publish.

    Using GTM makes it easy to add additional GA4 event tags, track clicks, form submissions, ecommerce events, and to test before publishing.

CMS-specific tips

  • WordPress: Use a GA4 plugin (e.g., "Site Kit by Google" or GA4 integration plugins) or paste the gtag snippet into the header. If using a theme, add code in header.php or via a header insertion plugin.
  • Shopify / Wix / Squarespace: Most platforms have a dedicated GA/Analytics field in settings to paste the Measurement ID or a plugin/integration.

Step 5 — Verify installation (Realtime & Debug)

After installing the tag:

  1. Open the GA4 property and go to Reports > Realtime. Visit your site in another tab or device — you should see active users and page_view events within seconds.
  2. Use DebugView (Admin > DebugView in GA4) to see events from an instrumented browser (enable debug mode using the GA Debugger extension or add ?gtm_debug=x to your URL when using GTM).
  3. Install the Chrome extension Tag Assistant (by Google) to inspect which Google tags are firing on a page and to troubleshoot common issues.

Step 6 — Configure essential settings

  1. Enhanced measurement: In the Web data stream settings enable enhanced measurement to automatically collect scrolls, outbound clicks, site search, video engagement and file downloads — this reduces manual tagging for common events.
  2. Data retention: Go to Admin > Property > Data Settings > Data Retention to set how long user-level data is retained. Pick a period that suits your compliance requirements.
  3. Reporting identity: Choose how Analytics identifies users (by device ID, user ID, or both). Configure this under Admin > Property Settings.
  4. Internal traffic filter: Create a filter to exclude internal IPs so your team's visits don't pollute analytics. In GA4 this is done via Admin > Data Streams > More Tagging Settings > Define internal traffic.

Step 7 — Events, conversions & ecommerce

GA4 measures everything as an event. Common next steps:

  • Recommended events: page_view, session_start, first_visit (auto-collected), and user interactions such as sign_up, login, file_download, purchase. You can send custom events using gtag('event', 'your_event_name', { /* params */ }) or via GTM.
  • Mark conversions: After an event appears in your Events list, flip the switch in Admin > Events to mark it as a Conversion (e.g., purchase, lead, signup).
  • Ecommerce: Implement recommended ecommerce event parameters (add_to_cart, purchase) and ensure correct currency and value fields. For complex ecommerce, use GTM or an ecommerce plugin that supports GA4.

Step 8 — Link other Google products

  1. Link Google Ads: Admin > Product Links > Google Ads > Link to import conversions and use audiences for remarketing.
  2. Link Search Console: Linking helps you see organic search queries with Analytics (Admin > Product Links > Search Console).
  3. BigQuery export: For advanced reporting and raw data access, set up the BigQuery linking (Admin > Product Links > BigQuery) to export GA4 event data automatically to a BigQuery dataset. This is useful for long-term storage and custom analysis.

Step 9 — Privacy, consent and compliance

Cookies, user privacy and legal compliance are essential:

  • Implement a cookie consent banner if required by law (GDPR, ePrivacy, CCPA). Configure your site to delay or restrict analytics until consent is given when necessary.
  • Consider Consent Mode (if you use Google Ads/gtag) so Google tags adjust behavior based on consent signals. Test thoroughly.
  • Use internal traffic filters and data retention settings to respect user privacy policies and local regulations.

Step 10 — Users, roles and access

  1. In Admin > Account & Property > Access Management you can add users and give them roles like Viewer, Analyst, Editor, or Admin. Grant the minimum permissions required for each person.
  2. Use groups (Google Workspace) to simplify multiple user management for your organization.

Troubleshooting & useful tips

  • No realtime data? Double-check the Measurement ID, ensure the tag snippet is on the page you loaded, and open Realtime reports. Some data may take a few seconds to appear.
  • Duplicate events? Check if both gtag.js and GTM are firing the same configuration tag; avoid double-tagging the same Measurement ID.
  • Test with DebugView and the Google Tag Assistant extension to inspect events, parameters and tag firing.
  • Backup historical UA data (if you still have a Universal Analytics property): export important reports and raw data before it becomes inaccessible. (If you migrated previously, keep a copy for historical comparisons.)

Printable setup checklist

  1. Create/choose Google account
  2. Create Analytics account and GA4 property
  3. Create Web data stream and copy Measurement ID (G-...)
  4. Install tag (gtag.js or GTM)
  5. Verify in Realtime and DebugView
  6. Enable Enhanced Measurement
  7. Configure events and mark conversions
  8. Link Google Ads & Search Console (if used)
  9. Implement consent/cookie banner (if required)
  10. Set user permissions and internal traffic filters

Resources & further reading

  • Official Google Analytics Help — Set up Analytics for a website and/or app (guides to create properties and streams).
  • Measurement ID & gtag.js developer docs (how to install the Google tag)
  • Google Tag Manager docs (install GA4 via GTM)