Landing Pages

Add your Google Analytics code to your HubSpot pages or blog

Last updated: March 3, 2020

Applies to:

Marketing Hub  Professional, Enterprise
Legacy Marketing Hub Basic
HubSpot CMS

You can integrate your HubSpot website and blog content with Google Analytics by adding your Google Analytics tracking ID in your HubSpot settings.

If your developers have customized your Google Analytics script, or if you only want to add Google Analytics tracking to a specific page or blog, add your Google Analytics tracking code snippet to the site header HTML for your pages or blog.

Integrate Google Analytics with all pages on all domains or a specific domain

When you integrate Google Analytics with HubSpot, your Google Analytics account will collect data on the visitors to your HubSpot site.

Please note: as of November 1, 2019, if you have GDPR settings enabled or have a cookie policy banner that requires visitor opt-in, HubSpot will only run the Google Analytics script if your visitors opt in to being tracked. If a visitor opts out, the Google Analytics script will not run and the visitor's data won't be tracked.

To integrate Google Analytics with all HubSpot domains or a specific HubSpot domain:

  • 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 dropdown menu and select the domain to add the code to. To add the code to all your HubSpot-hosted domains, select All domains.

Please note: if you integrate Google Analytics with a specific HubSpot domain, it will override any integration preferences you set as the default settings for all domains. 

  • Click the Integrations tab.
  • In the Tracking integrations section, select the Integrate with Google Analytics checkbox. You can also disconnect this integration by clearing the same checkbox.
  • In the text field, enter your Google Analytics tracking ID.

default-for-all-domains

  • In the bottom left, click Save.

Add customized Google Analytics tracking code to the header HTML for all pages on all domains or on a specific domain

If your developers have customized your Google Analytics script, to maintain the changes they've made to the code, do not integrate Google Analytics with HubSpot using the tracking ID. Copy your custom Google Analytics tracking code and add it to the the Site header HTML code editor in your settings.

Please note: when you add your Google Analytics tracking code to the header HTML instead of integrating Google Analytics with HubSpot, the Google Analytics script cannot be controlled by the HubSpot cookie policy banner and by default, will record data on visitors regardless of whether a visitor opts in or out, unless you customize your Google Analytics script.

Your legal and developer teams are the best resources to help you ensure that your use of the Google Analytics script on your site is compliant with privacy laws. This Google document on disabling the Google Analytics tag may be a helpful resource for your developer team.

  • 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 dropdown menu and select the domain to add the code. To add the code to all your HubSpot-hosted domains, select All domains.
  • In the bottom left, click Save.

Please note: if you add code to the header or footer HTML for a specific domain, it will override any code you've placed in your header and footer HTML for All domains.

Apply your Google Analytics code to a specific blog

If you've applied your code to all domains using the instructions above, your code will be applied to all your HubSpot blogs automatically. Only follow these instructions if you want your code to be applied to a specific blog and not your other HubSpot content.

  • In your HubSpot account, click the settings icon settings in the main navigation bar.
  • In the left sidebar menu, navigate to Website > Blog.
  • Click the Select a blog to modify dropdown menu and select the blog you want to track with Google Analytics.
  • Click the Templates tab, and in the Header HTML for Blog Listing Pages field, enter your Google Analytics tracking code snippet.
  • To apply the code to your blog posts as well, select the Use the same header HTML for blog posts checkbox.

  • Click Save to apply your changes.

Apply Google Analytics only to a particular page

  • Click Publish or Update to take your changes live.
/cos-general/add-your-google-analytics-code-to-your-hubspot-pages-or-blog?_ga=2.100588702.1638437897.1554681579-1350116256.1554681579