How to install tracking code on HubSpot
Installing HubSpot tracking code involves copying the tracking snippet from your HubSpot account settings and adding it to your website's HTML before the closing tag. The code automatically tracks visitor behavior and enables HubSpot's analytics and marketing features.
Prerequisites
- Active HubSpot account
- Website administrator access
- Basic understanding of HTML/JavaScript
Step-by-Step Instructions
Access your HubSpot tracking code
Copy the tracking code snippet
<!-- Start of HubSpot Embed Code -->
<script type="text/javascript" id="hs-script-loader" async defer src="//js.hs-scripts.com/XXXXXXX.js"></script>
<!-- End of HubSpot Embed Code -->Access your website's HTML code
Locate the closing </head> tag
</head> tag in your website's HTML code. This is typically located in the header template file (header.php for WordPress) or the main HTML template. The tracking code must be placed immediately before this closing tag.Paste the tracking code
</head> tag. Ensure there's a line break between the tracking code and the closing head tag for clean formatting:<!-- Start of HubSpot Embed Code -->
<script type="text/javascript" id="hs-script-loader" async defer src="//js.hs-scripts.com/XXXXXXX.js"></script>
<!-- End of HubSpot Embed Code -->
</head>Save and publish changes
Verify tracking code installation
Common Issues & Troubleshooting
Tracking code shows as 'Not Installed' after 24 hours
Verify the code is placed before the </head> tag, not in the <body>. Check that your website cache has been cleared and that no security plugins are blocking the script. Also ensure you haven't modified the tracking code snippet.
Website loading slowly after installing tracking code
The HubSpot tracking code is designed to load asynchronously and shouldn't affect page speed. Check for conflicting scripts or plugins. Consider placing the code just before </body> instead of </head> if speed is critical, though this may delay data collection.
Tracking code not working on all pages
Ensure you've added the code to your main template file that's used across all pages, not just individual page files. For WordPress, add it to header.php of your active theme. For other CMS platforms, add it to the global header template.
Console errors related to HubSpot script
Check that the Hub ID in your tracking code matches your HubSpot account. Verify there are no syntax errors in the code placement and that the script URL is accessible. Try regenerating the tracking code from HubSpot settings if the issue persists.