HubSpot (HS) forms are a powerful tool for capturing leads and engaging visitors. However, tracking form submissions accurately is crucial for measuring performance, optimizing conversions, and understanding user behavior.
By leveraging Google Tag Manager (GTM), you can track form submissions seamlessly and send event data directly to Google Analytics 4 (GA4) for in-depth analysis.
In this guide, we’ll walk you through the step-by-step process of implementing enhanced conversion tracking for HubSpot forms using GTM, ensuring no conversion goes untracked.
While there are multiple ways to track HubSpot form submissions, using Google Tag Manager (GTM) offers unique advantages in flexibility, scalability, and control:
Centralized Tag Management
Manage all tracking scripts (GA4, Google Ads, Facebook Pixel, etc.) from a single interface without touching HubSpot or site code directly.
Custom Event Triggers for HubSpot
GTM lets you listen for HubSpot-specific events (like onFormSubmitted) and create custom triggers and tags based on form IDs, user data, or page context.
Scalable Across Multiple Forms
Whether you have 1 or 100 HubSpot forms, GTM allows consistent tracking setup without duplicating scripts across pages.
Enhanced Conversion Setup Made Easier
With GTM, you can easily push user data (like email and phone) into the Data Layer for Enhanced Conversions — no need to customize each individual HubSpot form.
Improved Debugging and Version Control
GTM’s Preview and Debug mode helps you test form tracking in real time, and version history gives you rollback safety.
By using GTM, you can track HubSpot form submissions more efficiently, with greater customization and less risk of breaking your site or forms.
When a HubSpot form is successfully submitted, it triggers a built-in event called hsFormCallback. However, Google Tag Manager (GTM) doesn’t automatically detect this event — so we need to manually listen for it and push the relevant data into the Data Layer.
The script below listens for postMessage events from HubSpot forms. When it detects a form submission (onFormSubmitted), it extracts key information like the user’s email, phone number, and form ID (GUID), and then pushes a custom event called hubspot-form-success into the dataLayer. This makes the submission data available to GTM for tracking purposes, including Enhanced Conversions if set up properly.
Here’s the code you should place in your site’s <head> tag or inject via GTM:
<script type="text/javascript">
window.addEventListener("message", function(event) {
if (event.data.type === 'hsFormCallback') {
var email = '';
var phone = '';
var formGuid = '';
if (event.data) {
formGuid = event.data.formGuid || event.data.id || '';
if (event.data.data && event.data.data.submissionValues) {
email = event.data.data.submissionValues.email || '';
phone = event.data.data.submissionValues.phone || '';
}
}
if (event.data.eventName === 'onFormSubmitted') {
window.dataLayer.push({
'event': 'hubspot-form-success',
'hs-form-guid': formGuid,
'email': email,
'phone': phone
});
}
}
});
</script>
Now, use this trigger to fire Google Analytics 4 (GA4) events.
1. Create a new Tag in GTM.
2. Choose Google Analytics: GA4 Event as the tag type.
3. Connect the Measurement ID of your GA4 account.
4. Set Event Name as hubspot-form-success.
5. Set Event Name as hubspot-form-success.
5.1 To configure the UPD Manually go to GTM > Variables > Choose ‘User-Provided Data’
5.2 Select Manual configuration and insert the variables for Email and/or Phone
6. Link it to the trigger created in Step 1.
7. Test in Preview Mode and submit a test form.
7.1 Remember to check if the Google Tag Assistant is working correctly, this message should be showing on the screen
8. The event should appear on the left, and the tag should fire; To debug the user-provided data, check the API call, you must be able to see the client information as set.
Accurately tracking HubSpot form submissions using Google Tag Manager (GTM) and Google Analytics 4 (GA4) is a crucial step toward understanding user behavior, optimizing conversion paths, and making smarter, data-driven marketing decisions.
By implementing the steps outlined in this guide, you’ll gain visibility into form interactions that might otherwise go unnoticed. This not only ensures that every lead is properly captured and attributed but also gives you the insights needed to fine-tune your campaigns, improve user experience, and ultimately increase your return on investment.
Whether you’re managing a few landing pages or running a large-scale demand generation strategy, having a reliable tracking setup is the foundation of effective digital marketing.
If you’re looking for hands-on support or want to ensure your GTM and HubSpot integration is set up correctly and efficiently, don’t hesitate to reach out. A solid tracking framework today can lead to smarter decisions and better results tomorrow.