Integrate Google Analytics with your HubSpot pages or blog

최종 업데이트 : 2021 년 2 월 25 일

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.

Please note: if you are using a Measurement ID instead of a Tracking ID, you will need to add the Google Analytics tracking code directly to the header HTML for your domains. 

 

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: 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 its settings dropdown menu and select the domain where you want to integrate Google Analytics. To integrate all your HubSpot-hosted domains, select Default settings for 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. 

  • Navigate to 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. By default, it will record data on visitors regardless of whether they 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. Learn more about disabling the Google Analytics tag from Google.

  • 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 the domain where you want to add the code. To add the code to all your HubSpot-hosted domains, select Default settings for 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 already integrated your Google Analytics account with all pages on 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 integrate with Google Analytics.
  • Click the Templates tab.
  • In the Blog listing page header HTML field, enter your Google Analytics tracking code snippet.
  • The same tracking code will be applied to your blog listing page template and blog post template by default. To apply custom Google Analytics tracking code to your blog post template:
  • Click Save to apply your changes.

Apply Google Analytics to a specific page

You can integrate Google Analytics with specific pages from the page editor. This feature is only available in Marketing Hub Professional and Enterprise and CMS Hub Professional and Enterprise accounts.

  • In your HubSpot account, navigate to Marketing > Website > Website Pages or Landing Pages
  • Hover over the page you want to update and click Edit.
  • In the page editor, click the Settings tab.
  • Click Advanced options and scroll down to the Additional Code Snippets section. 
  • Enter your Google Analytics tracking code snippet in the Head HTML code editor.
  • Click Publish or Update to take your changes live.