askvity

How to use Google Tag Manager in a website?

Published in Website Tagging 6 mins read

Using Google Tag Manager (GTM) on your website is a powerful way to manage your marketing and analytics tags without modifying your website's code every time. Essentially, you install GTM once, and then you can deploy various tags (like Google Analytics, Google Ads conversion tracking, Facebook Pixel, etc.) and track events directly from the GTM web interface.

Here's a breakdown of how to get started and effectively use GTM on your website:

1. Setting Up Your Google Tag Manager Account and Container

The first step is to create an account and container for your website.

  • Create Account: Go to the Google Tag Manager website and sign in with your Google Account.
  • Create Container: Click "Create Account," provide your organization name, country, and container setup details.
    • Container Name: Enter your website's name (e.g., "My Website").
    • Target Platform: Select "Web."
    • Click "Create."

You will be presented with the Google Tag Manager Terms of Service agreement. Review and accept it.

2. Installing the GTM Container Code on Your Website

Once your container is created, GTM will provide you with two code snippets. These snippets must be added to every page of your website where you want GTM to function. This is a one-time code implementation.

  • The first snippet should be placed as high in the <head> of the page as possible.
  • The second snippet should be placed immediately after the opening <body> tag.

Example of code placement:

<!DOCTYPE html>
<html>
<head>
<title>My Website</title>
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXX"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->

<!-- 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-XXXXXX');</script>
<!-- End Google Tag Manager -->
</head>
<body>
<!-- Place the second GTM code snippet here -->

</body>
</html>

Replace GTM-XXXXXX with your actual GTM Container ID.

Important: Ensure these snippets are present on all pages you intend to track or modify with GTM.

3. Working with Tags, Triggers, and Variables

This is where the core "using" of GTM happens in the web interface.

  • Tags: Snippets of code (usually JavaScript) that send information to third parties, like Google Analytics, Google Ads, etc. You create tags for specific purposes (e.g., a Google Analytics 4 Configuration Tag, a Google Ads Conversion Tag, a Facebook Pixel ViewContent Tag).
  • Triggers: Rules that determine when a tag should fire. Examples include page views, button clicks, form submissions, video plays, etc. A trigger listens for specific events on your website.
  • Variables: Placeholders for dynamic information that tags and triggers might need. Examples include the Page URL, Clicked Element ID, Form ID, Data Layer variables, etc.

Typical Workflow:

  1. Choose a Tag Type: Select the type of tag you want to deploy (e.g., Google Analytics: GA4 Configuration).
  2. Configure the Tag: Add necessary IDs (like your GA4 Measurement ID) and configuration settings.
  3. Choose a Trigger: Specify when this tag should fire (e.g., All Pages).
  4. Save: Save your tag.

You can add multiple tags, each with its own triggers and variables, all managed within the GTM interface.

4. Previewing and Testing

Before making your changes live, use the "Preview" mode in GTM. This allows you to browse your website in a special debugging window (tagassistant.google.com) to see which tags fired and which didn't, and why. This is crucial for troubleshooting.

5. Publishing Your Container

Once you are confident that your tags are firing correctly in Preview mode, you can publish your container. Click the "Submit" button, add a version name and description (good practice for tracking changes), and click "Publish." Your changes will then become live on your website for all visitors.


While Google Tag Manager is the primary tool for deploying and managing tags, some tags might have settings that need to be configured within the associated platform (like Google Analytics or Google Ads) after the tag is deployed via GTM or directly.

For instance, if you are using the Google tag (gtag.js), which is often the basis for modern Google product tags like GA4 and Google Ads, you might need to adjust settings related to its behavior directly within the Google Analytics 4 property settings.

Configuring Google Tag Settings within Google Analytics 4 (as per reference):

If you are using the Google tag and need to configure its settings directly within Google Analytics 4, follow these steps:

  1. Sign in to your Google Account. (Learn how to create a Google Account here).
  2. In Admin, under "Data collection and modification," select Data Streams.
  3. Select the data stream that you want to edit (e.g., your website's data stream).
  4. Under "Google tag," click Configure tag settings.

This section in Google Analytics allows you to manage settings like cross-domain tracking, internal traffic definitions, unwanted referrals, and more, which apply to the Google tag collecting data for that specific GA4 property, regardless of whether it was deployed via GTM or directly.

Using Google Tag Manager streamlines the process of implementing and updating tags, giving you more control and reducing reliance on developers for every change. By mastering the concepts of tags, triggers, and variables, you can unlock powerful tracking and marketing capabilities for your website.

GTM Component Description What it Does
Tag Code snippet from a third party. Sends data or performs an action.
Trigger Condition(s) that determine when a tag fires. Listens for events on the page.
Variable Placeholder for information needed by tags/triggers. Provides dynamic values.

Related Articles