How to install the HubSpot JavaScript tracking code
Who is this document for?
All Professional and Enterprise HubSpot customers that want to use HubSpot's website analytics on a non-HubSpot hosted website. HubSpot Basic customers must have their entire websites hosted on HubSpot, so they can skip to the next steps at the bottom of this article.
What does this document tell me?
The HubSpot tracking code is what makes the HubSpot website analytics work with your site if you are not hosted with HubSpot.
Here's exactly what it does for you:
- Allows HubSpot to tell you how your website is generating traffic and leads.
- Lets you see what you can do to improve your website traffic.
- Lets HubSpot provide you with sophisticated lead intelligence that enables you to turn more website leads into customers.
The tracking code is installed out of the box on any HubSpot hosted pages, but if you are not hosting your full site with HubSpot you must install the tracking code on your website. The sooner you get your JavaScript installed on all of your website pages, the sooner you’ll be able to start getting value out of HubSpot!
Do you use Wordpress or Joomla?
We have specific instructions on how to install the tracking code if you are hosting your site with Wordpress or Joomla that are linked to below:
General Instructions for a non-HubSpot hosted website
1. Assign this task to someone on your team
- If you DO have access to the HTML of your website (or 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 – they should be able to complete these steps in no time flat.
2. Go to your Reports Settings
Log into HubSpot, and click on Reports > Reports Settings.
3. Copy the HubSpot Javascript tracking code
Copy the tracking code provided in your account using the Copy to clipboard button or by highlighting the code and using the copy function of your keyboard.
4. Paste the JavaScript above the </body> tag on each website page
Paste the code immediately before the </body> tag in the HTML code of each page of your site. Here's what the code would look just before the </body> tag in an HTML code view of a page:
Most content management systems & IT departments have a way to batch-upload a piece of code to all pages of your site. If you don’t have access to your content management system, send these instructions to the person who does. Sometimes this comes in the form of a footer file that is referenced across all pages.
5. Verify that the code installation worked
Go back to HubSpot's report settings and use the Validate your Installation input to check that your tracking code was properly installed.
Next Steps:
- Filter out traffic from your internal networks so that you don't skew your analytics.
- Set your timezone so that Analytics reflect the timezone that your business is physically located in.
- Track traffic across multiple domains (if you have multiple domains).
- Limit visitor tracking in HubSpot to specific domains.
- Enable a Privacy Policy popup if you are doing business in Europe.
- Add more users to your HubSpot account.





