← All Guides

HubSpot Form Tracking and Sales Qualified Lead Tracking with Server-Side Google Tag Manager

Track HubSpot form submissions in GTM, then go further: send Sales Qualified Lead stage changes from HubSpot to Google Ads and Meta through server-side Google Tag Manager, so your ad platforms optimise for pipeline, not form fills.

Atiqul Islam
Written by Atiqul Islam

Tracking & analytics specialist. 278+ GTM, GA4 and server-side tracking projects for clients in the US, UK and Australia.

Rather not do this yourself? I set this up for clients every week. Free 15-minute audit, no obligation.

Book a Free Audit

Most B2B tracking stops at the form submission. The sales team then spends a week discovering that half the submissions were students, competitors and vendors, and the ad platforms never find out. They keep optimising for the kind of person who fills in forms.

This guide covers two layers. First, tracking HubSpot form submissions properly in Google Tag Manager. Second, sending Sales Qualified Lead stage changes from HubSpot back to Google Ads and Meta through server-side GTM, so the platforms learn from qualified pipeline.

Part 1: HubSpot Form Submission Tracking

How HubSpot forms confirm a submission

Embedded HubSpot forms post messages to the parent page. The one we care about has type equal to hsFormCallback and eventName equal to onFormSubmitted, with the form GUID in the data. Newer HubSpot form embeds also emit a hs-form-event:on-submission:success event. The listener below handles both.

Step 1: Listener tag

Create a Custom HTML tag named Listener - HubSpot Forms on All Pages:

<script>
(function () {
  var lastEmail = '';
  window.dataLayer = window.dataLayer || [];

  // Capture the email as it is typed, since HubSpot clears the form on success.
  document.addEventListener('input', function (e) {
    var t = e.target;
    if (t && t.name === 'email' && t.closest && t.closest('form.hs-form')) {
      lastEmail = (t.value || '').trim().toLowerCase();
    }
  }, true);

  function pushSuccess(formId) {
    window.dataLayer.push({
      event: 'form_submit_success',
      form_tool: 'hubspot',
      form_id: formId || '',
      user_email: lastEmail || undefined
    });
  }

  window.addEventListener('message', function (e) {
    var d = e.data;
    if (!d || typeof d !== 'object') { return; }
    if (d.type === 'hsFormCallback' && d.eventName === 'onFormSubmitted') {
      pushSuccess(d.id);
    }
  });

  window.addEventListener('hs-form-event:on-submission:success', function (e) {
    var detail = e.detail || {};
    pushSuccess(detail.formId || (detail.form && detail.form.id) || '');
  });
})();
</script>

Step 2: Capture the Google click ID on the contact

Add a hidden field named gclid to the HubSpot form, create a matching contact property, and populate the field from a first-party cookie that stores the gclid URL parameter for 90 days. HubSpot also captures its own hutk cookie, and HubSpot's Google Ads integration can store gclid automatically when connected. Either way, make sure the click ID ends up on the contact record. Everything in Part 2 depends on it.

Step 3: Variables, trigger and tags

Data Layer Variables for form_id and user_email. Custom Event trigger form_submit_success with a form_tool equals hubspot condition. Fire:

If you run server-side GTM, send these through your server container rather than directly from the browser, so the same endpoint handles both the form fill and the SQL and can deduplicate by event ID.

Part 2: Sales Qualified Lead Tracking

The flow

  1. Sales changes the contact's lifecycle stage to Sales Qualified Lead in HubSpot.
  2. A HubSpot workflow fires a webhook to your server-side GTM container.
  3. The server container receives the contact's email, gclid and timestamp.
  4. It sends an offline conversion to Google Ads and a server event to Meta.

Step 4: Create the conversions in the ad platforms

In Google Ads, create a conversion action named SQL with source Import from clicks, or use Enhanced Conversions for Leads so it can match on email as well. Set a 90 day window and a value that reflects what an SQL is worth to you.

In Meta Events Manager, decide on an event name. A custom event such as QualifiedLead, or the standard Lead event with a higher value, both work. For Conversion Leads optimisation, Meta expects a CRM integration or Conversions API events that reflect lead stages.

Step 5: Build the HubSpot workflow

Create a contact-based workflow with the enrolment trigger Lifecycle stage is any of Sales Qualified Lead. Add a Send webhook action with method POST to your server-side GTM endpoint, for example https://sgtm.yourdomain.com/hubspot-sql. Include the contact's email, the gclid property, the lifecycle stage and the current timestamp in the request body. Add a shared secret header so the endpoint only accepts requests from HubSpot.

Step 6: Receive the webhook in server-side GTM

In the server container, add a Client that listens on the webhook path and claims the request. Parse the JSON body into event data: event_name of sql, email, gclid, conversion_time. Reject requests without the secret header.

Step 7: Send to Google Ads and Meta

Step 8: Test end to end

  1. Submit the HubSpot form as a test contact after arriving on the site with ?gclid=test123. Confirm the form fill conversion fires in GTM Preview and that the contact in HubSpot has test123 in the gclid property.
  2. Manually set the contact's lifecycle stage to SQL. Confirm the workflow ran and the webhook returned 200.
  3. In the server container's Preview, confirm the request was claimed, the data parsed and the Google Ads and Meta tags fired.
  4. In Google Ads, check the conversion action's Diagnostics or upload history after a day. In Meta Events Manager, check the Test Events tab with a test event code.

What Changes Once SQLs Flow

Set SQL as the primary conversion in Google Ads and demote the form fill to secondary after you have 30 or more SQLs in a 30 day window. In Meta, test a campaign optimised toward the QualifiedLead event. Both platforms will shift spend toward the audiences and keywords that produce leads your sales team actually calls back.

Common Problems

Outcome

Your ad platforms stop learning from form fills and start learning from the leads sales wants. In most B2B accounts that shifts spend noticeably within a month, and it gives marketing and sales the same definition of a good lead for the first time.

Frequently Asked Questions

Why do GTM form triggers not fire on HubSpot forms?

Embedded HubSpot forms render inside their own frame or script context. The generic GTM form trigger cannot see them. HubSpot posts a message to the page on submission, which is what the listener in this guide captures.

What is the difference between tracking a form fill and an SQL?

A form fill is a lead the website produced. A Sales Qualified Lead is one your sales team confirmed is worth pursuing, usually set as a lifecycle stage in HubSpot days later. Sending the SQL back to Google Ads and Meta teaches them which clicks turn into pipeline.

Do I need server-side GTM for the SQL part?

You need something that can receive a webhook from HubSpot and send a conversion to Google Ads and Meta. Server-side GTM is the cleanest option because it can also handle your browser events and deduplication. HubSpot's native Google Ads integration is an alternative with less control.

How does Google Ads connect the SQL to the original click?

Through the Google click ID stored on the contact when the form was submitted, or through Enhanced Conversions for Leads which matches on the hashed email. Capture the gclid in a hidden form field so it lands on the HubSpot contact record.

Will this double count with HubSpot's own ads tracking?

It can. If you enable HubSpot's Google Ads or Meta integrations and also send conversions through GTM, pick one source per conversion. Typically GTM handles the form fill and either HubSpot or sGTM handles the SQL, never both.

Want This Done Right the First Time?

Book a free 15-minute audit call. I'll review your setup, show you what is broken, and tell you exactly what it takes to fix it.

Chat Now