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:
- You can integrate with HubSpot-hosted content by adding a Google Analytics Measurement ID to your HubSpot settings. Users with a Marketing Hub Starter subscription and no CMS Hub subscription can only integrate using a Measurement ID.
- 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.
**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. Learn more about setting up Google Analytics 4 in a video or article from Google.
Integrate Google Analytics using a Measurement ID
You can add a Tracking ID directly to your HubSpot settings to track visitors in Google Analytics. You can either integrate Google Analytics with individual domains, or integrate it with all domains.
Please note: if you are using GDPR 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 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 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.
- 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.
**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 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.
- 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 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.
- 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 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.
- In the top right, click Publish or Update to take the changes live.