How to Install the HubSpot Tracking Code on Your Site
The HubSpot tracking code is essential for tracking visitors, logging page views, and capturing analytics across your website. This guide explains, step by step, how to find, install, and verify the tracking script so your data flows correctly into your HubSpot account.
What the HubSpot Tracking Code Does
Before you add the script, it helps to understand why the HubSpot tracking code matters.
- Tracks page views for contacts and visitors.
- Enables behavioral analytics and attribution.
- Connects form submissions and chat interactions to sessions.
- Supports reports, lists, and automation based on website activity.
Without the script installed correctly on every page, HubSpot may miss traffic or misattribute sessions, which can affect your reporting and automation.
Where to Find Your HubSpot Tracking Code
You generate and copy your unique script from within your HubSpot account. The interface may change over time, but the core flow is consistent.
- Log in to your HubSpot account with admin access.
- Navigate to your settings area.
- Open the tracking or reporting section where the tracking code is listed.
- Locate the
<script>snippet that references your portal ID. - Click to copy the full code snippet to your clipboard.
The tracking code is typically a JavaScript snippet that loads asynchronously. It must be copied exactly, without edits to the script body other than approved domain-level configuration options provided inside HubSpot.
How to Add the HubSpot Tracking Code to a Website
You can add the script manually or through a content management system. The best practice is to insert the HubSpot tracking code into a global template or header file so it loads on every page by default.
General Placement of the HubSpot Code
For most websites, the correct placement is near the closing </body> tag.
- Open the HTML template or theme file that controls your site layout.
- Locate the main
<body>section of the page. - Paste the HubSpot tracking code directly before the closing
</body>tag. - Save and publish or deploy your changes.
If you use multiple templates, ensure each template that serves public pages contains the script. A global header or footer file is usually the simplest place to insert the tracking snippet once for all layouts.
Installing the HubSpot Tracking Code in a CMS
Many content management systems provide a specific setting or field where third-party tracking scripts can be added.
- WordPress or similar CMS: paste the code into a header or footer script area provided by your theme or a tracking plugin.
- Hosted site builders: use the site-wide custom code settings, often found under analytics, tracking, or advanced settings.
- Custom frameworks: add the snippet to the base layout template used across pages.
The goal is the same regardless of platform: the HubSpot tracking code must load on every page where you want to track visits and actions.
Using the HubSpot Tracking Code on Non-HubSpot Pages
If your website is not hosted on HubSpot, or only some pages are hosted there, you must still add the script to all external pages for unified analytics.
For non-HubSpot pages:
- Copy the same unique script from your account.
- Insert it into the external site templates or global tag manager.
- Verify that the script appears on all important landing pages, blog posts, and other key URLs.
This ensures that visits to external pages are associated with the same contacts and sessions inside HubSpot.
Managing Multiple Domains with the HubSpot Code
If you track more than one domain, confirm that each domain is configured within your account settings.
- Add every domain you plan to track in your domain settings.
- Use the same tracking script unless your documentation instructs otherwise.
- Check that cookies and tracking settings align with your privacy requirements for each domain.
By configuring domains correctly and deploying the script on each one, all visitor activity will be stored in the same HubSpot portal as appropriate.
Verifying That the HubSpot Tracking Code Is Installed
After installing the script, you should test that it is firing correctly.
Check the HubSpot Tracking Status
- Open your HubSpot account.
- Go to the section where tracking status or code installation is displayed.
- Enter a page URL from your site, if prompted, to test.
- Look for a confirmation that the tracking code was detected.
If the status shows that the code is missing, double-check that your latest template or deployment includes the snippet and that caching or CDN layers are not serving an older version without it.
Use Browser Tools to Confirm the HubSpot Script
Beyond the built-in checks, you can confirm the HubSpot tracking code manually.
- Open your website in a browser.
- View the page source and search for the tracking script.
- Use the network panel of developer tools to look for network calls to the tracking endpoint.
- Reload the page to confirm that the script loads without errors.
Some browsers or extensions can block tracking scripts, so test with tracking protection disabled to ensure that the script itself is functioning correctly.
Troubleshooting Common HubSpot Tracking Issues
Problems with analytics are often caused by a few recurring issues. Use these checks if you suspect the HubSpot tracking code is not working properly.
- Script not on all pages: confirm the code appears in every template.
- Incorrect placement: ensure you did not place the script inside another script tag or in a location where it is commented out.
- Multiple conflicting scripts: avoid adding duplicate or outdated versions of the code.
- Cache or CDN problems: purge caches after updating templates with the script.
- Consent and cookies: if you use consent banners, verify that the HubSpot tracking code is allowed to run after users accept tracking.
If issues continue, consult the official installation instructions directly on the HubSpot knowledge base at this tracking code guide for the most up-to-date technical details.
Best Practices for Ongoing HubSpot Tracking
Once the HubSpot tracking code is in place, maintain it as your site evolves.
- When launching new templates or microsites, include the script from the start.
- Periodically test a few URLs to confirm the script is still present.
- Review analytics to spot any sudden drops in page views that could signal tracking issues.
- Coordinate with developers so that redesigns or migrations do not remove the tracking snippet.
Keeping this simple script active and consistent ensures reliable contact and traffic data across your entire digital presence.
Get Help with HubSpot Tracking Implementations
If you need expert assistance beyond the basics of installing the HubSpot tracking code, consider working with a dedicated implementation and optimization partner. For additional resources and consulting on marketing operations, you can visit Consultevo to explore support options for complex configurations and multi-site setups.
With the tracking code installed correctly and monitored regularly, you can rely on accurate analytics, better lead attribution, and more powerful automation inside HubSpot.
Need Help With Hubspot?
If you want expert help building, automating, or scaling your Hubspot , work with ConsultEvo, a team who has a decade of Hubspot experience.
“`
