Landing Pages

Add the Google Tag Manager code to your pages

Last updated: February 25, 2021

Applies to:

Marketing Hub  Starter, Professional, Enterprise
CMS Hub  Professional, Enterprise
Legacy Marketing Hub Basic

You can integrate Google Tag Manager with HubSpot to manage tracking from multiple sources in one place. For more information about Google Tag Manager, see Google's getting started guide, which includes a page on common questions.

Integrate with Google Tag Manager

When you integrate HubSpot with Google Tag Manager, the tag manager will run on all pages with the HubSpot tracking code. This automatically includes HubSpot-hosted pages.

  • In your HubSpot account, click the settings icon settings in the main navigation bar.
  • In the left sidebar menu, navigate to Website > Pages.
  • Click the Integrations tab.
  • Select the Integrate with Google Tag Manager checkbox.
  • Enter your Google Tag Manager ID in the text field. Learn how to find this in your Google Tag Manager account.

integrate-with-google-tag-manager

  • Click Save to apply your changes.

Add the Google Tag Manager code manually

You can also add the Google Tag Manager code to your HubSpot-hosted pages manually. This is recommended if you only want some HubSpot-hosted domains tracked this way. These steps only apply for accounts that have access to site header and footer HTML settings.

Copy the code from Google Tag Manager

  • Log into your Google Tag Manager account.
  • Click the Admin tab.
  • Click the Container dropdown and select the Container that contains your tags.
  • Click Install Google Tag Manager
  • On the next screen, you will be able to copy both code snippets (1) and (2) for your Google Tag Manager Container.

Add the Google Tag Manager code to HubSpot pages

Google advises the Javascript code snippet (labeled 1 in the above screenshot) be placed in the <head> of the page. This can be done in your settings in the Site header HTML field.

Google also advises that the <noscript> snippet (labeled 2 in the above screenshot) be placed after the opening <body> tag. When adding code to the body of your HubSpot pages domain-wide, you can only add the code directly before the closing </body> tag. This can be done in your settings in the Site footer HTML field.

  • In your HubSpot account, click the settings icon settings in the main navigation bar.
  • In the left sidebar menu, navigate to Website Pages
  • Click the Choose a domain to edit its settings dropdown menu and select a domain. If you want to add the code to all your HubSpot-hosted domains, select Default settings for all domains. 
choose-a-domain-1

Please note: if you add code to the header or footer HTML for a specific domain, it will override any code you have placed in header and footer HTML in Default settings for all domains. Learn more about the order that code is applied to your pages.

  • Add the code snippets you copied from Google Tag Manager:
    • Add your Javascript code snippet (1) in the Site header HTML field.
    • Add your <noscript> code snippet (2) to the Site footer HTML section.
  • Click Save to apply your changes.