The short answer is:
Capturing the HubSpot Contact Record ID directly on the thank you page for a standard HubSpot form submission and sending it as a user property to Google Analytics 4 (GA4) isn’t straightforward because the form submission itself doesn’t inherently pass the new ID back to the front-end before the redirect, but you can achieve this with a server-side solution that acts as an intermediary, like using the HubSpot API in combination with the GA4 Measurement Protocol, often facilitated by Google Tag Manager (GTM) Server-Side and a platform like Stape or Google Cloud.
The core idea is to let HubSpot create the contact, retrieve the ID using the API from your server environment, and then send that ID as a user property to GA4’s data collection endpoint, bypassing the front-end data layer issue.
The long answer is:
Since the HubSpot form submission redirects to the thank you page, and the Contact Record ID is generated server-side after the form submission, the ID isn’t readily available on the front-end data layer of the thank you page for easy capture and transmission via a standard GA4 configuration.
The Record ID is internal to HubSpot, and their forms don’t automatically inject it into the redirect URL or the thank you page’s data layer.
To solve this, you need a server-side workflow that connects HubSpot’s data to GA4.
A very robust solution involves using the HubSpot API to retrieve the newly created contact’s information, and then the Google Analytics Data API or Measurement Protocol to send this information to GA4.
This process typically starts with the form submission triggering a server-side event instead of trying to pass the data client-side.
You could use a Web Hook from HubSpot’s workflow engine or a custom server-side script that listens for the form submission.
This script would:
1 - Receive the form submission data.
2 - Use the HubSpot API to query the contact and get the Record ID.
3 - Construct a GA4 hit containing the necessary parameters, including a custom user property for the Record ID.
4 - Send this hit using the GA4 Measurement Protocol.
This whole server-side process can be greatly simplified and managed using Google Tag Manager Server-Side (sGTM) deployed on a platform like Stape or Google Cloud Platform (GCP).
When the form is submitted, instead of sending the data straight to GA4’s front-end endpoint, you send a server-side generate_lead or form_submit event to your sGTM container.
In the sGTM container, you can set up a custom tag or use a solution like a Stape or custom GTM template to interact with the HubSpot API to fetch the Record ID.
Once the ID is retrieved, the sGTM container can forward the enhanced hit via the GA4 Measurement Protocol back to the GA4 endpoint, including the contact’s Record ID as a user property.
This approach is highly reliable because it isn’t dependent on client-side browser events or redirects, and it allows for a secure, backend-to-backend data transfer.
It also means you can ensure the Record ID is associated with the original user’s client_id or a stable user_id if you capture that during the form submission.
This is generally a much better long-term solution than relying on potentially fragile client-side workarounds.
This comment was generated with the assistance of an AI tool, incorporating my expertise in conversion tracking 