How to Install HubSpot Tracking Code on Your Website

·
September 16, 2024
·
2
minutes
linkedin logotwitter logoyoutube logohubspot

Need to install the HubSpot tracking code on your website? You're in the right place!

This article will guide you through each step to ensure your tracking code is set up correctly, letting you monitor website traffic and gather essential analytics.

Whether your website is hosted on HubSpot, WordPress, or other platforms, this article provides clear, actionable steps to get it right.

What Is the HubSpot Tracking Code?

The HubSpot tracking code is a powerful tool that allows HubSpot to monitor website traffic and provide valuable insights into user behavior.

Once installed, the tracking code collects data on visitors, such as the pages they view, how long they stay, and their actions on your site. This data is then tied directly to contacts in your HubSpot CRM, enabling more personalized marketing efforts and targeted sales outreach.

Tip : Use tracking URLs to gain more detailed insights into specific campaign performance and visitor behavior, helping you refine your marketing strategies effectively.

Key Benefits:

  • Track Behavior: Understand which content attracts the most engagement.
  • Monitor Conversions: Follow visitors through the sales funnel and track their key actions.
  • Optimize Campaigns: Use data insights to refine emails, ads, and content for better results.

What is the Difference between HubSpot Tracking Code and Google Analytics?

Unlike Google Analytics, which focuses on general web traffic data like bounce rates and page views, the HubSpot tracking code connects visitors’ behavior with specific contacts in your CRM, providing a holistic view of their journey through the funnel—from the first site visit to conversion.

Where to Find the HubSpot Tracking Code?

  • Log in to your HubSpot account.
  • Navigate to Tracking & Analytics > Tracking code
  • Copy your HubSpot tracking code.

How to Install the HubSpot Tracking Code

The method of installing the HubSpot tracking code depends on your website platform.

Below are step-by-step instructions for different platforms, including manually adding the code and using Google Tag Manager.

Manual Installation for Any Website

This method works for any website that isn't hosted on HubSpot.

  • Copy the HubSpot Tracking Code
In your hubspot account, copy the embed code section
  • Then, open your website’s HTML code (Ctrl + U). Locate the closing </body> tag on every page you want to track, then paste the HubSpot tracking code right before the </body> tag.
Paste hubspot tracking code manually in the html code to every landing pages you want to track
  • After inserting the code, save and click publish the page.
  • Repeat this process for all pages you want to track.
Tip : Make sure you don’t accidentally place more than one HubSpot tracking code on a single page. I’ve made that mistake before, and it messed up all the data! Once I fixed it by keeping just one code, everything ran smoothly, and the insights were much more accurate.

Installing the HubSpot Tracking Code Using Google Tag Manager

Google Tag Manager (GTM) allows you to manage and deploy tags on your website pages without manually editing the code each time.

Here's how to use GTM to install the HubSpot tracking code:

  • Log In to Google Tag Manager Account
    • If you don't have a GTM account, create one at tagmanager.google.com.
    • Set up a container for your website.
  • In your GTM account, click on Tags in the left sidebar, then click New.
  • Choose Tag Configuration and select Custom HTML.
Install the tracking code in Google Tag Manager and choose custom html tag
  • Paste the HubSpot Tracking Code into the HTML field.
  • Under Triggering, choose All Pages to ensure the tag fires on every page of your site.
  • Once everything is set, click Save, then Submit to publish the changes to your site.

Installing the Tracking Code on WordPress

For WordPress users, the easiest way to install the HubSpot tracking code is through the HubSpot Wordpress Plugin, which automatically installs the tracking code into your WordPress website, eliminating manual installation. Here’s how you can install the plugin:

  • Log in to your WordPress account.
  • Go to Plugins > Add New and search for "HubSpot All-in-One Marketing".
  • Install and activate the plugin.
Find the HubSpot Plugin in WordPress for your wordpress website tracking | hubspot wordpress plugin
  • Once activated, the plugin will prompt you to connect your HubSpot account. Follow the instructions to authenticate the connection.
  • The plugin automatically installs the HubSpot tracking code across your entire WordPress site.

Alternatively, if you don’t want to use a plugin, you can also manually install it. Here is how you can do it :

Personal recommendation: Use the HubSpot All-in-One Marketing plugin to ensure your tracking code stays updated automatically, letting you focus on data analysis rather than manual code installation.

Installing the Tracking Code on Shopify

Now if you're using Shopify as your e-commerce platform, here's how to add the HubSpot tracking code to your store:

  • Log in to your Shopify admin account
  • Navigate to Online Store > Themes > Edit Code.
Shopify and HubSpot tracking code | In the left sidebar menu access theme files and edit code to install the tracking code
  • Open the theme.liquid file.
  • Scroll down to the closing </body> tag and paste the HubSpot tracking code right before it.
Shopify and HubSpot - edit html code - insert tracking code
  • Click Save to apply the tracking code to all your pages.

Installing the Tracking Code on Wix

If you're using Wix, you can add the HubSpot tracking code using an HTML widget from the Wix App Market, which allows embedding custom HTML code into your site.

