Tutorials

How to Track Legacy HubSpot Form Submissions with Google Tag Manager

October 21, 2025

If you’re still using HubSpot’s legacy form embed (the one implemented via JavaScript on your page, not the new multi-step v4 form inside an iframe), you can listen for successful form submissions directly from the browser and use that as a trigger for your marketing events.
This is especially useful when you want to push conversion events to Google Analytics 4, Facebook, Google Ads, or any other platform that’s integrated via Google Tag Manager.

Why This Works for Legacy Forms

Legacy HubSpot forms run directly on the page, so when a visitor submits the form successfully, HubSpot sends a “postMessage” event to the parent window. By listening for that event, you can capture the submission data and send it to your dataLayer. From there, GTM can handle sending the event to any marketing platform.

Note: This method will not work for HubSpot’s new v4 multi-step forms (which run in an iframe). For those, check out our other guide: Tracking HubSpot v4 Multi-step Forms.

The Code

Add this JavaScript snippet to any page containing your HubSpot legacy form:

<script type="text/javascript">
  // HubSpot legacy form submission listener - by Terrific Digital
  window.addEventListener("message", function(event) {
    if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormSubmitted') {
      window.dataLayer = window.dataLayer || [];
      window.dataLayer.push({
        'event': 'form_submission',
        'form_type': 'HubSpot Legacy Form',
        'form_id': event.data.id,
        'submission_id': event.data.data.conversionId,
        'submission_data': event.data.data.submissionValues
      });
    }
  });
</script>

Setting Up the Trigger in GTM

  1. In Google Tag Manager, create a Custom Event Trigger:
    • Event name: “form_submission”
  2. Create a new Tag for the platform you want to send data to (e.g., GA4 Event, Meta Ads Pixel, Google Ads Conversion, etc..).
  3. Map the form details from the dataLayer to your event parameters as needed.
  4. Publish your GTM container.

Summary

  • Works only for HubSpot Legacy Forms.
  • Listens for hsFormCallback → onFormSubmitted.
  • Pushes a “form_submission” event with all relevant data to the dataLayer.
  • GTM can then forward the event to your analytics and ad platforms.

Looking for the v4 multi-step HubSpot form tracking solution? Read our dedicated guide here.