How to Add Google Analytics to GTM

Cody Schneider8 min read

Adding Google Analytics to your website is essential, but doing it through Google Tag Manager (GTM) is a game-changer for managing your tracking scripts efficiently. This guide provides a clear, step-by-step walkthrough to connect Google Analytics 4 with your site using GTM, giving you a flexible and powerful analytics foundation.

Why Use Google Tag Manager for Google Analytics?

While you can add the Google Analytics script directly to your website's code, using GTM offers significant advantages, especially as your tracking needs grow more complex. Think of GTM as a central hub or a container for all the third-party tracking scripts (known as "tags") you use on your site, not just for Google Analytics.

Here’s why it's the recommended approach:

  • Centralized Management: Instead of juggling multiple code snippets scattered across your website's header file for different tools (Google Analytics, Facebook Pixel, Google Ads, etc.), you manage everything from one clean GTM interface. This declutters your site's code and makes auditing your tracking setup much easier.
  • No More Developer Requests: Once the GTM container is installed, marketers can add, edit, or remove tracking tags without needing to file a ticket with the development team. This empowers you to deploy new campaigns and track conversions much faster.
  • Advanced Tracking Made Easy: GTM simplifies the process of tracking user interactions beyond simple pageviews. Want to track button clicks, form submissions, or video plays? GTM’s built-in triggers and variables allow you to set up this kind of event tracking with a few clicks, not a few lines of JavaScript.
  • Testing and Debugging Tools: GTM comes with a powerful Preview mode that lets you test your tags and triggers on your own computer before publishing them live. You can see which tags are firing on which pages and what data is being sent, helping you catch errors before they mess up your data.
  • Version Control: Every time you publish a set of changes in GTM, a new, archived version is created. If you accidentally break something, you can quickly revert to a previous, working version.

Before You Begin: A Quick Checklist

To follow along with this tutorial, there are two preliminary steps you need to have completed. Make sure you have the following ready to go:

  1. A Google Analytics 4 Property: You should have already created a GA4 property for your website. If you haven't, head over to Google Analytics, go to the Admin section, and create a new property.
  2. A Google Tag Manager (GTM) Account and Container: You need an active GTM account with a container set up for your website. Crucially, the GTM container code should already be installed on every page of your site. This involves adding two small snippets of code — one to the <head>, and one to the <body> of your site's HTML.

Important Note: If you already have the standard Google Analytics script (gtag.js) installed directly on your website, you will need to remove it after completing this setup to avoid double-counting pageviews and events.

How to Add Google Analytics to GTM: Step-by-Step

Once you have your GA4 property and GTM container ready, connecting them is a straightforward process involving a "tag" and a "trigger." The tag is the piece of code you want to run (in this case, GA4), and the trigger is the rule that tells the tag when to run (on all pages).

Step 1: Get Your GA4 Measurement ID

Your Measurement ID is the unique identifier that tells GTM where to send the data. It ensures that the tracking data from your website goes to the correct Google Analytics property.

  • In your Google Analytics account, click on the gear icon for Admin in the bottom-left corner.
  • In the Property column, click on Data Streams.
  • Select the relevant web data stream for your website.
  • Here you'll see your Stream details. On the right, copy the Measurement ID (it will start with "G-" followed by a string of letters and numbers). Keep this handy for the next step.

Step 2: Create the GA4 Configuration Tag in GTM

Now, let's head over to Google Tag Manager to create the tag that will load GA4 on your website. This is the base tag that initializes your analytics tracking.

  • Go to your GTM workspace and select Tags from the left-hand navigation menu.
  • Click the New button to create a new tag.
  • Give your tag a clear name that you'll easily recognize. A good practice is to use a consistent naming convention, like “GA4 - Configuration”.
  • Click inside the Tag Configuration box.
  • From the list of tag types, choose Google Analytics: GA4 Configuration.
  • In the Measurement ID field, paste the Measurement ID you copied from your GA4 property.
  • Leave the "Send a page view event when this configuration loads" box checked. This setting automatically handles pageview tracking for you, which is the most basic and essential form of website analytics.

