Thanks for previewing Google's new tag platform documentation! This site is in public beta. (Feedback)

Install Google Tag Manager for web pages

Google Tag Manager is a tag management system that allows you to quickly and easily update tags and code snippets on your website. Launch Google Tag Manager.

This article describes Tag Manager installation for web pages. For other platforms, read the documentation for Android, iOS, or Server installations.

Tag Manager installation for web requires a small piece of code that you add to your web pages or mobile applications. This code enables Tag Manager to fire tags by inserting tags into web pages or mobile apps.

Standard web page installation

In most cases, the easiest way to get started is to find the code and instructions from within Tag Manager.

  1. If you have not done so already, create a Google Tag Manager account and container.
  2. In Google Tag Manager, click Workspace.
  3. Near the top of the window, find your container ID, formatted as GTM-XXXXXX. Click your container ID to launch the Install Tag Manager window.
  4. Copy the code and install on all pages based on the instructions provided. The first code block is best placed immediately after the web page's opening <head> tag, or as high in the <head> as possible. This helps to ensure that your Tag Manager configuration is available and ready when the rest of the page loads.
    Tag Manager installation screen
  5. Optional, but recommended: Install a data layer object. A data layer will enable more robust measurement for your tag configurations.
  6. Publish your container.

Once your Tag Manager installation is complete, all tag configuration is performed from within the Tag Manager user interface.

Custom web installations

In rare cases (e.g. when creating a new template for a content management system or ecommerce template), you may wish to code a custom gtm.js tag. Add the following code so that it is as close to the opening <head> tag as possible on every page of your website. Replace GTM-XXXXXX with your container ID:

<!-- Google Tag Manager -->
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
<!-- End Google Tag Manager -->

Next, add this code immediately after the opening <body> element on every page of your website. Replace GTM-XXXXXX with your container ID:

<!-- Google Tag Manager (noscript) -->
<noscript><iframe src=""
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->

Obtain product-specific setup guidance

Click the links below to learn how to setup Tag Manager for specific products: