Reports

Install the HubSpot tracking code

Last updated: October 17, 2018

free

If you're not hosting your entire website on HubSpot, or have pages on your website that are not hosted on HubSpot, you'll need to install the HubSpot tracking code on your non-HubSpot pages in order to capture those analytics.

The HubSpot tracking code helps you monitor:

  • How well your website is generating traffic and leads.
  • What you can do to improve your website traffic.
  • Sophisticated lead intelligence that enables you to turn more website leads into customers.

If you're using a single-page application, refer to the developers documentation to set up tracking.

Copy the tracking code in your HubSpot 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.
  • Below the Embed code field, 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. 

Please note: the user installing the tracking code must log in to HubSpot to complete the steps. If you have an IT person or web developer installing the code, a HubSpot user account must be created for them in order to complete the installation process. 

copy-tracking-code

If you're a HubSpot CRM or Sales Hub user and you're setting up your prospects tool, you can access the tracking code from the prospects dashboard:

  • In your HubSpot account, navigate to Reports > Analytics Tools.
  • Click Prospects.
  • Click Actions, then select View tracking code.

code-from-prospects

  • In the dialog box, click Copy.
Please note: the tracking code is different for every HubSpot account and corresponds to your HubSpot account number.

Paste the tracking code on each website page

Paste the code immediately before the </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.

Below are more specific instructions for pasting the code on different website hosts: 

Please note: follow the instructions below for WordPress if you are not using the Contact Form Builder for WordPress - Conversion Tools by HubSpot.

Learn more about using the Contact Form Builder for WordPress - Conversion Tools by HubSpot.

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, email this article to your webmaster, IT department, or technical resource.

Most content management systems and IT departments have a way to batch-upload a piece of code to all pages of your site. Sometimes this comes in the form of a footer file that is referenced across all pages. If you don’t have access to your content management system, send these instructions to the person who does. 

Install the tracking code on a WordPress website without the plugin

While it is recommended that you use the Contact Form Builder for WordPress - Conversion Tools by HubSpot, 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 posts versus pages in its reporting. 

Please note: if your website is hosted on wordpress.com, you will not be able to add the HubSpot tracking code to your website. WordPress does not allow users to add any JavaScript code to wordpress.com sites because it is a shared environment. 

  • Follow the steps above to copy the HubSpot tracking code in your HubSpot account. 
  • Log in to your WordPress account and then navigate to Appearance > Editor in the left sidebar menu.  

  • 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 sidebar menu on the left, 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 and select Structure in the main navigation menu. Then, select 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, 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, and then 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. Then, 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 and navigate to Settings in the left sidebar menu.  

  • Under the Website section of the menu, navigate to Advanced, then select Code Injection
  • Paste the tracking code into the Header field and then 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 and select your container
  • Create a new tag for the HubSpot tracking code by clicking Tags in the left sidebar menu, and then select 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. Please note that if you do not set up a firing rule, then 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, and then click Publish in the upper right corner to save your container and tags.  

  • Add the Google Tag Manager code to your website pages before the </body> tag, if not already installed. The Google Tag Manager code is available in your Google Tag Manager account under the Admin tab and then under Install Google Tag Manager

Was this article helpful?

If you still need help you can get answers from the , or to contact support.