How to Track HubSpot Forms in Google Analytics 4 (GA4) Using Google Tag Manager

Track HubSpot Forms in GA4

Tracking HubSpot forms in Google Analytics 4 is important for measuring lead quality, form performance, and conversion rate. But HubSpot forms are often embedded in iframes, which means GA4 cannot detect form submissions automatically.

Both methods work seamlessly with Google Tag Manager (GTM).

Method 1: Track HubSpot Forms Using onFormSubmit Callback (Recommended)

This is the most accurate and reliable method because:

✔ It works with embedded forms
✔ It works even if you use iframes
✔ It fires on 100% of valid form submissions

HubSpot provides a built-in JavaScript callback called onFormSubmit, which we will use to push an event into the dataLayer, and then send it to GA4.

Step 1: Add HubSpot on FormSubmit Listener in GTM

In Google Tag Manager, go to Tags → New

Contact Us Confirmation Screenshot

2. Choose Custom HTML

Contact Us Confirmation Screenshot

3. Paste this code:

<script>
window.dataLayer = window.dataLayer || [];
//listener for older version (v3) of HS forms
window.addEventListener(‘message’, function(event) {
  if (event.data.type === ‘hsFormCallback’ && event.data.eventName === ‘onFormSubmitted’) {
    window.dataLayer.push({
      event: ‘hubspot_form_submission’,
      form_id: event.data.id,
      conversion_id: event.data.data.conversionId,
      form_data: event.data.data.submissionValues,
    });
  }
});
//listener for v4 HS forms 
window.addEventListener(“hs-form-event:on-submission:success”, function(event) {
    var hsform = HubspotFormsV4.getFormFromEvent(event);
    if (hsform) {
      hsform.getFormFieldValues().then(function(fieldValues) {
        var transformedData = fieldValues.reduce(function(obj, item) {
          var key = item.name.split(‘/’)[1]; 
          if (key) {
            obj[key] = item.value;
          }
          return obj;
        }, {});
  
        window.dataLayer.push({
          event: “hubspot_form_submission”,
          form_id: hsform.getFormId(),
          conversion_id: hsform.getConversionId(),
          form_data: transformedData
        });
      });
    }
  });
</script>

Contact Us Confirmation Screenshot

4. Trigger → DOM Ready

Contact Us Confirmation Screenshot

5. Save the tag as:
HubSpot – onFormSubmit Listener

Contact Us Confirmation Screenshot

Step 2: Create Custom Event Trigger

1. Go to Triggers → New

Contact Us Confirmation Screenshot

2. Choose Custom Event

Contact Us Confirmation Screenshot

3. Event Name: hubspot_form_submit

4. Name the trigger: HubSpot – Form Submit Trigger

5. Save

Contact Us Confirmation Screenshot

Step 3: Create GA4 Event Tag

1. Go to Tags → New

Contact Us Confirmation Screenshot

2. Choose Google Analytics: GA4 Event

Contact Us Confirmation Screenshot

3. Event Name: hubspot_form_submit

Contact Us Confirmation Screenshot

4. Under Triggering → Select:  HubSpot – Form Submit Trigger

Contact Us Confirmation Screenshot

5. Save the tag as: GA4 – HubSpot Form Submission

Contact Us Confirmation Screenshot
Contact Us Confirmation Screenshot

Step 4: Test in GTM Preview Mode

  1. Click Preview
  2. Submit your HubSpot form
    Contact Us Confirmation Screenshot
    Contact Us Confirmation Screenshot
  3. In the left panel, look for:
    • hubspot_form_submit event
      Contact Us Confirmation Screenshot
  4. Confirm your GA4 tag fired

Step 5: Verify in GA4 DebugView

1. Open GA4

2. Go to Admin → DebugView

Contact Us Confirmation Screenshot

3. Submit the form again

4. Look for the event:
hubspot_form_submit

Contact Us Confirmation Screenshot

Method 2 (Optional): Track HubSpot Form Redirect to Thank You Page

If your HubSpot form redirects to a thank-you page (e.g., /thank-you/), you can simply track that page as a conversion.

Step 1: Create Thank You Page Trigger

1. Go to Triggers → New

2. Choose Page View → Some Page Views

Condition:

Page URL → contains → thank-you

3. Save as:
HubSpot – Thank You Page Trigger

Step 2: Create GA4 Event Tag

1. Go to Tags → New

2. Select GA4 Event

Event Name:
hubspot_form_submit

3. Trigger → HubSpot – Thank You Page Trigger
4. Save

Conclusion

You now have the setup  using:

HubSpot onFormSubmit callback (most accurate)
✔ Optional thank you page tracking

This ensures your HubSpot forms are tracked correctly in GA4 without guesswork or unreliable triggers.

Want Professional Tracking Setup?
Connect with Incisive Ranking

At Incisive Ranking, we implement:

  • GA4
  • HubSpot tracking
  • Server-side tagging
  • CRO & advanced analytics

If you want your form tracking to be 100% accurate, we can set it up for you.

Follow Us:

About Us

We are experts in Tags and Tracking Services. With experience in eCommerce and Custom Conversion tracking, Server Side Tagging, and Data tracking to help you get the advantage of ACCURATE data for better decision making. With more than 6 years of experience, We have already delivered more than 500 projects.