Tracking Code

Set up your site domains

Last updated: October 28, 2019

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. Below, learn how you can change your target domain, add additional site domains, set up cross-domain linking, and limit tracking to specific domains on your site.

Change your target domain

Your target domain is used as the basis for metrics in the links, competitors tools, and reports, and 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 your sources report.

  • In your HubSpot account, click the settings icon settings in the main navigation bar.
  • In the left side navigation, click the Reports dropdown menu and select Tracking Code.
  • Under the Tracking code tab, enter your new domain in the Domain field.
  • At the bottom of the screen, click Save.

 

Add site domains

In addition to adding the tracking code to any pages that are not hosted in HubSpot, you need to add any additional site domains to your reports settings to include them in your HubSpot analytics. To add external domains and subdomains to HubSpot: 

  • Install the HubSpot tracking code on all pages that you want to track in your account.

  • In your HubSpot account, click the settings icon settings in the main navigation bar.

  • In the left sidebar menu, navigate to Reports Tracking Code
  • 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. Traffic from domains that are not brand domains will be included in the sources report when filtering by All analytics activities and when viewing the pages report.

 

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. Otherwise, each domain will have their own cookie and visitor profile of the same person.

 This merging can take place when one of two things happens:

  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, 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, click to toggle the Limit tracking to these domains switch on, then click Save

limit-tracking-to-these-domains