The global site tag (gtag.js) is now the Google tag. Learn more

Add a tag to your website

Stay organized with collections Save and categorize content based on your preferences.

The Google tag and Google Tag Manager provide different ways to set up and manage tags on a website. You're free to choose the option that best suits your needs since they're built using the same technology.

This article provides instructions on how to add each option to your site; however, you only need to add one of them. Choose from the following to see the information for the tag you want to add:

About Tag Manager

Google Tag Manager is a tag management system that allows you to update tags on your website quickly and easily. Tag Manager installation for web requires a small piece of code that you add to your web pages. This code enables Tag Manager to fire tags by inserting tags into web pages.

Before you begin

Create a Google Tag Manager account and container. Learn more

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. In Google Tag Manager, click Workspace.
  2. Click your container ID (formatted as GTM-XXXXXX) at the top of the window to launch the Install Tag Manager window
    GTMID
  3. Install the tag on every page of your website using 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
  4. Optional, but recommended: Install a data layer object. A data layer will enable more robust measurement for your tag configurations.
  5. Publish your container.

Once your Tag Manager installation is complete, all tag configuration is performed from in Tag Manager.

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 -->
<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 -->

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="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) -->

Get product-specific setup guidance

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