How to Attach Google Analytics to Website

Cody Schneider••7 min read

You’ve launched your website, but how do you know if anyone is actually visiting? To understand who your audience is, where they're coming from, and what they do on your site, you need to connect it to Google Analytics. This guide will walk you through exactly how to set up Google Analytics 4 on your website, step by step, with methods that work for any platform.

GraphedGraphed

Build AI Agents for Marketing

Build virtual employees that run your go to market. Connect your data sources, deploy autonomous agents, and grow your company.

Watch Graphed demo video

First, What Is Google Analytics (and Why Do You Need It)?

Google Analytics (GA) is a free web analytics service that tracks and reports website traffic. Think of it as the ultimate dashboard for your website's performance. It unlocks critical insights that help you make smarter decisions about your content, marketing, and overall business strategy.

Without it, you're essentially flying blind. With it, you can answer questions like:

  • How many people are visiting my site? Track daily, weekly, and monthly user counts.
  • Where are my visitors coming from? See if they found you through Google Search, social media, an email newsletter, or another source.
  • What content do they find most interesting? Find out which pages and blog posts are the most popular.
  • Are my marketing campaigns actually working? Measure the traffic and conversions generated by your specific marketing efforts.

Modern websites use Google Analytics 4, which is the latest version. It’s designed to track user journeys across both websites and apps, focusing more on user interactions (or "events") rather than just pageviews. All new setups will be on GA4, which is exactly what we'll be doing today.

Free PDF · the crash course

AI Agents for Marketing Crash Course

Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.

Step 1: Create a Google Analytics 4 Property

Before you can add Analytics to your website, you need an account and a “Property” to send your data to. If you already have a Google account (like a Gmail account), this will only take a couple of minutes.

Create Your Account and Property

  1. Go to the Google Analytics website. Navigate to analytics.google.com and sign in with your Google account. If you don't have one, you'll be prompted to create one first.
  2. Start the Setup Process. Click the "Start measuring" button. This will take you to the account creation screen.
  3. Account Setup. Give your account a name. This is the highest level of organization. If you manage multiple businesses, you might want to use your business name here. For most people, simply using your website or company name is perfect. Leave the data sharing settings as they are and click "Next."
  4. Property Setup. Now, enter a name for your Property. Again, your website's name is a good choice. Set your reporting time zone and the currency your business operates in. Then click "Next."
  5. About Your Business. Google will ask for some optional information about your business, like your industry and company size. Choose the options that best fit. This helps Google provide you with more relevant benchmark data. Click "Next."
  6. Choose your business objectives. Select the goals that are most important to you, like "Generate leads" or "Drive online sales." If you’re not sure, you can select "Get baseline reports." Finish by clicking "Create." Accept the terms of service to proceed.

Set Up Your Web Data Stream

Your GA4 Property is now ready. The very next step is to create a "Data Stream." This is simply the source of data for your property - in our case, your website.

  1. Choose a Platform. You'll be prompted to "Choose a platform." Select "Web."
  2. Enter Your Website Details. In the "Website URL" field, type your domain (e.g., yourwebsite.com) and give the stream a name (e.g., "My Website"). Make sure to select https if your site is secure, which it should be. Click "Create stream."
  3. Find Your Measurement ID. After creating the stream, you'll see a screen with your stream details. The most important piece of information here is the Measurement ID, which looks like G-XXXXXXXXXX. This is your unique identifier. Keep this page open, you're going to need this ID or the code snippet on this page in the next step.

Step 2: Connect Analytics to Your Website

With your Measurement ID in hand, it's time to actually link Analytics to your site. There are a few ways to do this, ranging from super simple to slightly more technical. We'll cover the three most common methods.

Method 1: Use a Plugin or Native Integration (Easiest Method)

Most modern website platforms like WordPress, Shopify, and Squarespace have made this process incredibly simple. You won't need to touch any code.

For WordPress Websites

The easiest way to add GA4 to WordPress is with a plugin. We recommend using Google's official Site Kit plugin because it's free, secure, and integrates with other Google services like Search Console.

  1. In your WordPress dashboard, go to Plugins > Add New.
  2. Search for "Site Kit by Google," then click "Install Now" and "Activate."
  3. Follow the on-screen setup wizard. It will ask you to connect your Google account. Sign in with the same account you used to create your GA4 property.
  4. Site Kit will automatically detect your new GA4 property. Just confirm it, and you're done! It handles all the code placement for you.

For Shopify or Squarespace Websites

Platforms like Shopify and Squarespace have a dedicated field for your Google Analytics ID.

  1. Go back to your Google Analytics dashboard and copy your Measurement ID (G-XXXXXXXXXX).
  2. In your Shopify Admin, navigate to Online Store > Preferences.
  3. Find the "Google Analytics" section and paste your Measurement ID into the box.
  4. Click Save.

The process is very similar for Squarespace, Wix, and other popular website builders. Look for "External APIs," "Integrations," or "Marketing" in your site's settings.

GraphedGraphed

Build AI Agents for Marketing

Build virtual employees that run your go to market. Connect your data sources, deploy autonomous agents, and grow your company.

Watch Graphed demo video

Method 2: Add the Tracking Code Manually to Your Site's Header

If your website is custom-built, or if you prefer not to use a plugin, you can add the tracking code directly to your site’s HTML. It sounds technical, but it’s simpler than you think.

On the same "Web stream details" page in Google Analytics where you found your Measurement ID, look for the section called "View tag instructions". Select "Install manually." This will show you a block of JavaScript code. This is your Global Site Tag (gtag.js).

<!-- 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>
  1. Copy the Code. Click the copy icon to copy the entire code snippet.
  2. Edit Your Website's Code. You now need to access your website's source code. You're looking for the opening <head> tag. In many systems, you can edit this in a "header.php" file or a "Theme Header" section.
  3. Paste the Code. Paste your copied Global Site Tag code immediately after the opening <head> tag on every page of your website. By placing it in a shared header file, it will automatically appear across your whole site.
  4. Save Your Changes. Save the file and reload your website. Google Analytics is now active.

Free PDF · the crash course

AI Agents for Marketing Crash Course

Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.

Step 3: Verify That Google Analytics Is Working

Congratulations, you’ve installed your tracking code! But how do you know if it's actually working? Here’s a quick and easy way to check.

  1. In your Google Analytics account, navigate to Reports > Realtime.
  2. Open a new browser window (ideally an incognito or private window) and go to your own website.
  3. Switch back to the Google Analytics Realtime report. Within a minute or two, you should see at least one user appear on the report card labeled "Users in last 30 minutes.”

If you see that number jump from 0 to 1, it means Analytics is successfully tracking your visit. Your setup is a success! Keep in mind that it can take 24–48 hours for more detailed data to start populating your standard reports, but the Realtime view gives you immediate confirmation.

Final Thoughts

You’ve successfully connected Google Analytics to your website, unlocking a world of data that will help you grow your audience and your business. Now you know how to create a GA4 property, connect it to your site using several different methods, and verify that it’s tracking visitor data correctly.

Once you start collecting data, the next step is making sense of it all. Diving into GA4 reports can feel overwhelming when all you want are straightforward answers to your business questions. That's why we created Graphed. We turn hours of data analysis into quick conversations by allowing you to connect sources like Google Analytics and ask questions in plain English, instantly generating the real-time dashboards and reports you need to make better decisions faster.

Related Articles