Skip to content

Integrate Google Analytics with HubSpot content

Last updated: May 24, 2024

Available with any of the following subscriptions, except where noted:

All products and plans

When you integrate Google Analytics with HubSpot, your Google Analytics account will collect data on the visitors to your HubSpot site. There are two ways to integrate Google Analytics with HubSpot: 

Please note: starting July 1 2023, Google is replacing Universal Analytics with Google Analytics 4. To avoid losing data synced to HubSpot, you'll need to switch to Google Analytics 4 prior to the change.

Integrate Google Analytics using a Measurement ID

You can add a Tracking ID directly to your HubSpot settings to track website visitors in Google Analytics. You can either integrate Google Analytics with individual domains, or integrate it with all domains.

Integrating Google Analytics with this method will also automatically add tracking to the payments checkout page, which facilitates payments for both payment links and quotes. You can turn this tracking off in your payments settings.

Please note: if you are using data privacy features or a cookie consent 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 settings icon in the top navigation bar.
  • In the left sidebar menu, navigate to Content > 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 4 checkbox. To disconnect the integration instead, clear the checkbox.
  • In the field, enter a Google Analytics Measurement ID. You can also add the Google Analytics tracking code to your site's header HTML instead. 

google-analytics-integrations-page-setting

  • In the bottom left, click Save.

Add Google Analytics tracking code to a domain, blog, or page's header HTML

Apply Google Analytics to a domain’s site header HTML (Marketing Hub Professional and Enterprise)

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. 

Integrating Google Analytics with this method will also automatically add tracking to the payments checkout page, which facilitates payments for both payment links and quotes. You can turn this tracking off in your payments settings.

Please note: a Google Analytics tracking code added via header HTML cannot be controlled by the HubSpot consent 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 settings icon in the top navigation bar.
  • In the left sidebar menu, navigate to Content > 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-4-tracking-code

  • In the bottom left, click Save.

Apply Google Analytics to a blog

If you've added a Measurement 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 settings icon in the top navigation bar.
  • In the left sidebar menu, navigate to Content > 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-4-code-to-blog-header

  • Click Save in the bottom left. 

Apply Google Analytics to a specific page

If you've added a Measurement 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 Content Hub accounts.

  • Navigate to your content:

    • Website Pages: In your HubSpot account, navigate to Content > Website Pages.
    • Landing Pages: In your HubSpot account, navigate to Content > Landing Pages.
  • Click the name of your page.
  • In the content editor, click the Settings menu and select Advanced
  • In the Additional Code Snippets section of the dialog box, enter the Google Analytics tracking code in the Head HTML field. Learn more about finding your Google Analytics tracking code from Google. 

set-google-analytics-tracking-code

  • To take your changes live, click Publish or Update in the top right.
Was this article helpful?
This form is used for documentation feedback only. Learn how to get help with HubSpot.