Installing GTM on Your Site
What you'll learn: You'll learn how to add the Google Tag Manager container snippet to your HTML and verify it's working correctly using preview mode.
Understanding the Installation Process
Installing GTM is straightforward: you embed two code snippets Google provides into your site's HTML. Think of it like installing a smart electrical panel in your house—once it's in place, you can plug in and control all your appliances (tags) from one central location without rewiring everything.
The installation consists of two parts working together:
- The
<head>snippet: The main JavaScript that loads GTM - The
<body>snippet: A fallback<noscript>version for users with JavaScript disabled
Adding the Container Snippet
After creating your GTM container, Google provides code that looks like this:
<!DOCTYPE html>
<html>
<head>
<!-- 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>
<!-- 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) -->
<!-- Your page content -->
</body>
</html>
Place the first snippet as high in the <head> as possible, and the second immediately after the opening <body> tag.
Verifying Installation
Use GTM's Preview Mode (found in your container workspace) to test. It opens a special debug panel showing which tags fire on your site. If you see your page connected in the preview panel, installation succeeded.
Key Takeaway: Installing GTM requires adding two snippets to your HTML—one in the <head> and one after <body>—then verifying with preview mode before publishing any tags.