Set up Google Analytics in Google Tag Manager

Learn how to move your Google Analytics tag over to Google Tag Manager in just a few steps.

Google Analytics allows you to track traffic to your website and gain a better understanding of your website viewers and behaviors on your site. At a certain point when you expand your business you may be looking to set up other types of tags such as Google Ads, the Facebook Meta Pixel, LinkedIn Insight Tag, Hotjar Tracking code and more. Google Tag Manager (GTM) serves as a kind of storage locker that allows you to keep all of your tags in one place and then apply one snippet of code from GTM which references all of the stored tags instead of having to apply each individual tag to your website.

To get started with moving your Google Analytics tag over to GTM you will need to first set up your Google Tag Manager account and create a container. A container is essentially the place where you plan to link all your tags too (typically your website). A container is your locker that holds all your tags. Then you’ll want to sign into your Google Analytics account, select the Admin gear in the bottom left sidebar, select Data Streams, click on the stream for your website, scroll down to configure Tag settings, then copy the Google Tag ID. You will add this Google Tag ID to your Google Tag Manager account.

Back in GTM you will want to select tags in the left sidebar and then click the blue “New” button. From there give the tag a name and then select the pencil in the top right corner of the Tag Configuration box. Under Featured select Google Analytics >> Google Tag and then add the Tag ID you captured early in your GA account. Then click Save.

Congratulations you have just carried over your GA-4 tracking tag over to GTM. As a final step you need to ensure the GTM tracking code is added to your website. You’ll also want to remove any Google Analytics code from your website as it is now stored in Google Tag Manager.

To get your Google Tag Manager code you want to click on the a combination of letters and numbers starting with GTM- and highlighted in blue found in white top bar of your Google Tag Manager dashboard. This is your GTM tracking tag and by clicking on you will then see a popup that provides you the tracking code to your website. It should look something like this:

<!-- Paste this code as high in the <head> of the page as possible -->
<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>

<!-- Place this immediately after the opening <body> tag. -->
<noscript>
<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXXX"
height="0" width="0" style="display:none;visibility:hidden"></iframe>
</noscript>

In the same area you can also test to see if the code was properly added to your website which is super helpful to make sure the tag is firing correctly. If your were curious the noscript portion of the Google Tag Manager code snippet is intended as a backup piece of code in the event that Javascript is disabled on a user's device (extremely rare nowadays). As a best practice for now it is beneficial to add both scripts that Google provides you within your account.

That’s it! With the GTM code added you can now add any number of tags straight with Google Tag Manager which will then be linked to your website because you added that GTM tracking code.

No fluff. Just real projects, real value, and the path from code to cash — one useful build at a time.

Copyright 2025 Matthew Seiwert