How to Add Google Analytics 4 to Website

Cody Schneider9 min read

Adding Google Analytics 4 to your website gives you the power to understand who your visitors are and how they interact with your pages. This guide will walk you through creating a GA4 property and provide three step-by-step methods to get the tracking code properly installed on your site.

GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

First, What is Google Analytics 4?

Google Analytics 4 is the latest version of Google's free web analytics service. It's built to track user behavior across websites and apps in a unified way. Unlike its predecessor, Universal Analytics (which was sunset in 2023), GA4 uses an "event-based" data model. This means that instead of just tracking pageviews, it tracks meaningful interactions - like link clicks, video plays, and form submissions - as individual events.

This new model offers several key benefits:

  • Better Customer Insights: By focusing on the entire user journey, you can see how users move from your social media ads to a blog post, and finally to a purchase.
  • Automatic Event Tracking: Many common interactions like scrolls, outbound clicks, and file downloads are tracked automatically with "Enhanced Measurement" features, requiring no extra setup.
  • Built for the Future: GA4 is designed to work with or without cookies, adapting to a more privacy-conscious web.

How to Set Up a New GA4 Property

Before you can add GA4 to your website, you need to create an "account" and a "property" within Google Analytics. The account is the highest-level folder for your business, and a property lives inside that account and holds the data from a specific website or app.

