How to Connect Google Analytics 4 to Website
Getting Google Analytics set up lets you understand how people find and use your website, providing the data you need to drive growth. This guide walks you through every step of connecting Google Analytics 4 to your site, from creating your account to making sure your data flows correctly.
What is Google Analytics 4?
Google Analytics 4 is the latest version of Google’s web analytics platform. If you've used Google Analytics before, you might remember Universal Analytics (UA), which officially stopped processing data in July 2023. GA4 is now the standard.
The biggest difference is how it measures activity. Instead of focusing on "sessions" and "pageviews" like the old version, GA4 uses an event-based model. This means everything a user does - from loading a page to clicking a link or playing a video - can be tracked as a distinct event. This approach offers a much more flexible and user-centric view of the customer journey, especially across websites and mobile apps.
For you, this means richer data. GA4 automatically tracks key actions like scrolls, outbound link clicks, and file downloads without any extra setup. Connecting it is the first essential step to making data-driven decisions for your business.
Before You Start: A Quick Checklist
Before you begin, make sure you have a couple of things ready. This will make the process much smoother.
- A Google Account: You’ll need a Google account (like Gmail) to create and log in to Google Analytics. If you don't have one, you can create one for free.
- Access to Your Website's Backend: You will need to add a snippet of code or a tracking ID to your website. This requires administrator-level access to your website's CMS (like WordPress, Shopify, or Squarespace) or access to the site's code files.
Step 1: Create a Google Analytics 4 Property
Your Google Analytics setup is organized into a hierarchy: Account > Property > Data Stream. Your Account is the top level, usually for your business. A Property is your website or app. And a Data Stream is the specific source of data flowing into your property.
First, we’ll create the account and property.
- Navigate to the Google Analytics website and log in with your Google account.
- If you’re creating an account for the first time, you’ll be taken directly to the setup wizard. If you already have a Google Analytics account, go to the Admin section (look for the gear icon in the bottom-left corner) and click Create Account.
- Account Creation: Enter an "Account Name." A good practice is to use your business name here. Review the data-sharing settings and click Next.
- Property Creation: Now, you’ll set up your property.
- Business Details: Provide some basic information about your business, like your industry category and size. This helps Google provide relevant benchmark data.
- Business Objectives: Select how you intend to use Google Analytics (e.g., "Generate leads" or "Drive online sales"). This helps tailor the reports you'll see on your dashboard. Click Create and accept the terms of service.
With your account and property now ready, you'll be prompted to set up your first data stream.
Step 2: Set Up Your Web Data Stream
A data stream is the pipeline that sends data from your website to your new GA4 property. For a website, this is called a "Web data stream."
- On the "Start collecting data" page, choose the Web platform.
- Enter your website's full URL (e.g., https://www.yourwebsite.com) and create a Stream name (something simple like "YourWebsite.com Stream" works great).
- Make sure Enhanced measurement is turned on. This is one of GA4’s most powerful features, automatically capturing common interactions like page views, scrolls, outbound clicks, site searches, and file downloads. For 99% of users, you’ll want to leave this enabled.
- Click Create stream.
After clicking, you'll land on the "Web stream details" page. Don't close this window! It contains the information you'll need for the next step: the Measurement ID and the tracking code itself.
Step 3: Add the GA4 Tracking Tag to Your Website
This is where you connect your website to Google Analytics. You need to place a tracking code on your site so it can send data to your data stream. There are a few ways to do this, ranging from very simple to more advanced. Pick the one that works best for your setup.
Finding Your Measurement ID and Global Site Tag (gtag.js)
On the "Web stream details" page, you'll see two key pieces of information:
- Measurement ID: A unique identifier that looks like
G-XXXXXXXXXX. Some platforms only need this. - Global Site Tag (gtag.js): A snippet of JavaScript code. This code is what actually does the tracking. Find it under the "Install manually" tab.
Method 1: Using a Website Builder or CMS Integration (The Easy Way)
Most popular website platforms have a dedicated spot to add your Google Analytics ID, making installation quick and code-free.
- WordPress: The easiest method is to use a plugin. Popular options like Google Site Kit, MonsterInsights, or even simple header/footer script plugins allow you to paste your Measurement ID (
G-XXXXXXXXXX) into a field. Install your chosen plugin, find its settings, and paste the ID. - Shopify: In your Shopify admin, go to Online Store > Preferences. You’ll find a section for Google Analytics. Simply paste the entire Global Site Tag (gtag.js) snippet into the provided box and save.
- Squarespace: Go to Settings > Advanced > External API Keys. In the "Google Analytics" field, paste your Measurement ID. Squarespace takes care of the rest.
- Wix: In your dashboard, go to Marketing & SEO > Marketing Integrations. Under Google Analytics, click "Connect" and follow the prompts to add your Measurement ID.
Method 2: Using Google Tag Manager (The Recommended Way)
Google Tag Manager (GTM) is a free tool that acts as a container for all your tracking scripts. While it has a slight learning curve, it’s the best long-term solution. It keeps your site code clean and makes it easy to add other tools in the future without touching your website’s code again.
- If you haven't already, create a Google Tag Manager account and container for your website. Tag Manager will give you its own code snippet - you’ll need to add that snippet to your site's
<head>and<body>once. - Inside your GTM container, navigate to Tags > New.
- Give your tag a descriptive name like "GA4 - Configuration Tag".
- Click on Tag Configuration and select Google Analytics: GA4 Configuration.
- In the Measurement ID field, paste your GA4 Measurement ID (
G-XXXXXXXXXX). - Next, click on Triggering and select the All Pages trigger. This tells the tag to fire on every page of your website.
- Click Save. Finally, click the blue Submit button in the top-right corner, give your changes a version name, and hit Publish.
Method 3: Manually Adding the Tracking Code (For Advanced Users)
If you don’t use a CMS or prefer direct implementation, you can add the code manually. This method is best for static websites or custom-built platforms.
Warning: Be careful when editing your website’s code. A mistake can break your site. If using WordPress, it's highly recommended to use a child theme so theme updates don't overwrite your changes.
- From your GA4 "Web stream details" page, click "Install manually" to reveal the full Global Site Tag (gtag.js) code. Click the copy icon.
- Paste this entire code snippet immediately after the opening
<head>tag on every single page of your website.
Here’s an example of what the code looks like:
<!-- 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>Step 4: Verify Your Installation
Once you’ve added the tag, the final step is to make sure it’s working. Don’t skip this! Verification confirms you’ll be collecting accurate data from day one.
Using the GA4 Realtime Report
This is the simplest way to check your connection.
- In a new browser window or tab, open your website.
- In your Google Analytics account, navigate to Reports > Realtime.
- Within about 30-60 seconds, you should see at least one user (that's you!) on the report map and in the "Users in last 30 minutes" card.
If you see your activity, you're all set! It can take 24-48 hours for data to fully populate in standard reports, but the Realtime report confirms your connection is live and working.
Using Google Tag Assistant
For a more detailed check, especially if you're using Google Tag Manager, the Tag Assistant is an excellent tool.
- Install the free Google Tag Assistant Companion Chrome extension.
- In GA4 or GTM, find "DebugView". In your stream details, you can find the link or go to Admin > DebugView. Then you can use Tag Assistant to connect. Navigate to tagassistant.google.com.
- Click Add domain, enter your website URL, and click Connect.
- A new window of your site will open with a debug parameter in the URL. As you click around your site, you’ll see the events firing in the Tag Assistant window in real-time.
If you see events like page_view and user_engagement show up in Tag Assistant, your GA4 tag is firing correctly.
Final Thoughts
You've successfully connected your website to Google Analytics 4. With this setup, you can now track traffic, understand user behavior, and discover which marketing channels are delivering results, giving you the power to grow your site with confidence.
Now that your data is flowing into Google Analytics, the next step is turning that data into clear, actionable insights. For anyone who finds the native GA4 interface overwhelming, analyzing your performance can be a challenge. We built Graphed to solve exactly that. Instead of fighting with complex reports, you can get answers by simply asking questions in plain English, instantly building dashboards that combine GA4 data with other sources like Shopify, Google Ads, or HubSpot to get a complete picture of your performance.
Related Articles
What SEO Tools Work with Google Analytics?
Discover which SEO tools integrate seamlessly with Google Analytics to provide a comprehensive view of your site's performance. Optimize your SEO strategy now!
Looker Studio vs Metabase: Which BI Tool Actually Fits Your Team?
Looker Studio and Metabase both help you turn raw data into dashboards, but they take completely different approaches. This guide breaks down where each tool fits, what they are good at, and which one matches your actual workflow.
How to Create a Photo Album in Meta Business Suite
How to create a photo album in Meta Business Suite — step-by-step guide to organizing Facebook and Instagram photos into albums for your business page.