Tracking Code

Set up site tracking in HubSpot

Last updated: March 29, 2021

Applies to:

All products and plans

Once you've installed the HubSpot tracking code, you may need to do some additional setup to ensure that HubSpot gathers analytics for all of the domains and subdomains on your website. Some of this data will be displayed in your reports and analytics tools.

Apart from setting up your site tracking, you should also filter out bot activity and your own traffic from your analytics and customize your cookie tracking settings and privacy policy alert.

If you're looking to update how your domain appears to your contacts in marketing emails, sales emails and more, check out how to set up your company branding in HubSpot.

If you're looking to display your HubSpot content on your domain, learn how to connect your domain.

Update your company domain

Your company domain is the domain crawled to detect your website pages.

Please note: if your website is hosted entirely on HubSpot, the primary domain in your domain manager needs to match your target domain in order for visits to show in the Sources tab in the traffic analytics tool.

  • In your HubSpot account, click the settings icon settings in the main navigation bar.
  • In the left sidebar menu, navigate to Account defaults.
  • On the General tab, enter your domain in the Company domain field. This is the domain used in your analytics tools.
  • At the bottom of the screen, click Save.

If you are hosting your site externally (i.e., your domain is not connected to HubSpot), the HubSpot tracking code needs to be embedded on your external site. Without the tracking code on your pages, visits will not be registered from those pages. Learn how to install the tracking code on your external site.

Please note: if your domain is connected to HubSpot, the tracking code will be on all HubSpot pages you create. You should not install the tracking code on your HubSpot pages.

Add site domains

After adding the tracking code to any pages that are not hosted with HubSpot, you should add the external site domains to your reports settings to include them in your HubSpot analytics.

To add external domains and subdomains to HubSpot:

  • In your HubSpot account, click the settings icon settings in the main navigation bar.
  • In the left sidebar menu, navigate to Tracking & Analytics > Tracking Code. If you have a free HubSpot account, click Tracking code in the left sidebar menu.
  • Click the Advanced Tracking tab.
  • Click + Add domain at the bottom of the Additional site domains table to add new domain(s) to be included as part of your site for cross-domain traffic.
account-settings-reports-tracking-code-advanced-tracking-additional-site-domains

Please note: future traffic between domains added in your advanced tracking settings will be considered part of your website and will not appear in your sources report as a referral.

  • In the dialog box, enter a domain, then click Add.
    • If you add a subdomain (e.g., www.hubspot.com, academy.hubspot.com), HubSpot will track that specific subdomain.
    • If you add a top level domain (e.g., hubspot.com), HubSpot track all subdomains (e.g., www.hubspot.com, academy.hubspot.com etc.) under the top level domain.

While these steps will allow you to track traffic on any domain, you can only create a custom analytics view to segment your website traffic if the domain is a brand domain in the account.

Please note: HubSpot will crawl domains that are added to the site domains settings, even if the tracking code is not installed on these domains. HubSpot will crawl these domains to collect information for other HubSpot tools, such as SEO data for page performance reports. You can use the robots.txt file to block all crawlers from HubSpot, which will prevent these domains from getting crawled. 

Track multiple domains with cross-domain linking

Cross-domain linking allows HubSpot to merge the visitor profiles of one person as they visit your multiple domains. By merging visitor profiles, you can more accurately track traffic sources between your websites.

For example, if a visitor arrives at yourwebsite.com through social media, then they navigate to yournewbrand.com, cross-domain linking enables HubSpot to categorize both sessions as having a source of Organic social. Without cross-domain linking, the visit to yournewbrand.com would have a source of Direct traffic because the website visit cookies can't be linked.

Visitor profile merging can take place when:

  1. A visitor submits more than one form with the same email address across multiple domains on which you have your HubSpot tracking code installed.
  2. A visitor clicks a link that takes them between two different domains, each of which have your HubSpot tracking code installed on them. HubSpot attaches parameters to your links from one domain to another (__hsfp, __hssc, and __hstc) to track visitors as they travel between domains. You must have automatic cross-domain link tracking enabled in your account settings for this to work.

Please note: this is only necessary to track traffic between distinct domains (e.g., thisdomain.com and anotherdomain.com). This requirement is a result of a privacy limitation of cookies, where cookies are set at the domain level and cannot be carried from one domain to the next. Traffic between subdomains (e.g., www.hubspot.com to blog.hubspot.com) is automatically tracked using cookies.

If you have multiple HubSpot accounts and would like to track individual subdomains in separate accounts, please contact HubSpot Support to help update your cookie settings.

To turn on cross-domain linking:

  • In your HubSpot account, click the settings icon settings in the main navigation bar.
  • In the left sidebar menu, navigate to Tracking & Analytics > Tracking Code. If you have a free HubSpot account, click Tracking Code in the left sidebar menu.
  • Click the Advanced Tracking tab.
  • Click to toggle the Automatic cross-domain linking switch ON, then click Save.

 

Limit tracking to specific domains

Limiting tracking to specific domains is useful if you have several different website domains and subdomains, but only want to track a few of them in HubSpot. This is also useful if your tracking code was placed on an external site that you do not operate and you want to prevent your analytics from becoming skewed.

To limit tracking to only the domains listed:

  • In your HubSpot account, click the settings icon settings in the main navigation bar.
  • In the left sidebar menu, navigate to Tracking & Analytics > Tracking Code. If you have a free HubSpot account, click Tracking Code in the left sidebar menu.
  • Click the Advanced Tracking tab.
  • Click to toggle the Limit tracking to these domains switch on, then click Save.

limit-tracking-to-these-domains

Exclude your traffic from your analytics

To prevent yourself and your team from adding noise to your analytics, learn how to exclude traffic from your site analytics.