Step 3: Add a Trigger to Fire the Tag

The tag is configured, but GTM doesn’t know when to execute it yet. That's where the trigger comes in. For our base configuration tag, we want it to fire on every single page of the website as soon as possible during the page load process.

  • Below the Tag Configuration box, click inside the Triggering box.
  • From the list of available triggers, select All Pages.
  • Why "All Pages"? Because we want this tag to fire on every page load, ensuring consistent tracking.
  • Click Save in the top-right corner to save your new tag and trigger configuration.

Test and Verify Your Setup with Preview Mode

Never publish your GTM changes without testing them first! GTM's Preview mode is a sandbox that lets you see exactly how your tags are behaving on your site before you push them live for all visitors.

  • In your GTM Workspace, click the Preview button in the top right.
  • A new tab will open asking for your website’s URL. Enter it and click Connect.
  • Your website will open in a new tab or window. At the bottom right, you'll see a small "Tag Assistant" badge confirming you are connected.
  • Go back to the Tag Assistant tab (the preview mode tab). On the left, click on "Initialization" in the event timeline.
  • Under the Tags Fired section, you should see your newly created "GA4 - Configuration" tag listed. This confirms that the trigger worked and the tag was successfully fired.

For extra confirmation, you can check the Realtime report in your Google Analytics property. You should see yourself as an active user, and in the "Event count by Event name" card, you should see the page_view event.

Publish Your Changes in GTM

Once you’ve confirmed that your GA4 tag is firing correctly in Preview mode, you're ready to make it live. Publishing pushes all the changes you've made in your GTM workspace to your website.

  • Go back to your GTM workspace and click the blue Submit button in the top-right corner.
  • A "Submit Changes" panel will appear. It's a best practice to document your changes here.
  • For the Version Name, enter something descriptive, like "Added GA4 Base Tag".
  • In the Version Description box, you can add more detail if you wish. This is incredibly helpful if you ever need to troubleshoot or understand past changes.
  • Click Publish. That's it! Google Analytics is now officially installed on your site via Google Tag Manager.

Final Step: Remove Old GA Tracking Code

Remember that important note from the beginning? Now is the time to act on it. If you previously had the Google Analytics (gtag.js) script hard-coded into your website's theme or template files, you must remove it. Having both the direct script and the GTM implementation active will cause all data to be sent to Google Analytics twice, which will inflate your metrics for pageviews, users, and sessions severely.

Find the old script in your site's source code and delete it. You've now fully migrated your GA setup to a cleaner, more efficient system.

Final Thoughts

You have now successfully set up Google Analytics using Google Tag Manager, creating a scalable, flexible, and powerful foundation for your digital analytics. This not only centralizes your tag management but also empowers you to add more advanced tracking, like form submissions or button clicks, without ever having to touch your website’s code again.

Setting up tracking is the first step, the next is turning that data into easy-to-understand insights. Instead of spending hours in Google Analytics trying to connect the dots, we created Graphed to help businesses connect their data sources - like Google Analytics, Google Ads, and Shopify - and build live dashboards using plain English. It's like having a data analyst on your team, ready to give you clear answers about your performance in seconds.

Related Articles

How to Connect Facebook to Google Data Studio: The Complete Guide for 2026

Connecting Facebook Ads to Google Data Studio (now called Looker Studio) has become essential for digital marketers who want to create comprehensive, visually appealing reports that go beyond the basic analytics provided by Facebook's native Ads Manager. If you're struggling with fragmented reporting across multiple platforms or spending too much time manually exporting data, this guide will show you exactly how to streamline your Facebook advertising analytics.

Appsflyer vs Mixpanel​: Complete 2026 Comparison Guide

The difference between AppsFlyer and Mixpanel isn't just about features—it's about understanding two fundamentally different approaches to data that can make or break your growth strategy. One tracks how users find you, the other reveals what they do once they arrive. Most companies need insights from both worlds, but knowing where to start can save you months of implementation headaches and thousands in wasted budget.