Tracking Code

Install the HubSpot tracking code

Last updated: December 4, 2019

The HubSpot tracking code is unique to each HubSpot account and allows HubSpot to monitor your website traffic. The tracking code is automatically included on HubSpot blog posts, landing pages, and website pages.

If you have any externally hosted pages (i.e., pages not on HubSpot), you must install the HubSpot tracking code manually to capture analytics for those pages. 

Please note:

Copy your HubSpot tracking code

  • In your HubSpot account, click the settings icon settings in the main navigation bar.
  • Navigate to your Reports and Analytics Tracking settings:
    • In Marketing Starter only accounts and free CRM accounts, navigate to Tracking Code in the left sidebar menu.
    • For all other subscriptions, navigate to Reports > Tracking Code in the left sidebar menu.

Install the tracking code on your website

To install the tracking code, paste the code before the closing </body> tag in the HTML code for each page of your site. Once you've installed the tracking code, learn how to verify installation and troubleshoot the code.

At the same time, most content management systems and your developers can install code to all pages on your site, such as a footer file that is referenced across all pages. Check with your developers on how they can help do this.

The following sections may also help if you're using a specific content management system.

Please note: because every website 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, contact your webmaster, IT department, or developer and show them this article.
 

Install the tracking code on a WordPress website

It is strongly recommended that you install and use the HubSpot All-in-One Marketing - Forms, Pop-ups, Live Chat WordPress plugin. The plugin automatically installs the HubSpot tracking code on your WordPress website for you.

Only if you're unable to install the HubSpot WordPress plugin, you can manually install the HubSpot tracking 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.

Please note:
  • If you manually install the tracking code and have a HubSpot Marketing Hub subscription, HubSpot will not be able to differentiate between WordPress posts and pages in its analytics.
  • 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.

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.

 
/reports/install-the-hubspot-tracking-code