Google Tag Manager: what it is and how to install it on your site
Published by the UTM Builder team at Limner.
Google Tag Manager (GTM) is where you set up your site’s tags: GA4, Google Ads, the Meta pixel and others. You install the GTM code once and, from then on, add and change tags in the interface, without editing your site’s code for every change.
Container, tags, triggers and variables
- Container: the set of tags, triggers, variables and related settings installed on a site. One container covers the whole site; you don’t need one per page. Its ID starts with
GTM-. - Tag: a snippet of code from an analytics or marketing provider. The Google tag with your GA4 ID is a tag; the Meta pixel is another.
- Trigger: the rule that decides when a tag fires. It listens for events such as page loads, clicks and form submissions.
- Variable: a placeholder that holds a value used by a tag or a trigger. GTM comes with built-in variables and lets you create your own.
GTM and GA4 aren’t the same thing
GA4 is the Google Analytics property, where the data arrives. GTM is the tool that puts tags on your site, and one of them can be the Google tag with your GA4 ID, which starts with G-. Neither replaces the other: GTM is one way to install GA4.
The other way is to paste the Google tag (gtag.js) directly into your code. The difference, according to Google: gtag.js requires writing code and only sends data to Google products; GTM also sends data to third-party and custom tags, without editing code. If GTM is already on the site, you don’t need to install gtag.js separately.
How to create the account and container
- Go to
https://tagmanager.google.comand sign in with your Google Account. - In the Accounts tab, click Create Account.
- Name the account and choose the country.
- Under Container Setup, use the site’s main address as the name and choose the Web type.
- Click Create and accept the Terms of Service.
The account is the company level. The container is the site. For another site, create another container in the same account.
Where to paste the two code snippets
In the Workspace tab, click the container ID. The Install Google Tag Manager dialog shows two blocks of code, which go on every page of the site:
- The first goes as high as possible inside the
<head>. - The second, the one with
<noscript>, goes right after the opening<body>tag.
In the same dialog, enter your site’s address and click Test to check the installation. If the site is built on WordPress, Shopify, Wix or another website builder, Google recommends the platform’s integration, which saves you from editing the code on every page.
If the site uses a dataLayer, declare it before the container snippet, high in the code, and afterward only add data with dataLayer.push:
window.dataLayer = window.dataLayer || [];
How to add GA4 inside GTM
- In GA4, under Admin, Data collection and modification, Data streams, open the site’s stream and copy the ID that starts with
G-. - In GTM, create a new tag of type Google Tag and paste the ID into Tag ID.
- Under Triggering, choose Initialization - All Pages.
How to test in preview mode (Tag Assistant)
- In the Workspace tab, click Preview at the top right. Tag Assistant opens in a new tab.
- Enter your site’s address and click Connect. The site opens and shows as Connected in the bottom right corner.
- Go back to the Tag Assistant tab, click Continue and browse the site. The screen shows which tags fired, in what order and what data they sent.
Preview mode runs the container draft as if it were published, only in the browser where you turned it on. Regular visitors see nothing. If a page breaks with the debug parameter in the address, uncheck Include debug signal in the URL.
How to publish a version
- In the Workspace tab, click Submit at the top right.
- Under Submission Configuration, choose Publish and Create Version.
- Give the version a name and a description that says what changed.
- Click Publish.
Create Version, without publishing, only saves. Each version is a snapshot of the container at a point in time, and you can go back to an earlier version if something goes wrong.
Common mistakes
- Forgetting to publish. What you change in the workspace only takes effect on the site after it’s published. Worked in preview mode but nothing reaches GA4? Check that the version was published.
- gtag and GTM at the same time. If gtag.js is pasted into the code and GTM also fires GA4, some events are counted twice. Google’s documentation is direct: use gtag.js or GTM, not both.
- GA4 installed twice. Many store and website platforms have their own GA4 integration. Turning that integration on and also adding the Google tag in GTM, or having two containers with GA4 on the same page, duplicates events. Keep a single installation per page.
- Wiping the dataLayer. Writing
dataLayer = [...]after the container replaces what was already there. Declare it once and usedataLayer.push.
Official sources
- Tag Manager Help: Introduction to Tag Manager
- Tag Manager Help: Tag
- Tag Manager Help: Trigger
- Tag Manager Help: Variable
- Tag Manager Help: Google Tag Manager vs. gtag.js
- Tag Manager Help: 1. Create an account and container
- Tag Manager Help: 2. Install a web container
- Tag Manager Help: 3. Add the Google tag in Google Tag Manager
- Tag Manager Help: 4. Verify and publish tags
- Tag Manager Help: Preview and debug containers
- Tag Manager Help: Publishing, versions, and approvals
- Analytics Help: Set up Analytics for a website and/or app
- Google for Developers: The data layer
- Google for Developers: Validate your ecommerce setup (gtag.js)