If you're brand new to Google Analytics, follow these steps to create both. If you already have an account, you can skip to step 4 to create a new GA4 property.

  1. Go to the Google Analytics homepage and sign in with your Google account.
  2. Click the gear icon in the bottom-left corner to go to the Admin section.
  3. In the Account column, click Create Account. Give your account a name (e.g., your business name) and configure the data sharing settings as you see fit. Click Next.
  4. Now you're ready to create a property. In the Property column, click Create Property.
  5. Enter a name for your property (e.g., your website's name), then select your reporting time zone and the currency your business uses. Click Next.
  6. Provide some optional details about your business category and size. This helps Google tailor your reporting experience. Click Create.
GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

Setting Up Your Data Stream

Once you've created a property, GA4 will prompt you to set up a "Data Stream." This is simply the source of your data. For a website, this is the connection that allows data to flow from your site into your GA4 reports.

  1. Choose Web as your platform.
  2. Enter your website's URL (e.g., www.yourwebsite.com) and give the stream a name (e.g., "My Website Stream").
  3. Make sure Enhanced Measurement is turned on. This feature automatically captures important events like page views, scrolls, outbound clicks, and more, giving you valuable data right out of the box.
  4. Click Create stream.

After you create the stream, a new window will appear with your "Stream details." The most important piece of information here is your Measurement ID, which will be in the format G-XXXXXXXXXX. Keep this ID handy, as you'll need it for all installation methods.

3 Ways to Add GA4 to Your Website

Now that you have your Measurement ID, it's time to add the tracking code to your website. We'll cover the three most common ways to do this, from easiest to most flexible.

Method 1: Use a CMS Integration or Plugin (The Easiest Method)

If your website is built on a popular platform like WordPress, Shopify, Wix, or Squarespace, this is by far the simplest option. These platforms have built-in integrations or plugins that make adding GA4 as easy as copying and pasting your Measurement ID.

For WordPress Websites:

Millions of websites run on WordPress, and there are dozens of excellent plugins to connect Google Analytics. Some of the most popular and user-friendly options are:

  • Site Kit by Google: Google's official plugin for WordPress. It connects your site to several Google services (Analytics, Search Console, AdSense) in just a few clicks.
  • MonsterInsights: A very popular plugin dedicated to analytics. The setup wizard is beginner-friendly and guides you through authenticating your Google account.
  • GA Google Analytics: A lightweight and simple plugin that lets you paste your Measurement ID directly.

Here’s the general process for using a plugin:

  1. From your WordPress dashboard, go to Plugins > Add New.
  2. Search for your chosen analytics plugin (e.g., "Site Kit by Google").
  3. Click Install Now, and then Activate.
  4. Follow the plugin's setup prompts. This usually involves clicking a button to connect your Google account and then selecting the GA4 property you just created from a dropdown menu. The plugin handles the rest.

For Shopify Stores:

Shopify makes this process incredibly simple with a native integration.

  1. From your Shopify Admin dashboard, go to Online Store > Preferences.
  2. Find the Google Analytics section.
  3. In the text box, paste your full GA4 Measurement ID (G-XXXXXXXXXX).
  4. Click Save.

That's it! Shopify will automatically add the GA4 tracking code to all of your store's pages, including the checkout pages.

Most other hosted platforms like Squarespace and Wix offer a similar experience, with a dedicated field in their settings to paste your Measurement ID.

GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

Method 2: Use Google Tag Manager (The Most Flexible Method)

Google Tag Manager (GTM) is a free tool that acts as a middleman between your website and third-party scripts like Google Analytics. Instead of adding multiple code snippets directly to your website, you add GTM once, and then you can manage all other tags (like GA4, Facebook Pixel, Google Ads, etc.) from the GTM interface.

This is the preferred method for most marketers because it keeps your website code clean and makes it easy to add or remove tracking tags without needing a developer.

If you haven't used GTM before, here's how to set it up for GA4:

  1. Create a GTM Account: Go to the Google Tag Manager website, create an account, and set up a "container" for your website. GTM will give you two small code snippets to place on your site - one in the <head>, and one in the <body>. Follow the on-screen instructions to add them.
  2. Create a New Tag in GTM: Once inside your GTM container, navigate to Tags in the left menu and click New.
  3. Configure the GA4 Tag:
  4. Set the Trigger: A trigger tells GTM when to fire the tag.
  5. Save, Preview, and Publish: Save your new tag. Before making it live, click the Preview button in the top right. This will open your website in a special debug mode. Check that your new GA4 tag appears in the "Tags Fired" section. Once you've confirmed it's working, return to GTM, click Submit, and then Publish to apply the changes to your live site.

Method 3: Add the Tracking Code Directly to Your Site's HTML (The Manual Method)

This old-school method involves manually placing the GA4 code snippet (known as the global site tag or gtag.js) into the HTML of your website. This approach should only be used if you can't use a CMS plugin or Google Tag Manager.

Warning: Be careful when editing your website's theme files. An error could break your site. It's always a good idea to create a backup first.

  1. Find Your Code Snippet: Return to your Google Analytics property. Go to Admin > Data Streams and click on your web stream. Under "Installation instructions," select Install manually. This will reveal a JavaScript code block.
  2. Copy the Code: Click the copy icon to copy the entire gtag.js snippet.
  3. Paste the Code into your Website's Head: You need to paste this code immediately after the opening <head> tag on every page of your website. If you're using a theme where you can edit the header.php file (common in WordPress), that's the place to do it. Some themes also have a built-in feature in the theme options for adding scripts to the header.

The main downside of this method is that every tracking script you add will bloat this file, and any changes to the code require you to repeat the process.

GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

How to Check if GA4 Is Working Correctly

After you've installed the tracking code, it's a good practice to verify that it's actually working and sending data correctly.

Check the Realtime Report

The easiest way to check is to use the Realtime report in GA4 itself.

  1. Open your Google Analytics property and navigate to Reports > Realtime.
  2. In a separate browser window, visit your own website.
  3. Within 30-60 seconds, you should see your visit appear in the Realtime report, confirming that Google Analytics is successfully tracking your activity.

Use the Google Tag Assistant

For a more technical check, you can use the free Google Chrome extension called Tag Assistant Legacy. After installing it on your browser, navigate to your website and enable the extension. It will scan the page for Google tracking tags and show you a report indicating whether your GA4 tag was found and if it fired correctly.

Final Thoughts

Whether you used a simple plugin, the flexible Google Tag Manager, or added the code manually, getting Google Analytics 4 installed is a fundamental step toward making data-driven decisions for your business. Once data starts flowing, you can begin analyzing traffic sources, understanding user engagement, and measuring conversions.

Setting up GA4 is the first step, but transforming that raw data into clear, actionable insights is the real goal. Manually checking reports across multiple marketing tools can be draining on your time and energy. As you start connecting your marketing channels, we built Graphed to do the heavy lifting for you. Simply connect your sources like Google Analytics, and use natural language to create live reports and get instant answers without ever getting lost in menus and configs again.

Related Articles