Skip to content
Landing Pages

Integrate Google Analytics with HubSpot content

Last updated: October 14, 2021

Applies to:

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

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

If you are using the Universal Analytics version of Google Analytics, you can integrate it with HubSpot-hosted content by adding a Google Analytics Tracking ID to your HubSpot settings.

If you are using Google Analytics 4 or a customized Google Analytics script, you can add your Google Analytics tracking code snippet to the site header HTML for your domain. You can also use this method to track only a specific blog or page.  

Integrate Google Analytics using a Tracking ID

With the Universal Analytics version of Google Analytics, you can add a Tracking ID directly to your HubSpot settings to track visitors in Google Analytics. This will track all pages hosted on a single domain. You can repeat this process for additional domains, or add the Tracking ID to your default settings for all domains.  

Please note: if you are using GDPR features or a cookie policy banner that requires visitor opt-in, the Google Analytics script will only run for visitors who 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 one or all domains hosted in HubSpot:

  • 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. To apply tracking to all HubSpot-hosted content, select Default settings for all domains. If there is a conflict, a domain's specific settings will take priority over the general default settings. 
  • Click the Integrations tab.
  • In the Tracking integrations section, select the Integrate with Google Analytics checkbox. To disconnect the integration instead, clear this checkbox.
  • In the field, enter a Google Analytics Tracking ID. Only IDs beginning with UA can be added here. If you are instead using Google Analytics 4 and have an ID beginning with G, add the Google Analytics tracking code to your site's header HTML instead. 

default-for-all-domains

  • In the bottom left, click Save.

Add Google Analytics tracking code to a domain's header HTML

If you are using Google Analytics 4, you can add the Google Analytics tracking code to the header HTML of your domains in settings. This is also recommended if you are using a customized Google Analytics script. 

Please note: a Google Analytics tracking code added via header HTML cannot be controlled by the HubSpot cookie policy banner. By default, it will record data on visitors regardless of their opt in status. You can customize this behavior in Google using their developer documentation. 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. 

  • 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. To add the tracking code to all HubSpot-hosted domains, select Default settings for all domains. If there is a conflict, a domain's specific settings will take priority over the general default settings. 
  • In the Site header HTML field, enter your Google Analytics tracking code. Learn more about finding your Google Analytics tracking code from Google. 

add-google-analytics-to-a-domain

  • In the bottom left, click Save.

Apply Google Analytics to a blog

If you've added a Tracking ID or the Google Analytics tracking code to a domain, any blog hosted on that domain will be tracked automatically. To track a single blog, rather than all content on a domain, you can add the Google Analytics tracking code to the blog's header HTML. 

  • 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 a blog.
  • Click the Templates tab.
  • In the Blog listing pages header HTML field, enter the Google Analytics tracking code. Learn more about finding your Google Analytics tracking code from Google. 
  • By default, the tracking code will be applied to both the listing page and posts of the blog. You can also track only the listing page or only the posts instead:   
    • To only add the tracking code to the blog post template, click Use custom header HTML for blog posts. Then enter the Google Analytics tracking code in the Blog post header HTML field.
    • To only add the tracking code to the blog listing page template, click Use custom header HTML for blog posts, but leave the Blog post header HTML field blank.

add-google-analytics-to-a-blog

  • Click Save in the bottom left. 

Apply Google Analytics to a page

If you've added a Tracking ID or the Google Analytics tracking code to a domain, any pages hosted on that domain will be tracked automatically.

To track a single page, rather than all content on a domain, you can add the Google Analytics tracking code to the page's header HTML.  This feature is only available in Marketing Hub Professional and Enterprise and CMS Hub accounts.

  • Navigate to your content:

    • Website Pages: In your HubSpot account, navigate to Marketing > Website > Website Pages.
    • Landing Pages: In your HubSpot account, navigate to Marketing > Landing Pages.
  • Hover over a page and click Edit.
  • In the content editor, click the Settings tab, then click Advanced options
  • In the Additional Code Snippets section, enter the Google Analytics tracking code in the Head HTML field. Learn more about finding your Google Analytics tracking code from Google. 

add-google-analytics-to-a-page

  • In the top right, click Publish or Update to take the changes live.