This method offers flexibility, as you can configure the HTML widget to load on specific pages, ensuring all your analytics data is captured.

To set it up:

  • Copy the code from your HubSpot account, as described in the Manual Installation section.
  • In your Wix dashboard, go to Settings
  • Click the Custom Code tab in the Advanced section.
Wix - access edit code - hubspot tracking
  • Click + Add Custom Code at the top right.
  • Paste the code in the provided field, and set it to load on All Pages.
  • Place it in the Body - End section, then click Apply.

Installing the Tracking Code on a Joomla site

To install the HubSpot tracking code on a Joomla site, you have two options:

  • Option 1: Use an Extension You can choose an extension from the Joomla Extension Directory, where you'll simply paste the HubSpot tracking code for easy integration.
  • Option 2: Manual Installation For a more hands-on approach, manually insert the code into your template:
    • Log in to your Joomla account as an administrator.
    • Navigate to Extensions > Templates .
    • Select your template and open the index.php file.
    • Paste the HubSpot tracking code just above the closing </body> tag.
    • Click Save.
Tip : From my experience, it's always best to pick the installation method you're most comfortable with. It makes the process smoother and avoids any headaches later!

Verifying the Installation of the Tracking Code

After installing the HubSpot tracking code, it’s important to verify that everything is working correctly. Follow these steps to check:

  1. Inspect the Page Source
    • Open any page on your site.
    • Right-click and select View Page Source.
    • Use the search function (Ctrl+F or Command+F) to find your Hub ID followed by .js in the code. If it’s there, the code is installed.
  2. Check via Network Tab
    • In your browser, open the Developer Tools (usually F12).
    • Go to the Network tab and refresh the page.
    • Look for your HubSpot tracking code in the list of requests. If you see a 200 OK status, the code is functioning.
Use the web developer tools to check if the tracking code is well installed in your website pages and capture analytics

Advanced Configuration Options

Once your tracking code is installed, you can customize it for more advanced tracking.

Tracking Multiple Domains

If you have multiple domains, HubSpot can track visitors across these domains by adding them to your HubSpot settings. This ensures accurate cross-domain tracking and attribution.

In your HubSpot account:

  • Go to Settings > Tracking & Analytics > Tracking Code.
  • Click the Advanced Tracking tab.
  • Click + Add domain at the bottom of the Additional site domains table.
Tracking Multiple Domains in HubSpot using the tracking code

Customizing Your Tracking Code

For advanced users, you can modify the HubSpot tracking code to track specific events or user behaviors. For example, you can track:

  • Button clicks
  • Form submissions
  • Video plays

This requires additional JavaScript to customize the data being sent to HubSpot.

Common Issues and Troubleshooting

While the installation process is straightforward, you might encounter some issues. Here’s how to address common problems:

  • Multiple Tracking Codes: Ensure that there is only one HubSpot tracking code per page. Multiple HubSpot tracking codes can cause errors and inaccurate data.
  • Ad Blockers: Some users may have ad blockers installed that prevent the tracking code from working. While you can't control this, it’s something to be aware of when analyzing your data.
  • Incorrect Placement: Double-check that the code is placed just before the closing </body> tag on every page you want to track.

Best Practices

To get the most out of your HubSpot tracking code, follow these recommendations:

  • Avoid Installing Multiple Tracking Codes: Only one HubSpot tracking code should be present per page.
  • Use a Plugin for WordPress: If you’re using WordPress, the HubSpot plugin is the easiest way to ensure accurate installation.
  • Verify Installation: Always check the code using the methods outlined above to ensure it’s working properly.
  • Optimize Data Collection: Customize the tracking code to exclude internal traffic and irrelevant data for more accurate reporting.

Key Takeaways

  • Installing the HubSpot tracking code is crucial for tracking visitor behavior and connecting it to your CRM.
  • Installation varies by platform (e.g., WordPress, Wix) with manual options or plugins for ease.
  • After setup, verify the code and troubleshoot to ensure accurate data collection and analytics.

Frequently Asked Questions

How to use a tracking code?

To use a tracking code, simply copy and paste it into the HTML of your website or landing page, just before the closing </body> tag. The exact steps depend on the platform you're using.

What does the HubSpot tracking code do?

The HubSpot tracking code tracks page views, identifies visitors, and captures event data. It also allows you to manually track page views and create custom events via the API.

What is the difference between HubSpot tracking code and Google Analytics?

HubSpot de-anonymizes visitor data, linking actions to specific contacts, while Google Analytics tracks anonymous user behavior. HubSpot provides a detailed view of individual visitor journeys.

Why do HubSpot and Google Analytics not match?

Differences in cross-domain tracking settings can cause discrepancies between HubSpot and Google Analytics data. Ensure both tools have the same domains enabled for consistent tracking.

How do I obtain my HubSpot tracking code?

Go to your HubSpot account settings, navigate to Tracking & Analytics, and select Tracking Code to copy your unique tracking code for your site.