HubSpot forms
Set up the HubSpot contact property and hidden form field.
This part is the same for every analytics tool. Then follow your analytics guide: GA4, Segment, or PostHog.
Before you begin
- The optional Roadway attribution tag on the pages where the form appears, or your own script that fills the field. See Capture IDs manually.
- You're a HubSpot super admin, or you have permission to edit properties and forms.
- You know the field name for your analytics tool. See the field reference. The examples use
ga4_pseudo_user_id.
Step 1: create the contact property
- In HubSpot, click the Settings icon in the top navigation bar.
- In the left sidebar, go to Data Management > Properties.
- Click Create property.
- For Object type, select Contact.
- Choose a Group, such as Contact information.
- For Label, enter
ga4_pseudo_user_id. - Click Next. For Field type, choose Single-line text.
- Click Next, then Create.
- Open the property and confirm its Internal name is exactly
ga4_pseudo_user_id. HubSpot generates the internal name from the label and lowercases it.
Don't set the property to read-only. The form needs to write to it.
Step 2: add the property to the form as a hidden field
- Go to Marketing > Forms.
- Hover over the form and click Edit.
- In the left panel, find the
ga4_pseudo_user_idproperty under Contact properties, and add it to the form. - Click the field in the form editor, and select Make this field hidden.
- Click Update or Publish.
Repeat for every form you want to attribute.
Step 3: confirm the form type
The tag fills fields in the host page's DOM. How you embed the form matters:
| Embed type | Works with the tag? |
|---|---|
HubSpot Forms embed (JavaScript, hbspt.forms.create) rendered in the page |
Yes |
| HubSpot form module in a HubSpot-hosted CMS page | Yes |
Form inside an <iframe> |
No for hidden fields. Use the HubSpot form-submission event (UTK matching), which Roadway enables for your workspace. |
| Standalone HubSpot-hosted form page | Not applicable. The tag isn't on that page. |
The tag can't fill hidden fields inside an iframe. Use HubSpot's standard (non-iframe) embed, which makes the form part of your page. The tag fills only the first matching field on a page. Set the field yourself on any other form. The submit event is still caught for iframe forms.
Verify
- Open a page with the form and add
?roadway_debugto the URL. - Wait two seconds, then inspect the hidden input named
ga4_pseudo_user_id. It should contain a value like1234567890.1700000000. - Submit the form with a test email address.
- In HubSpot, open the contact record and find
ga4_pseudo_user_idunder About this contact (or search for the property). It should have the same value.
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
| The field isn't in the HTML | It isn't on the form | Add it and publish |
| Value present in HTML, missing in HubSpot | Property internal name differs from the field name | Match the names exactly |
| Field visible to visitors | Not set to hidden | Select Make this field hidden |
| Two forms on one page, one fills | The tag fills only the first matching field on the page | Keep one attributed form per page, or set the field yourself |
Vendor docs: Create and edit properties (HubSpot), Create forms (HubSpot), Forms embed options (HubSpot developers)
With GA4
For when GA4 supplies page views and HubSpot is your CRM.
You need:
- GA4 installed directly with
gtag.js, or through Google Tag Manager - A HubSpot hidden field and contact property created, named
ga4_pseudo_user_id
GA4 installed directly
If you have GA4 on your site with gtag.js, there's nothing more to do. The tag reads the _ga cookie and fills the hidden field. It also sends a hubspot_form_submission event to GA4. See HubSpot form-submission event.
Keep gtag('config', 'G-XXXXXXXXXX') in your install, so the tag can detect GA4.
GA4 through Google Tag Manager
The tag still fills the hidden field. If the tag can't find a gtag.js GA4 config (typical with GTM), it pushes hubspot_form_submission to the dataLayer. You need GTM steps only if Roadway links your workspace through the HubSpot form cookie (UTK). Follow HubSpot form-submission event for the steps, or ask Roadway to add them.
HubSpot to Salesforce
If HubSpot syncs contacts to Salesforce, also create the field in Salesforce and map it. See HubSpot to Salesforce.
Verify
- Open the form page with
?roadway_debug. - Check the
_gacookie and the hidden field as described in Debug and verify. - Submit a test form.
- Confirm the HubSpot contact has
ga4_pseudo_user_idand the GA4 export has page views withuser_pseudo_idequal to that value.
Troubleshooting
See Troubleshoot the tag.
With Segment
For when Segment supplies page views and HubSpot is your CRM.
You need:
- Segment Analytics.js installed on the pages with the form
Steps
- Create a HubSpot contact property with the internal name
segment_anon_id, field type Single-line text. - Add the property to each form as a hidden field.
- Publish the forms.
- Tell Roadway to read the
segment_anon_idproperty. Roadway's default is the GA4 property.
The tag reads analytics.user().anonymousId() and writes it into the hidden field. Nothing else is needed on the page.
Verify
-
Open the form page with
?roadway_debug. -
In the console, run
analytics.user().anonymousId()and note the value. -
Inspect the hidden
segment_anon_idinput. It should have the same value. -
Submit a test form, then confirm the HubSpot contact's
segment_anon_idmatches. -
Query your Segment
pagestable for thatanonymous_id:SELECT COUNT(*) FROM your_segment_schema.pages WHERE anonymous_id = 'PASTE_VALUE_HERE';
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
| Field stays empty | Analytics.js isn't loaded on that page | Load it before or alongside the tag |
ID differs from pages |
The visitor's anonymousId changed (cleared storage, reset()) |
Expected for some visitors |
With PostHog
The Roadway tag can write PostHog IDs into HubSpot form fields.
Roadway reads PostHog events from a PostHog batch export, and joins the CRM to page views on posthog_device_id. posthog_distinct_id is optional. Tell Roadway which property you created.
You need:
- PostHog (posthog-js) installed on the pages with the form
Steps
- Create a HubSpot contact property
posthog_device_id, Single-line text. Optionally addposthog_distinct_idtoo. - Add them to each form as hidden fields.
- Publish the forms.
posthog_device_id is stable per browser. posthog_distinct_id changes to your user ID after posthog.identify runs. The tag overwrites both while the page is open.
Verify
- In the console, run
posthog.get_distinct_id()andposthog.get_property('$device_id'). - Inspect the hidden inputs. They should match.
- Submit a test form and confirm the HubSpot contact has both values.
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
| Fields empty | PostHog isn't on window.posthog and persistence is memory or sessionStorage, or localStorage is blocked |
Load posthog-js on the form page |
distinct_id is your user ID on a form |
The visitor was already identified | Expected. device_id still holds the browser ID |
Form-submission event
In addition to filling hidden fields, the tag sends a hubspot_form_submission event when a form is submitted.
The event carries the HubSpot visitor token (hubspot_utk), so form submissions can be tied to a HubSpot contact and to the visitor's analytics identity.
What the event contains
| Parameter | Value |
|---|---|
hubspot_form_id |
The HubSpot form ID, when the submission comes from a HubSpot embedded form. Empty for native browser submits. |
hubspot_utk |
The value of the hubspotutk cookie, sanitized to word characters and hyphens |
The tag sends the event in these ways:
- GA4 through gtag. If
gtaganddataLayerexist and thedataLayercontains aconfigentry whose ID starts withG-, the tag callsgtag('event', 'hubspot_form_submission', params). - GA4 through GTM. Otherwise it pushes
{ event: 'hubspot_form_submission', ...params }todataLayer. Google Tag Manager must handle that event. See below. - PostHog. If PostHog is present, the tag calls
posthog.capture('hubspot_form_submission', params).
The tag listens for HubSpot's form-submit message and for native browser submit events, so the event may also fire for non-HubSpot forms. In that case hubspot_form_id is empty.
When you need this. If your HubSpot forms carry the hidden anonymous-ID field, you don't need the
hubspot_form_submissionGTM setup. Use the HubSpot form-cookie (UTK) route when your forms render in an iframe. Roadway can enable this on request. That method requires the GA4 BigQuery export and a HubSpot connection.
The tag detects GA4 only when a gtag config ID starting with G- is present on the page.
Direct gtag.js
If GA4 is installed directly with gtag.js and gtag('config', 'G-XXXXXXXXXX') runs on the page, no extra setup is needed. The tag sends the event to GA4 for you.
If your page uses gtag('set') only and never calls config, the tag doesn't detect GA4 and pushes to dataLayer instead, where nothing handles it. Keep a config call for your measurement ID.
Google Tag Manager
With GTM, create a trigger, a variable, and a GA4 event tag.
Option A: let Roadway add it
- In GTM, open Admin > User Management.
- Click + > Add users and enter
contact@roadwayai.com. - Grant User (or Administrator) at account level and Publish on the container.
- Notify the user by email and click Invite.
Option B: add it yourself
-
Create the trigger. Go to Triggers > New, name it
Roadway Custom Event - hubspot_form_submission, choose Custom Event, set Event name tohubspot_form_submission, and select All Custom Events. Save. -
Create the variables. Go to Variables > New > Data Layer Variable. Create
DL - hubspot_utkwith Data Layer Variable Namehubspot_utk. Optionally createDL - hubspot_form_idforhubspot_form_id. -
Create the GA4 event tag. Go to Tags > New, name it
Roadway GA4 - HubSpot Form Submission, choose Google Analytics: GA4 Event, select your Google tag or configuration tag, set Event Name tohubspot_form_submission, and add event parameters:Parameter name Value hubspot_utk{{DL - hubspot_utk}}hubspot_form_id{{DL - hubspot_form_id}} -
Under Triggering, select the trigger you created. Save.
-
Click Preview, submit a test form, and confirm the tag fires.
-
Submit and publish the container.
Add hubspot_utk at minimum. Add hubspot_form_id if you want to know which HubSpot form was submitted.
Verify
- Open your site with
?roadway_debug, submit a test form, and look for[Roadway Tag] Sending event via gtagorfalling back to dataLayer. - In GA4 DebugView, confirm a
hubspot_form_submissionevent withhubspot_utk. - In BigQuery, confirm the event and parameters exist in
event_params.
Vendor docs: Tag Manager custom event triggers, Data layer variables