If you use HubSpot and have a WordPress website, you should track visitors and collect data. HubSpot can help you do that. It gives you a tracking code which you can place on your site. This tracking code enables HubSpot to collect information such as page visits, contacts, and more.
Let me walk you through how to add this code to your WordPress site — step by step—no need to be a developer. You can do this on your own.
What is a HubSpot Tracking Code?
A tracking code is a small piece of code. HubSpot gives it to you. It helps you see how people interact with your site. You can track things like:
- Page views
- Time spent on pages
- Contact form submissions
- Visitor behavior
This code is crucial for fully utilizing HubSpot’s CRM, emails, automation, and other tools.
Step 1: Get Your HubSpot Tracking Code
First, you need to get the tracking code from HubSpot.
- Log in to your HubSpot account.
- In the top right corner, click on your profile picture or settings gear icon.
- Go to Tracking & Analytics under the left sidebar.
- Click on Tracking Code.
- You will now see an extended code.
- Copy the whole code. You’ll paste this in WordPress later.
Step 2: Add the Code to WordPress
Now you need to paste this code into your WordPress site. You have a few ways to do that.
Option 1: Use a Plugin (Easy Method)
If you are not comfortable with code, this is the easiest way.
Recommended Plugin: Insert Headers and Footers
- Go to your WordPress dashboard.
- Click on Plugins > Add New.
- Search for “Insert Headers and Footers”.
- Install and activate it.
- Now go to Settings > Insert Headers and Footers.
- You will see a box called Scripts in the Header.
- Paste your HubSpot tracking code there.
- Click Save.
That’s it. Your tracking code is now live on your website.
Option 2: Add Manually to Theme (For Advanced Users)
If you are used to editing code, you can do it manually.
- Go to your WordPress dashboard.
- Click Appearance > Theme File Editor.
- Open the header.php file.
- Look for the </head> tag.
- Paste your HubSpot tracking code just before the </head> line.
- Click Update File.
Note: If your theme updates in the future, this code might get erased. Use a child theme if possible.
Step 3: Check If It’s Working
Once you have added the code, check if HubSpot is tracking your site.
- Go back to HubSpot.
- Open your Tracking Code section.
- It will show you whether the code is active on your site.
- If it says it’s not found, wait for a few minutes and check again.
You can also visit your site in an Incognito tab and check your HubSpot dashboard for any new activity.
What If You Use a Page Builder?
If you use Elementor, Divi, or another builder, you can still add the code:
- Many page builders have a Global Settings or Custom Code area.
- Look for Header Scripts or similar.
- Paste the HubSpot tracking code there.
- Save and refresh your site.
Why You Should Use This Tracking Code
You get many benefits:
- Understand how people use your site
- See what pages perform best
- Track contact forms
- Improve sales funnels
- Connect with HubSpot CRM and marketing tools
Without this code, you miss out on all that data.
Common Issues and Fixes
Code Not Showing Up?
- Make sure you pasted the complete code.
- Clear your site’s cache.
- Clear your browser cache.
- Wait a few minutes — sometimes HubSpot takes time to detect.
Code Removed After Theme Update?
- Don’t paste it into theme files unless you use a child theme.
- Use the Insert Headers and Footers plugin to avoid this.
Final Thoughts
Adding a HubSpot tracking code to your WordPress site is easy. You can use a plugin or do it manually. Once it’s live, HubSpot starts collecting visitor data. This helps you grow your business, understand your audience, and improve conversions.
Just follow the steps above and you’re good to go. If anything goes wrong, double-check the code and use a plugin to make things simple.
Let me know if you want help adding it using a specific theme or builder.