How to Install Google Analytics with Google Tag Manager
Thinking about installing Google Analytics on your website? The smartest and most flexible way to do it is with Google Tag Manager. Using Tag Manager eliminates the need to constantly bother your developer to add tracking code and gives you a central place to manage all your marketing tags. This guide will walk you through, step by step, how to install Google Analytics 4 using Google Tag Manager, even if you've never touched a line of code before.
First, Why Bother Using Google Tag Manager?
You could copy the Google Analytics tracking snippet and paste it directly into your website's code, and it would work just fine. So why add an extra tool like Google Tag Manager (GTM) to the mix? The short answer is: it gives you control and saves you massive amounts of time down the road.
Think of GTM as a toolbox that holds all of your third-party tracking scripts, which are called "tags." Instead of hard-coding each script (Google Analytics, Facebook Pixel, LinkedIn Insight Tag, etc.) onto your site, you just install the GTM script once. From then on, you can add, edit, or remove all your other tracking tags from GTM’s user-friendly interface.
- No More Waiting on Developers: Once GTM is installed, you can launch new marketing tags - like tracking conversions or button clicks - in minutes, without writing any code or submitting a request to your web developer.
- Centralized Tag Management: See all the scripts running on your website in one clean dashboard. No more hunting through code to figure out what's implemented and what's not.
- Built-in Testing: GTM comes with a powerful Preview mode that lets you test your tracking to make sure it's working correctly before you publish it to your live site. This helps you avoid collecting bad data or breaking your website.
- Performance: Because GTM loads tags asynchronously, it can help prevent a bunch of slow-loading tracking scripts from bogging down your site's speed.
Setting it up takes a few extra minutes upfront, but it pays for itself by giving you marketing agility and a much cleaner analytics implementation.
Step 1: Get Your Google Analytics 4 Measurement ID
Before you can connect anything in Google Tag Manager, you first need a Google Analytics 4 property set up. If you already have one, feel free to skip to the section where you find your Measurement ID. If you're starting from scratch, follow these steps.
Create a Google Analytics Account and Property
- Navigate to the Google Analytics website and sign in with your Google account.
- Click on the Admin gear icon in the bottom-left corner.
- In the Account column, click Create Account. Give your Account a name, like your business name. Configure your data sharing settings and click Next.
- Now it's time to create a Property. Enter a Property name, like "My Awesome Website." Set your reporting time zone and currency. Click Next.
- Provide your business information (industry, size) and click Create.
Set Up a Data Stream and Find Your Measurement ID
A "data stream" is simply where the data flows from into your GA4 property. For a website, you'll be creating a web stream.
- After creating your property, you'll be prompted to "Choose a platform." Select Web.
- Enter your website's URL (e.g., www.mywebsite.com) and give the stream a name (e.g., "MyWebsite.com Web Stream").
- Make sure "Enhanced measurement" is enabled. This feature automatically tracks key interactions like file downloads, video plays, and outbound clicks without any extra setup.
- Click Create stream.
Once you create the stream, a page appears with all the details. In the top right corner, you'll see the Measurement ID. It starts with "G-" and has a series of letters and numbers (like G-XXXXXXXXXX). This ID is the unique identifier for your data stream. Copy this ID - you'll need it in just a moment.
Step 2: Set Up and Install Google Tag Manager
Next, you'll create your Google Tag Manager account and get its code snippet installed on your website. This is the one and only time you'll need to touch your website's code.
Create Your GTM Account and Container
- Go to the Google Tag Manager website.
- Click Create Account.
- Set up your account with your company name.
- Beneath that, you'll set up your first "Container." Name the container after your website (e.g., www.mywebsite.com).
- Choose Web as your "Target platform."
- Click Create and accept the Terms of Service.
Install the GTM Snippet on Your Website
As soon as you create your container, a pop-up window will appear with two snippets of code. This is the GTM code you need to place on every single page of your website.
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[],w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'}),var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'',j.async=true,j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl,f.parentNode.insertBefore(j,f),
})(window,document,'script','dataLayer','GTM-XXXXXXX'),</script>
<!-- End Google Tag Manager --><!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXXX"
height="0" width="0" style="display:none,visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->Google provides these snippets with clear instructions:
- The first
<script>snippet should be pasted as high in the<head>section of your site's code as possible. - The second
<iframe>snippet should be pasted immediately after the opening<body>tag.
How you do this depends on your website platform. If you're using WordPress, a simple plugin like "GA Google Analytics" or "Insert Headers and Footers" lets you paste these snippets into the right place without ever needing to edit theme files. Other platforms like Shopify, Squarespace, and Webflow have specific sections in their settings for adding custom code or integrating with GTM directly.
Step 3: Connect Google Analytics to Your Site via GTM
Alright, you've got your GA4 Measurement ID and your GTM container installed on your site. Now for the magic: connecting the two.
Creating Your GA4 Configuration Tag
Back in your Google Tag Manager workspace, it's time to create your first tag.
- From the main Overview screen in GTM, select Tags from the left-hand menu, or click on "Add a new tag."
- Click the New button to create a tag.
- Give your tag a descriptive name at the top. A simple convention to follow is "Tool - Type - Detail". For this tag, something like
GA4 - Configuration - All Pagesis perfect. - Click inside the Tag Configuration box. A list will slide out. Select Google Analytics: GA4 Configuration.
- Now, in the Measurement ID field, paste that
G-XXXXXXXXXXID you copied earlier from your Google Analytics data stream.
You can leave the other settings as they are for now. The "Send a page view event when this configuration loads" checkbox should be checked by default. This makes the tag automatically track page views for you.
Setting Up the Trigger
A tag only fires when an event happens that tells it to. This is called a trigger. We want our main GA4 tag to load on every single page.
- Below the Tag Configuration box, click into the Triggering box.
- From the list of available triggers, select Initialization - All Pages.
Why "Initialization - All Pages"? GTM offers a standard "All Pages" trigger, but "Initialization - All Pages" is the best practice for main configuration tags. It's designed to fire before any other triggers, which ensures your GA code loads as early as possible and has the best chance of tracking every interaction, even ones that happen very quickly after a page loads.
Save Your Tag
Your setup should now look like this: a named GA4 Configuration Tag with your Measurement ID and a trigger set to "Initialization - All Pages". Click the blue Save button in the top right corner.
Step 4: Test Everything With GTM's Preview Mode
Before you publish anything, you need to confirm it works. Skipping this step is how mistakes happen. GTM's Preview mode is your best friend here.
How to Enter Preview Mode
- In the top right of your GTM workspace, click the Preview button.
- A new browser tab will open for the Tag Assistant. Enter your website’s URL and click Connect.
- Your website will open in another new tab. You should see a "Tag Assistant Connected" badge in the bottom right corner.
Whatever you do on your site in this window will now be mirrored in the Tag Assistant debug window.
What to Look For
Go back to the Tag Assistant tab. On the left-hand side, you'll see a log of all events that happened as the page loaded.
- Click on the Initialization event near the top of the list.
- Under the "Tags Fired" section in the main window, you should see your
GA4 - Configuration - All Pagestag. Success! - If you see your tag under "Tags Not Fired," click on it. GTM will show you exactly which part of your trigger condition was not met, helping you troubleshoot.
Double-Check in Google Analytics
For extra assurance, check if the data is actually arriving in Google Analytics.
- In your GA4 property, go to Admin > DebugView.
- You should see events appearing here in near-real time as you click around your website in the Preview tab. This display shows you a stream of every raw event being sent from your browser.
- You can also check the Reports > Realtime report to see yourself as an active user on the map.
Seeing activity in DebugView and Realtime confirms that GTM is successfully sending data to GA4.
Step 5: Publish Your Changes and Go Live
Once you've confirmed everything is working as expected, it’s time to push your changes live.
- Close the Preview mode and go back to your GTM workspace. You can now see a banner at the top showing you have Workspace changes.
- Click the blue Submit button in the top right corner.
- You'll be asked to provide a Version Name and Version Description. It's a great habit to be descriptive. For the name, use something like "Initial GA4 Install." For the description, add "Added the base GA4 Configuration tag to all pages." This creates a change log so you can always look back and see who published what, and why.
- Click Publish.
And that's it! Your Google Analytics 4 tracking is now live on your site, powered by Google Tag Manager.
Final Thoughts
In this guide, you installed Google Tag Manager, created your first tag to link to Google Analytics, tested it to make sure it was a success, and published it. You now have a solid foundation for all your future website analytics, making it significantly easier to track campaigns, user behavior, and conversions without ever having to edit your website's code again.
Once your data is flowing into Google Analytics, the next challenge is turning dashboards full of numbers into clear, simple answers. That's why we built Graphed. After easily connecting your Google Analytics account, you can skip the complex report-building and just ask what you want to know in plain English, like "Compare traffic and conversions from Google vs. Facebook ads for the last 30 days." We instantly translate your questions into the live dashboards you need, helping you find insights and make decisions faster.
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.