Tracking Code

Install the HubSpot tracking code

Last updated: October 28, 2019

The HubSpot tracking code helps you monitor your website's traffic. The tracking code is automatically included on HubSpot blog posts, landing pages, and website pages. If you have pages on your website that are not hosted on HubSpot, you must install the HubSpot tracking code to capture analytics for those pages. 

Please note:

  • You should not install multiple HubSpot tracking codes on a page. If there are multiple HubSpot tracking codes installed, the first one to load on the page will fire; any subsequent HubSpot tracking codes will not work.
  • If your IT admin or web developer is installing the code, they must have a HubSpot user account.
  • If you're using a single-page application, refer to the developers documentation to set up tracking.
  • If you're hosting entire domains or subdomains externally, you must also add your domain(s) and/or subdomain(s) to your settings in HubSpot.
  • The tracking code is not supported on AMP sites. 

Copy the tracking code from your HubSpot account

Follow the steps below to copy and install your tracking code. If you have already installed the tracking code, learn how to verify installation and troubleshoot

Set up analytics tracking on your external website

If you're a Marketing Hub user adding the tracking code to your external website:

  • In your HubSpot account, click the settings icon settings in the main navigation bar.
  • In the left sidebar menu, navigate to your Reports and Analytics Tracking settings:
    • In Marketing Hub Professional, Enterprise, and Basic (Legacy) accounts, navigate to Reports > Tracking Code
    • In Marketing Hub Starter accounts and free CRM accounts, navigate to Tracking Code.
  • Below the Embed code section, click Copy or click Email to my web developer to send the tracking code to the team member who will be installing it on your site.

    copy-tracking-code

Set up the prospects tool

To set up the prospects tool in your HubSpot CRM or Sales Hub account:

  • In your HubSpot account, navigate to Reports > Analytics Tools
  • Click Prospects.
  • If you're setting your prospects tool up for the first time:
    • Click Install HubSpot on your website.
    • In the right panel, select No, then click Next.
    • Click Copy to copy the tracking code.

Please note: if you're using Wordpress, select Yes, and then click Next, to access a link to HubSpot All-in-One Marketing - Forms, Pop-ups, Live Chat WordPress plugin.

  • If you've set up your prospects tool already:
    • In the upper right, click the Actions dropdown menu and select View tracking code.
    • In the dialog box, click Copy.

Add a chatflow to your website

  • In your HubSpot account, navigate to Conversations > Inbox.
  • In the bottom left corner, click Inbox Settings, then select Chat
  • Click the Tracking code tab.  
  • Click Copy or enter an email address to send the code to your web developer or IT resource. 

Please note: the tracking code is different for every HubSpot account; you must copy the code directly from your account.

  • Paste the code immediately before the closing </body> tag in the HTML code for each page of your site. You can then test your HubSpot tracking code to verify it is working.


Install the tracking code on your website

Most content management systems and IT departments can deploy a piece of code to all pages on your site, such as a footer file that is referenced across all pages.

Please note: because every website/CMS is structured differently, these steps may not be the exact instructions on how to access your HTML code. If you're not sure how to access the HTML code of your site, send this article to your webmaster, IT department, or technical resource.
 

Install the tracking code on a WordPress website without the plugin

While it is recommended that you use the HubSpot All-in-One Marketing - Forms, Pop-ups, Live Chat WordPress plugin, you can also install the tracking code manually. If you manually add the tracking code and have a HubSpot Marketing Hub Basic, Professional, or Enterprise account, HubSpot will not be able to differentiate WordPress posts versus pages in analytics.

Please note: if your website is hosted on WordPress.com, you will not be able to add the HubSpot tracking code to your website unless you are on their Business plan. The other plans (e.g., Premium, Personal) do not allow users to add any JavaScript code.

  • Follow the steps above to copy the HubSpot tracking code in your HubSpot account.
  • Log in to your WordPress account.
  • In the left sidebar menu, navigate to Appearance > Editor.
  • In the list of theme files on the right side of the editor, select Footer.
  • Paste in the tracking code and select Update File.

 

Install the tracking code on a Shopify site

Please note: if you're using the Shopify integration, you don't need to install the tracking code separately.

  • Follow the steps above to copy the HubSpot tracking code in your HubSpot account.
  • Log in to your Shopify admin dashboard.
  • In the left sidebar menu, navigate to Online Store > Themes.
  • Click the Actions dropdown menu and select Edit code.
  • Select the theme.liquid file for your theme.

  • Paste your HubSpot tracking code just before the </body> tag in this file.
  • In the upper right, click Save.

 

Install the tracking code on a Drupal site

  • Follow the steps above to copy the HubSpot tracking code in your HubSpot account.
  • Log in to your Drupal admin dashboard.
  • In the main navigation menu, navigate to Structure.
  • Click Blocks.

  • Click + Add Block.
  • Enter the fields for your new block. Paste the tracking code in the Block body field, and then click Save block.

 

Install the tracking code on a Magento site

Follow the steps above to copy the HubSpot tracking code in your HubSpot account. Then follow Magento's design user guide for instructions on installing third-party JavaScript code in the Header HTML.

 

Install the tracking code on a Wix site

Use the App Market in Wix to add an HTML widget to your page:

  • Follow the steps above to copy the HubSpot tracking code in your HubSpot account.
  • Navigate to your Site Manager.
  • In the left sidebar menu, navigate to Tracking and Analytics.
  • Click Custom or Add new tool > Custom.
  • Paste the tracking code in the Paste code snippet here field.
  • Set the Name of the new tool to HubSpot Tracking Code.
  • Under Add Code to Pages click the radio button for All pages and use the dropdown menu to select Load code on each new page.
  • Under Place Code in section, click the radio button for the Body - end option.
  • Click Apply to save your changes.
 
 

Install the tracking code on a Joomla site

There are two ways to add your HubSpot tracking code to your Joomla site. With either method, you'll first need to copy your HubSpot tracking code following the steps above.

You can select an extension from the Joomla Extension Directory where you can paste in the HubSpot tracking code. Alternatively, you can follow the steps below to install the tracking code:

  • Log in to your Joomla account as an administrator.
  • In the main navigation menu, navigate to Extensions > Templates > Templates.
  • Click the name of your template and select index.php in the left sidebar menu.
  • Paste the HubSpot tracking code directly above the </body> tag.
  • Click Save.

 

Install the tracking code on a Squarespace site

  • Follow the steps above to copy the HubSpot tracking code in your HubSpot account.
  • Log in to your Squarespace account.
  • In the left sidebar menu, navigate to Settings.
  • In the Website section of the menu, navigate to Advanced, then select Code Injection.
  • Paste the tracking code into the Header field.
  • In the upper left, click Save.

 

Install the tracking code using Google Tag Manager

  • Follow the steps above to copy the HubSpot tracking code in your HubSpot account.
  • In a new browser tab or window, log in to your Google Tag Manager account.
  • Select your container.
  • In the left sidebar menu, navigate to Tags.
  • Click New.

  • Click Tag Configuration.
  • For the Tag type, choose Custom HTML Tag. Then, give your tag a name.
  • Paste the tracking code in the HTML field.
  • Below Tag Configuration, click Triggering to set up a firing rule. If you don't set up a firing rule, the tag will not fire and HubSpot analytics data will not be collected.
  • For the tag to fire on all pages with the Google Tag Manager code installed (recommended), select the option for All Pages.

  • Click Save to save your new tag.
  • In the upper right, click Publish to save your container and tags.