Add the Google Tag Manager code to your pages
Last updated: December 21, 2020
Google Tag Manager provides a code snippet that can be added to your pages in your HubSpot settings. 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 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 Integrate with Google Tag Manager.
- Enter your Google Tag Manager ID in the text field. Learn how to find this in your Google Tag Manager account.
- At the bottom, click Save to apply your changes.
Add the Google Tag Manager code manually
These steps only apply for accounts that have access to site header and footer HTML settings.
1. Copy the code from Google Tag Manager
- Log in to your Google Tag Manager account.
- Click the Admin tab.
- Under the Container column, click the Container that contains your tags from the dropdown.
- 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.

2. Add the Google Tag Manager code to HubSpot pages
Google advises the Javascript code snippet (labeled 1 in the above screenshot) to be placed as high in the <head> of the page as possible. 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) is placed after the opening <body> tag. However, it can be added to other sections of the page, depending on a website's settings. See Google Tag Manager's documentation for more details.
When adding code to the body of your HubSpot pages site-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.
- Use the Modifying dropdown menu to choose a domain, or choose All domains to add the code to all your HubSpot-hosted domains.
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 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 in the Site header HTML field.
- Add your <noscript> code snippet to the Site footer HTML section.

- Click Save to apply your changes.
Related content
-
Export your content and data
Learn how to export HubSpot content and data from your account, such as pages, contacts, and files. Please...
Knowledge Base -
Manage multi-language content
You can manage content for your global audience in multiple languages on your landing pages and website...
Knowledge Base -
Require member registration to access private content
Users with publish permissions can control which contacts can access specific HubSpot-hosted pages, blogs and...
Knowledge Base