How to install the HubSpot tracking code

Last updated: November 20, 2017

Available For:

Marketing: Free, Starter, Basic, Pro, Enterprise
Sales: Free, Starter, Professional

If you're not hosting your entire website on HubSpot, or have pages of 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. This article will show you how to begin tracking your website activity within HubSpot. 

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.

Your tracking code is installed automatically on all of your HubSpot-hosted pages. But if you're not hosting your full site with HubSpot, you'll need to install the tracking code manually on your website.

1. Assign this task to someone on your team

  • If you do have access to the HTML of your website (or to your content management system), you can complete the steps below yourself.
  • If you do not have access to your website's HTML, email the URL of this article to your IT department or web developer. 
Please note: whoever is installing the tracking code will have to log in to HubSpot to complete the steps, so you need to create a HubSpot user account for them. For a refresher on creating a new HubSpot user account, click here.

2. Locate the tracking code in your HubSpot account

Navigate to the tracking code in your HubSpot account:

  • In your HubSpot Marketing Basic, Professional, or Enterprise account, navigate to Reports > Reports Settings. Then select Install Code & Tracking from the left sidebar menu, and click the Tracking code tab.

  • In your HubSpot Marketing Free or Starter account, navigate to Settings and then select Installation from the left sidebar menu. 

  • In your HubSpot Sales account, navigate to Settings and then select Install Code & Tracking from the left sidebar menu. Select the Tracking code tab at the top. 

If you're a HubSpot Sales Starter or Professional user and you're setting up your prospects tool, you can access the tracking code from Sales Tools > Prospects. Select Customize > View tracking code from the upper right-hand corner.  

3. Copy the HubSpot tracking code

Copy the tracking code provided in your account by clicking Copy or by highlighting the code and using the copy function on your keyboard.

Please note: the tracking code is different for every HubSpot account and corresponds to your HubSpot account number.

4. Paste the code above the closing body tag on each website page

Paste the code immediately before the </body> tag in the HTML code for each page of your site. Here's what the code would look like just before the tag in an HTML code view of a page: 

You can then test to make sure your tracking code is working by following the instructions here.

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

Please note: because every website/CMS is structured differently, we can't provide you with 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 document 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.

How to install the tracking code on a WordPress website with the plugin

To install the HubSpot tracking code on a WordPress site, install the HubSpot Tracking Code for WordPress plugin within your WordPress instance. 

The plugin performs the following actions:
  • Installs the HubSpot tracking code on your WordPress site.
  • Sets content type for filtering between pages and posts in your page performance tool.
  • Creates contacts with a lifecycle stage of Subscriber when non-HubSpot forms are filled out on the site.
Please note: the HubSpot Tracking Code for WordPress plugin replaces the HubSpot for WordPress plugin. Unlike the older plugin, this plugin does not include various deprecated features and improves the reliability of the plugin. Forms and CTAs should now be embeded directly in the WordPress editor. WordPress no longer transmits meta information such as publish date and comment count to your page performance tool. 

Requirements

  • Your website or blog must be using a WordPress.org install. The tracking code plugin cannot be installed on WordPress.com sites, as they do not allow you to add plugins or Javascript.
  • You must have WordPress version 3.0 or higher installed on your server (the latest version is recommended).
  • The wp_footer function must be included in your WordPress theme’s footer file (footer.php). This function is required for the tracking code to be installed on every page of your site.
  • You must be a WordPress admin to install plugins for your site. If you are not the admin, you can forward these instructions to the person who manages your WordPress install.

1. Log in to your WordPress account

Log in to your WordPress account. You can generally access the login screen by adding /wp-admin to your URL. 

HubSpot Help article screenshot

2. Add new plugin

Hover over the Plugins menu item in the WordPress side menu and then click Add New.

HubSpot Help article screenshot

3. Search for the HubSpot plugin

Type HubSpot Tracking Code into the search field and click Search Plugins to search for the HubSpot plugin.

HubSpot Help article screenshot

4. Install the plugin

Click Install Now to install the latest version of the HubSpot Tracking Code for WordPress plugin into your WordPress website.

HubSpot Help article screenshot

5. Activate the plugin

Click the Activate Plugin link to activate the plugin for your WordPress website.

HubSpot Help article screenshot

You'll see a Plugin activated message to confirm that the plugin is active. Next you'll configure the plugin to work with your HubSpot account.

HubSpot Help article screenshot

6. Edit plugin settings

Hover over the Settings menu item in the WordPress side menu and click HubSpot Settings.

HubSpot Help article screenshot

7. Enter your Hub ID

Enter your Hub ID and click Save Settings.

HubSpot Help article screenshot

How to install the tracking code on a WordPress website without the plugin

While it is recommended that you use the HubSpot tracking code for WordPress plugin, you can alternatively install the tracking code manually. If you manually add the tracking code and are a HubSpot Marketing Basic, Professional, or Enterprise user, 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. 

The instructions below walk through installing the tracking code manually on your WordPress site: 

  • 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.  

  • Select Footer in the left sidebar menu. Then paste in the tracking code and select Update File

How to install the tracking code on a Shopify site

The instructions below walk through installing the tracking code on a Shopify site:
  • 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, select Online Store > Themes.    

  • Towards the right side of your screen, select Actions > Edit code.
  • In this screen, select the theme.liquid file for your theme.  

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

How to install the tracking code on a Drupal site

The instructions below walk through installing 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 click Structure in the main navigation menu. Then select Blocks.    

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

How to install the tracking code on a Magento site

The instructions below walk through installing the tracking code on a Magento site:  

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

How to install the tracking code on a Wix site

To install the HubSpot tracking code on your Wix website, you'll need to use the App Market in Wix to add an HTML widget to your page. The instructions below walk through installing the tracking code on a Wix site:  

  • Follow the steps above to copy the HubSpot tracking code in your HubSpot account.   
  • Navigate to your website editor in your Wix account. Then click App Market on the left-hand side. 
  • From this window, search for html until you find HTML iFrame/Embed app made by Wix and click + Add to Site.  

  • Once this widget has been added to your site, click the settings (gear) icon within this module and click the radio button next to Code. Then insert your HubSpot tracking code into the text box within that window and click Update

Please note: because Wix does not support custom coding, the HubSpot tracking code must be added to each Wix page using an HTML iFrame. Because most browsers set the referer HTTP header to the iFrame file location rather than the URL of the page being viewed, your pages report (if you are a Marketing Basic, Professional, or Enterprise user) may only show data for the iFrame URLs rather than the actual page URLs.

How to 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 accunt 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

How to install the tracking code on a Squarespace site

The instructions below walk through installing the tracking code on a Squarespace site (you can also learn more about code injection for Squarespace here): 

  • Follow the steps above to copy the HubSpot tracking code in your HubSpot account. 
  • Log in to your Squarespace account and select Settings in the left sidebar menu.  

  • Under the Website section of the menu, navigate to Advanced, then Code Injection
  • Paste the tracking code into the Header field and then click Save

How to install the tracking code using Google Tag Manager

The instructions below walk through adding the tracking code as a tag 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-hand corner to save your container and tags.  

  • Add the Google Tag Manager code to your website pages below 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?

Previous article:

Next article: