How to Install Google Analytics 4 with GTM
Setting up Google Analytics 4 with Google Tag Manager (GTM) is the professional way to handle website analytics. This approach moves your tracking code off your site and into a centralized hub, making it faster and easier to manage. This guide will walk you through setting up GA4 with GTM, step by step, from creating your tags to verifying that data is flowing correctly.
Why Use GTM to Install Google Analytics 4?
Before we jump into the "how," let's quickly touch on the "why." You could just paste the GA4 code directly onto your website, but using Google Tag Manager is a much better long-term strategy. Think of GTM as a toolbox for all your website marketing and analytics code (known as "tags").
Here’s why it’s the preferred method:
It’s Flexible: Need to add another tracking tool, like a Facebook Pixel or a HubSpot tracking code? You can do it all within the GTM interface without ever having to ask a developer to edit your website's code.
It’s Cleaner and Faster: Instead of loading ten different JavaScript snippets on your site, you load just one: the GTM container. This can help keep your site running smoothly and your code base clean.
Advanced Tracking Made Simple: With GTM, setting up tracking for actions like button clicks, form submissions, or video plays becomes much more manageable. GTM has built-in features (called triggers and variables) specifically for this.
Testing is Built In: GTM's "Preview Mode" is a lifesaver. It lets you test all your new tags to make sure they are working perfectly before you publish them to your live site.
What You’ll Need to Get Started
To follow along, make sure you have these three things ready. If you don't, we'll cover how to create them in the first two steps.
A Google Account to access both Google Analytics and Google Tag Manager.
A Google Analytics 4 Property created for your website.
A Google Tag Manager Container set up for your website.
Step 1: Get Your GA4 Measurement ID
Your "Measurement ID" is the unique identifier that tells Google Tag Manager where to send the tracking data. You’ll need this to link GTM and GA4.
First, log in to your Google Analytics account.
If you already have a GA4 property:
Click the Admin gear icon in the bottom-left corner.
In the Property column, click on Data Streams.
Select the appropriate data stream for your website. This will open up the stream details.
In the top right, you'll see your MEASUREMENT ID. It starts with a "G-" followed by a combination of letters and numbers.
Click the copy icon next to it and save it somewhere handy. You’ll need it in a few minutes.
If you need to create a new GA4 property:
In the Admin section, make sure the correct account is selected and click the blue + Create Property button.
Give your property a name (e.g., your website's name), select your reporting time zone and currency, and click Next.
Answer the optional business questions and click Create.
Underneath "Choose a platform," select Web.
Enter your website’s URL (e.g., www.mybusiness.com), give the stream a name (e.g., "[Website Name] Web Stream"), and click Create stream.
Once the stream is created, the Measurement ID will be displayed in the top right. Copy this "G-" ID just like in the steps above.
Step 2: Install the Google Tag Manager Container on Your Site
Now, let's head over to Google Tag Manager. The GTM "container" is the single snippet of code that needs to be installed on your website. Once it's there, you'll manage everything else from within the GTM interface.
Log in to your Google Tag Manager account.
If you already have a GTM container:
If you're already using GTM, you can skip to Step 3. Just double-check that the container code is still correctly installed on your website. A great way to do this is with the Tag Assistant Companion Chrome extension.
If you need to create a GTM container:
Click the blue Create Account button.
Fill out your Account Name (usually your company name).
Under Container Setup, enter your website’s domain as the Container name (e.g., mybusiness.com).
Select Web as your target platform.
Click Create and accept the terms of service.
A pop-up window will appear with two snippets of code. This is your GTM container snippet. You need to place this code on every page of your website. If you're using a CMS like WordPress, Shopify, or Squarespace, there are often plugins or specific settings areas that make this simple. Otherwise, you'll need to edit your website's source code directly.
Copy the first code block and paste it as high in the
<head>of your page as possible.Copy the second code block and paste it immediately after the opening
<body>tag.
Once that code is on your site, you're ready to create your GA4 tag inside GTM.
Step 3: Create the GA4 Configuration Tag in GTM
This is where we connect the dots. The GA4 Configuration tag is the base tag responsible for sending pageview data and setting the cookies for your Google Analytics session.
From your main GTM workspace, click on Tags in the left-hand menu.
Click the New button on the right.
Give your tag a clear name. A good practice is to call it something like "GA4 Config - [Your Measurement ID]".
Configuring the Tag
Click inside the Tag Configuration box.
From the list of tag types, choose Google Analytics: GA4 Configuration.
In the Measurement ID field, paste the "G-" ID you copied from your GA4 property in Step 1.
Leave the "Send a page view event when this configuration loads" box checked. This automatically tracks pageviews.
Your tag is now configured to send data. Next, you have to tell it when to send the data.
Setting the Trigger
Click inside the Triggering box at the bottom.
Select the predefined trigger called Initialization - All Pages. This trigger is designed to fire your tag on every page of your website as early as possible. (Note: Some older guides might say "All Pages - Page View," but "Initialization" is the newer best practice for configuration tags.)
Click Save in the top right corner.
That's it! You've created the tag and the trigger that will install GA4 on your website.
Step 4: Preview, Test, and Publish
Never publish anything without testing it first. GTM's Preview Mode lets you see exactly what's happening on your site before your changes go live for all your visitors.
Enter Preview Mode
In the top right of your GTM workspace, click the Preview button.
A new tab will open. Enter your website’s URL and click Connect.
Your website will open in another new tab with a "Tag Assistant Connected" badge in the corner.
Test Your Tag Firing
Go to the Tag Assistant tab (the one that opened after you clicked Preview).
In the left-hand menu, you should see a list of events like "Consent Initialization," "Initialization," and "Container Loaded." Click on the "Initialization" event.
You should see your GA4 Configuration tag listed under the "Tags Fired" section. Success! This means your GTM container correctly instructed your GA4 tag to activate.
Verify in Google Analytics
Let's confirm the data is actually arriving in Google Analytics.
Keep your Preview mode tabs open and go to your Google Analytics property.
In the left menu, go to Reports > Realtime.
You should see activity in the "Users in Last 30 Minutes" chart. There should be at least one user - you! This confirms that GA4 is receiving data from your site. You may also see events for
page_viewandsession_start.
Publish Your Container
Once you've confirmed everything is working, it's time to make your changes live.
Go back to your GTM workspace and click the blue Submit button in the top right.
Choose Publish and Create Version.
Give your version a descriptive name, like "Installed GA4 Configuration Tag," and add a short description if you like. This helps you keep a history of your changes.
Click Publish.
Congratulations! You have now successfully installed Google Analytics 4 on your website using Google Tag Manager. Your site is now tracking pageviews and user activity.
Next Steps: Tracking Events in GTM
Now that your base tracking is set up, the real power of GTM comes from tracking specific user interactions, or "events." Let's say you want to track when someone clicks an important "Request a Quote" button.
Here’s a quick overview of how you'd do that:
Enable Click Variables: Go to Variables > Built-In Variables > Configure, and make sure all the "Clicks" variables are checked.
Create a Trigger: Go to Triggers > New. Choose "Click - All Elements" as the trigger type. Set it to fire on "Some Clicks" where the "Click Text" contains "Request a Quote."
Create an Event Tag: Go to Tags > New. Choose "Google Analytics: GA4 Event" as the tag type.
Select your main GA4 Configuration Tag.
For the "Event Name," enter a descriptive name like
request_quote_click.Attach the new click trigger you just created.
Test and Publish: Use Preview Mode again to click the button yourself and watch for your new event tag firing. Once confirmed, submit and publish your changes.
Using this same framework, you can set up tracking for all sorts of important interactions, giving you a much deeper understanding of how users are engaging with your site.
Final Thoughts
Set up Google Analytics 4 with Google Tag Manager lays a solid and scalable foundation for your site's analytics. You get a cleaner setup that’s easier to manage in the long run and opens the door to much more powerful and specific user behavior tracking without having to change your website's code.
Once data starts flowing from your website into GA4, the next challenge is turning all those numbers into clear, accessible insights. It can still be a time-consuming process to get the answers you need. We built Graphed to solve this by ditching the complexity. Just connect your Google Analytics account, and ask in plain English for the reports you want, like "Show me my top 10 landing pages by conversions last week." We build the dashboard for you in seconds, saving you from navigating complex interfaces and letting you get right to the insights.