Send Record ID to Google Analytics

We have a “Reuqest Demo” form implemented via Hubspot on our external website. When a user submits the demo form, a contact is created on Hubspot.

I want to pass the Contact’s “Record ID” to Google Ananlytics 4 as a user property for tracking purposes.

As the form submission redirect the website to a “Thank you” page, I am not able to find a way to capture the Record ID. Is there a way to capture Record ID of the contact created and send it GA?

Hello, @ASharma58 thank you for posting in our Community!

Have you tried working with GA integration according to this guide?

I want to invite our top experts to this conversation @Mike_Eastwood @danmoyle @ralphioooo. Do you have any suggestions for the @ASharma58 matter?

Thank you,

Pam

Thanks for the tag @PamCotton :blush:

Hi @ASharma58 You could try pushing the record ID as a custom event via our plugin:

With v3 we used to allow the record ID to be pushed as the User ID. But did not add this to v4 unfortunately. (as ran out of time).
What’s your usecase here? We could look at adding this in as well.

We are using GA4 for creating funnels and dashboards. But as it doesn’t collect any user related info, we are not find to the kind of business, designation, email, etc. on GA4.

To connect these two data sets, I am think of attaching the Record ID as a user property on GA and use it later to search for the user’s personal info on Hubspot.

Cannot pay extra for the plugin. Can you please suggest some free alternative?

I would be also interested in this. What are you referring to with v3 and v4?

@ASharma58 according to this post, “After creating a common key, transfer the CRM information to Google Analytics using the Data Import function. Another option is sending Measurement Protocol hits. Both methods provide the desired effect. To receive the CRM data in your Google Analytics, you need to create segments.”

I haven’t personally pushed the data, as I’ve always stuck with one system (HubSpot) for my full-journey reporting. But hopefully that resoruce helps.

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 :slightly_smiling_face: