RoadwayDocs

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

  1. In HubSpot, click the Settings icon in the top navigation bar.
  2. In the left sidebar, go to Data Management > Properties.
  3. Click Create property.
  4. For Object type, select Contact.
  5. Choose a Group, such as Contact information.
  6. For Label, enter ga4_pseudo_user_id.
  7. Click Next. For Field type, choose Single-line text.
  8. Click Next, then Create.
  9. 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

  1. Go to Marketing > Forms.
  2. Hover over the form and click Edit.
  3. In the left panel, find the ga4_pseudo_user_id property under Contact properties, and add it to the form.
  4. Click the field in the form editor, and select Make this field hidden.
  5. 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

  1. Open a page with the form and add ?roadway_debug to the URL.
  2. Wait two seconds, then inspect the hidden input named ga4_pseudo_user_id. It should contain a value like 1234567890.1700000000.
  3. Submit the form with a test email address.
  4. In HubSpot, open the contact record and find ga4_pseudo_user_id under 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

  1. Open the form page with ?roadway_debug.
  2. Check the _ga cookie and the hidden field as described in Debug and verify.
  3. Submit a test form.
  4. Confirm the HubSpot contact has ga4_pseudo_user_id and the GA4 export has page views with user_pseudo_id equal to that value.

Troubleshooting

See Troubleshoot the tag.

With Segment

For when Segment supplies page views and HubSpot is your CRM.

You need:

Steps

  1. Create a HubSpot contact property with the internal name segment_anon_id, field type Single-line text.
  2. Add the property to each form as a hidden field.
  3. Publish the forms.
  4. Tell Roadway to read the segment_anon_id property. 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

  1. Open the form page with ?roadway_debug.

  2. In the console, run analytics.user().anonymousId() and note the value.

  3. Inspect the hidden segment_anon_id input. It should have the same value.

  4. Submit a test form, then confirm the HubSpot contact's segment_anon_id matches.

  5. Query your Segment pages table for that anonymous_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:

Steps

  1. Create a HubSpot contact property posthog_device_id, Single-line text. Optionally add posthog_distinct_id too.
  2. Add them to each form as hidden fields.
  3. 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

  1. In the console, run posthog.get_distinct_id() and posthog.get_property('$device_id').
  2. Inspect the hidden inputs. They should match.
  3. 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:

  1. GA4 through gtag. If gtag and dataLayer exist and the dataLayer contains a config entry whose ID starts with G-, the tag calls gtag('event', 'hubspot_form_submission', params).
  2. GA4 through GTM. Otherwise it pushes { event: 'hubspot_form_submission', ...params } to dataLayer. Google Tag Manager must handle that event. See below.
  3. 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_submission GTM 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

  1. In GTM, open Admin > User Management.
  2. Click + > Add users and enter contact@roadwayai.com.
  3. Grant User (or Administrator) at account level and Publish on the container.
  4. Notify the user by email and click Invite.

Option B: add it yourself

  1. Create the trigger. Go to Triggers > New, name it Roadway Custom Event - hubspot_form_submission, choose Custom Event, set Event name to hubspot_form_submission, and select All Custom Events. Save.

  2. Create the variables. Go to Variables > New > Data Layer Variable. Create DL - hubspot_utk with Data Layer Variable Name hubspot_utk. Optionally create DL - hubspot_form_id for hubspot_form_id.

  3. 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 to hubspot_form_submission, and add event parameters:

    Parameter name Value
    hubspot_utk {{DL - hubspot_utk}}
    hubspot_form_id {{DL - hubspot_form_id}}
  4. Under Triggering, select the trigger you created. Save.

  5. Click Preview, submit a test form, and confirm the tag fires.

  6. 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

  1. Open your site with ?roadway_debug, submit a test form, and look for [Roadway Tag] Sending event via gtag or falling back to dataLayer.
  2. In GA4 DebugView, confirm a hubspot_form_submission event with hubspot_utk.
  3. In BigQuery, confirm the event and parameters exist in event_params.

Vendor docs: Tag Manager custom event triggers, Data layer variables