How to get Client ID through a hidden field in a HubSpot form

forms

#1

Hey,

I have a question on setting up some integration. For that, I need to add a Google Analytics Client ID (it's already set up as a custom dimension) within a hidden field in a Hubspot Form. I contacted the support but they don't know how to do that.

I found this method:

The hidden field should look something like this:

<input type='hidden' id='ga_client_id' name='ga_client_id'>

Finally, place a code like this to your website (already added via GTM):

var clientId = ga.getAll()[0].get('clientId');
$( document ).ready(function() {
$('form input#ga_client_id').val(clientId);
});

This code will automatically retrieve the value of GA Client ID and put it inside that new hidden field we just created.
(source: https://gaconnector.com/blog/salesforce-google-analytics-integration-guide/)

So the question is: How do I add this hidden field to the form to capture a ClientID?


Google Analytics Connector
#2

Hi @Kristina,

Are you using an embedded HubSpot form? If so, you'd want to add a new field to the HubSpot form, and change the jquery selector in the code you've listed to target the HubSpot hidden field instead. You should be able to follow the guidelines on the following doc to select the HubSpot hidden field:

Additionally, you'll want to trigger the code when the HubSpot form is actually ready, or else it'll execute before the HubSpot form is loaded. You can do that by adding the code directly into the onFormReady callback (see above) or by using the global onFormSubmit event (see below).