How do I add my HubSpot tracking code to my website?
The HubSpot tracking code lets HubSpot record visits and activity on your website. It's unique to each HubSpot account. Pages hosted in HubSpot (blog posts, landing pages and website pages) include it automatically. For any page hosted elsewhere, such as a WordPress site, you need to add it yourself.
Without the tracking code, HubSpot can't track page views or visitor activity on that page. It also won't capture non-HubSpot form submissions, and features like live chat won't load.
Before you start:
- Install the code only once per page. If a page has more than one HubSpot tracking code, only the first one loads.
- The person installing it needs a HubSpot user account.
- Some setups aren't supported. The code doesn't work on AMP pages, and single-page applications need extra developer setup.
- Ad blockers can prevent tracking for some visitors.
- Plan for privacy. The code sets cookies in visitors' browsers, so make sure your site has an appropriate cookie consent banner. HubSpot also uses some tracking data to improve its products, including its Breeze Intelligence dataset. You can turn this off in your account settings.
Step 1: Copy your tracking code
- In HubSpot, click the settings icon in the top navigation bar.
- Open your Tracking & Analytics settings:
- Free tools or Marketing Hub Starter only: click Tracking Code in the left sidebar.
- All other subscriptions: click Tracking & Analytics > Tracking code in the left sidebar.
- In the Embed code section, click Copy, or click Email to my web developer to send it to whoever will install it.
Step 2: Install the code on your website
Paste the code just before the closing </body> tag on every page you want to track. Most websites have a shared footer used by every page, so adding it there once covers the whole site. If you're not sure how to do this on your site, contact the Gate 39 team.
WordPress (recommended method)
Install the official HubSpot WordPress plugin and connect it to your HubSpot account. It adds the tracking code to every page automatically, and it isn't lost when your theme updates. If you use the plugin, don't also add the code manually.
WordPress (if you can't use the HubSpot plugin)
Use a header and footer code plugin, such as WPCode, to add the tracking code to the site footer on all pages. Avoid pasting the code directly into your theme's files. It will be erased the next time the theme updates, and many hosts block theme file editing.
WordPress notes:
- With a manual install, HubSpot Marketing Hub can't tell your WordPress posts apart from your pages in its analytics.
- Sites on WordPress.com can only add the tracking code on the Business plan or higher.
Google Tag Manager
- In Google Tag Manager, open your container and go to Tags > New.
- Click Tag Configuration and choose Custom HTML. Name the tag (e.g., "HubSpot Tracking Code") and paste the code into the HTML field.
- Click Triggering and select All Pages. Without a trigger, the tag won't fire.
- Click Save, then Submit or Publish to make it live.
For other platforms, including Shopify, Wix, Squarespace, Drupal, Joomla and Magento, see HubSpot's platform-specific instructions.
Step 3: Add your website domain in HubSpot
If your website isn't hosted in HubSpot, add its domain (and any subdomains) in your HubSpot tracking settings so the traffic appears in your analytics. See HubSpot's guide to setting up site tracking.
Step 4: Check that it's working
Visit your website in a new browser window, then confirm HubSpot is receiving data using HubSpot's tracking code troubleshooting steps. New traffic can take a little while to appear in reports.
Need help? Contact the Gate 39 team through the Customer portal.
References
[1] HubSpot – Install the HubSpot tracking code (updated Jul 21, 2026)
[2] HubSpot – Set up site tracking in HubSpot (updated Jun 12, 2026)
[3] HubSpot – Troubleshoot the HubSpot tracking code