Create a container in Tag Manager to get an ID like GTM-ABCD123. Paste Google's first snippet as high in the <head> as possible and the second, a noscript iframe, immediately after the opening <body> tag on every page. Then add tags, such as your Google Analytics tag, inside Tag Manager and publish.
| Step | Where | What you do |
|---|---|---|
| 1. Create a container | tagmanager.google.com | Choose Web as the platform and note the GTM- ID |
| 2. Install the snippets | Your site's HTML or theme settings | Head snippet high in <head>, noscript snippet right after <body> |
| 3. Add a tag | Tag Manager workspace | For Analytics: tag type Google Tag with your G- ID |
| 4. Test | Preview button | Tag Assistant connects to your site and shows which tags fired |
| 5. Publish | Submit in the workspace | Nothing goes live on your site until you publish |
Updated
Google Tag Manager is a free container for tracking codes. Instead of pasting each tool's script into your site, you install one container once, then add, change or remove tags (small scripts for analytics, ads and similar tools) from Tag Manager's website. Type your container ID into the builder to get both snippets ready to paste.
Type your container ID from the top of your Tag Manager workspace. Everything is built in your browser.
Container ID: GTM-ABCD123
Looks right. Paste both snippets on every page.
<!-- 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-ABCD123');</script>
<!-- End Google Tag Manager --><!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-ABCD123"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->Use this when something happens that Tag Manager cannot see by itself, such as a form that sends without leaving the page.
Create a Custom Event trigger named newsletter_signup in Tag Manager to fire tags on it.
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
event: "newsletter_signup",
signup_location: "footer"
});| Trigger | Fires when | Typical use |
|---|---|---|
| Initialization | Before all other triggers except Consent Initialization | Google Tag for Analytics |
| Page View | As the browser begins to load a page | Most other page-level tags |
| History Change | The URL fragment changes or the page calls pushState | Page views in single-page apps |
| Custom Event | Your code pushes a matching event to the data layer | Form sends, sign-ups, bookings |
| Click | A visitor clicks an element or link | Phone and email link clicks |
In your workspace, click Preview at the top right. Tag Assistant opens in a new tab: enter your site's address and click Connect. Your site opens in a new window and shows Connected in the corner.
Back in the Tag Assistant tab, click Continue to see each event and which tags fired. Fix anything that did not fire before you publish.
The data layer is a JavaScript array that passes information to Tag Manager. Push an object with an event key, like a newsletter sign-up, and build a Custom Event trigger with the same name.
Google's guide says the data layer is case sensitive, so dataLayer works and datalayer does not, and that you should only ever push to it, never reassign it.
Google's install help says to paste the first block as high in the <head> tag as possible and the second block immediately after the opening <body> tag, on every page of the site.
Google includes it in the install code. It is an iframe wrapped in a noscript element, which browsers only use when JavaScript is turned off. Paste it exactly as Google gives it to you.
In Tag Manager, add a new tag, choose Google Tag as the type and enter your tag ID starting with G-. Pick an initialization trigger, save, test it in Preview and then publish.
Apps that change pages without reloading do not trigger a fresh page load. Use the History Change trigger, which Google says fires when the URL fragment changes or when the site uses the HTML5 pushState API.
The standard version is free to use. Google also sells Tag Manager 360 as part of its enterprise products.
Related: How to set up Google Analytics, Google Search Console guide, How to view page source, How to get your business on Google.
Start for free or see all free tools. We.Inc is free to start, with no card needed. AI building is on paid plans from $20 a month.
We.Inc is an AI-powered website builder you can resell under your own brand. Launch a branded client dashboard, bill on Stripe Connect, and deliver AI-generated websites in minutes. White-label plans start at $99 a month for 25 client sites, with a 7-day free trial and no per-site fees.