Capture IDs in forms
For sales-led funnels, the form links marketing to revenue.
When a visitor submits a form, your CRM creates a contact. If that contact carries the visitor's anonymous ID, Roadway can join the contact to every earlier visit.
Before you begin
- Analytics (GA4, Segment, or PostHog) installed
- The optional Roadway tag installed, or your own script that fills the field. See Capture IDs manually.
The four steps
Every form setup has the same four steps:
- Add a hidden field to the form, named to match the field names.
- Fill the field. The optional Roadway attribution tag does this for you. Or capture the ID yourself.
- Create a CRM property with the same name, to store the value. Tell Roadway the property's internal name. Roadway reads one ID property per CRM.
- Map the field from the form to the CRM property (and across CRMs, if you sync HubSpot to Salesforce).
Choose your guide
Start with your form provider, then pick your analytics tool.
| Form provider | Guide |
|---|---|
| HubSpot forms | HubSpot forms, then with GA4, with Segment, or with PostHog |
| Custom HTML forms | Custom forms |
| Webflow forms | Webflow forms |
| Typeform | Typeform |
| Salesforce Web-to-Lead | Salesforce Web-to-Lead |
| Forms that need the ID at submit time, or sites without the tag | Capture IDs manually. For HubSpot forms without a hidden field, see the HubSpot form-submission event, which Roadway turns on for your workspace. |
| Your CRM | Where the property lives |
|---|---|
| HubSpot | Contact property. See HubSpot CRM |
| Salesforce | Custom field on the Lead and Contact objects. See Salesforce CRM |
| HubSpot syncing to Salesforce | Both, plus a field mapping. See HubSpot to Salesforce |
Which analytics ID to capture
Capture the ID from the analytics tool that supplies your page views. A Segment ID in the CRM won't match GA4 page views.
| Your sessions source | Hidden field |
|---|---|
| GA4 | ga4_pseudo_user_id |
| Segment | segment_anon_id |
| PostHog | posthog_device_id (required); posthog_distinct_id (optional) |
Verify
Submit a test form and confirm the new contact has the ID. See Debug and verify the tag.
Webflow forms
Webflow forms don't have a built-in way to read analytics cookies.
Add a hidden input with the field name the Roadway tag recognizes, and the tag fills it.
You need:
- The optional Roadway tag, added under Site settings > Custom code > Head code, or your own script that fills the field. See Capture IDs manually.
- A destination for submissions: Webflow's HubSpot integration, a webhook, or Zapier
Steps
-
In the Designer, select your Form Block.
-
Add an Embed element inside the form, above the submit button.
-
Paste a hidden input for your analytics tool:
<input type="hidden" name="ga4_pseudo_user_id" id="ga4_pseudo_user_id">Use
segment_anon_idfor Segment, orposthog_device_idfor PostHog. The tag fills only the first matching field on the page, so keep one attributed form per page. -
Publish the site.
-
In your destination, create a matching property and map the field:
- Webflow's native HubSpot form integration lists hidden fields as form fields. Map them to your HubSpot property.
- For webhooks and Zapier, include
ga4_pseudo_user_idin the payload.
The
nameof the input is what Webflow submits. Theidis optional.
Verify
- Visit your published page with
?roadway_debug. - Wait two seconds and inspect the hidden input.
- Submit a test form and confirm the CRM contact has the value.
- In Site Settings > Forms, open the submission and confirm the hidden field value is present.
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
| Input empty in Designer preview | The tag runs only on the published site | Test on the published or staging domain |
| Submission lacks the field | Embed is outside the form | Move it inside the Form Block |
| Field present in Webflow, missing in CRM | Not mapped in the integration | Add the mapping |
Vendor docs: Webflow Help Center, Webflow custom code
Typeform
Typeform calls hidden fields URL parameters (formerly Hidden Fields).
Unlike an HTML form, a Typeform embed isn't an input on your page, so the Roadway tag can't fill it. You pass the ID to Typeform yourself.
The Roadway tag can't reach inside a Typeform embed, so you don't need it here. The snippet below reads the ID itself.
You need:
- An embedded Typeform (not a standalone
typeform.com/to/...link)
Steps
-
In Typeform, open your form, go to Logic and add a hidden field (URL parameter) named
ga4_pseudo_user_id. -
Embed the form with one snippet, in this order: the
<div>, the inline script that setsdata-tf-hidden, thenembed.js:<div id="tf" data-tf-live="FORM_ID"></div> <script> function getGa4PseudoId() { var m = document.cookie.match(/(?:^|;\s*)_ga=([^;]+)/); return m ? m[1].split('.').slice(-2).join('.') : ''; } document.getElementById('tf').setAttribute( 'data-tf-hidden', 'ga4_pseudo_user_id=' + encodeURIComponent(getGa4PseudoId()) ); </script> <script src="//embed.typeform.com/next/embed.js"></script>For Segment, name the hidden field
segment_anon_idand set it fromanalytics.user().anonymousId(). For PostHog, name itposthog_device_idand set it fromposthog.get_property('$device_id'). -
In Typeform, connect the form to your CRM (for example the HubSpot integration) and map the hidden field to your contact property.
Verify
- Submit a test response.
- In Typeform, open the response and confirm the hidden field has a value like
1234567890.1700000000. - Confirm the CRM contact has the property filled.
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
| Hidden value empty | _ga cookie not set yet when the embed loaded |
Initialize the embed after analytics loads |
| Field missing from CRM | Not mapped in the integration | Add the mapping |
Vendor docs: Using URL parameters with embedded forms (Typeform)
Salesforce Web-to-Lead
Web-to-Lead posts a form directly to Salesforce and creates a Lead.
It names custom fields by their field ID, not their API name. That detail decides how you wire up the Roadway tag.
Roadway reads Contacts by default, or Leads, chosen for your workspace. Put the field on both objects and map it in lead conversion. Leads that never convert aren't joined unless Roadway models your funnel on Leads. The tag matches by field name, and Web-to-Lead uses field IDs like 00N5g00000AbCdE, so the script below copies the value across.
You need:
- Salesforce admin access
- A custom field on Lead and a matching custom field on Contact, so the value survives lead conversion. See Salesforce CRM.
Steps
-
Create the Lead field. In Setup > Object Manager > Lead > Fields & Relationships > New, create a Text (255) field with the label
ga4_pseudo_user_id. Salesforce adds__cto the API name. -
Create the Contact field with the same label and type.
-
Map the fields for lead conversion. In Object Manager > Lead > Fields & Relationships > Map Lead Fields, map the Lead field to the Contact field.
-
Generate the form HTML. In Setup, search for Web-to-Lead, click Create Web-to-Lead Form, include your new field, and generate the HTML.
-
Find the field ID. In the generated HTML, the new field looks like:
<input id="00N5g00000AbCdE" name="00N5g00000AbCdE" type="text" maxlength="255"> -
Make the input hidden and fill it. Change it to a hidden input and add a tiny script that copies the tag's value, since the tag matches by field name:
<input type="hidden" id="00N5g00000AbCdE" name="00N5g00000AbCdE"> <input type="hidden" name="ga4_pseudo_user_id"> <!-- filled by the Roadway tag --> <script> document.querySelector('form[action*="WebToLead"]').addEventListener('submit', function () { var source = document.querySelector('input[name="ga4_pseudo_user_id"]'); document.getElementById('00N5g00000AbCdE').value = source ? source.value : ''; }); </script>Replace
00N5g00000AbCdEwith your own field ID.
Verify
- Submit a test lead from the page.
- In Salesforce, open the Lead and confirm the custom field has a value.
- Convert the Lead to a Contact and confirm the Contact field has the same value.
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
| Lead field empty | Wrong field ID, or the value wasn't copied | Check the ID and the copy script |
| Contact field empty after conversion | Lead field not mapped to Contact field | Complete Map Lead Fields |
| Field not editable by the integration | Field-level security | Grant access to the relevant profiles |
Vendor docs: Pass hidden parameters in Web-to-Lead (Salesforce), Map custom lead fields for lead conversion (Salesforce)
Custom forms
For forms you build yourself, or tools that post to HubSpot or Salesforce.
Add the hidden input and make sure its value reaches the CRM.
You need:
- A way to write the field into your CRM: a native integration, a webhook, or your own backend
Steps
-
Add hidden inputs to the form for your analytics tool. Use the exact
namevalues from the field reference:<form action="/api/leads" method="post"> <input type="email" name="email" required> <input type="hidden" name="ga4_pseudo_user_id"> <button type="submit">Request a demo</button> </form> -
Make sure your form handler accepts the field and passes it to the CRM:
// Node.js example: forward the ID to HubSpot's Forms API app.post('/api/leads', async (req, res) => { const url = 'https://api.hsforms.com/submissions/v3/integration/submit/' + `${PORTAL_ID}/${FORM_GUID}`; await fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ fields: [ { name: 'email', value: req.body.email }, { name: 'ga4_pseudo_user_id', value: req.body.ga4_pseudo_user_id } ], context: { hutk: req.cookies.hubspotutk, pageUri: req.headers.referer } }) }); res.sendStatus(204); }); -
Create the CRM property with the same name:
- HubSpot: see HubSpot forms, steps 1 and 2.
- Salesforce: see Salesforce CRM.
-
Map the form field to the property in your integration (for example Zapier, a native form integration, or your backend code).
Notes for single-page apps and dynamic forms
- The tag fills only the first matching field on the page. If a page has several forms, set the field yourself on the others.
- If your form renders after a click, the tag fills it within about 1.5 seconds. For very fast submissions, read the ID yourself at submit time. See Capture IDs manually.
- Controlled inputs in React or Vue can overwrite values set by outside scripts. If the field is empty on submit, set it in your component's submit handler instead.
Verify
- Open the page with
?roadway_debugand inspect the hidden input after two seconds. - Submit a test form.
- Confirm the CRM contact has the property filled.
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
| Hidden input empty at submit | Form submitted before the tag ran, or the framework reset the value | Read the ID in your submit handler |
| Value arrives but isn't stored | Property name mismatch, or integration doesn't map it | Match names. Add the mapping |
| Contact created with no ID | Form posted by a server that doesn't forward the field | Forward the field in your handler |
Capture IDs manually
Use these snippets if you can't install the Roadway tag, or if a form needs the ID at the instant of submission.
They return the same values the tag writes.
Read the IDs
GA4 user_pseudo_id
// From the _ga cookie (synchronous)
function getGa4PseudoId() {
var m = document.cookie.match(/(?:^|;\s*)_ga=([^;]+)/);
return m ? m[1].split('.').slice(-2).join('.') : '';
}
// From the Google tag (asynchronous)
gtag('get', 'G-XXXXXXXXXX', 'client_id', function (clientId) {
console.log(clientId);
});
Read the
_gacookie, not the session cookie_ga_<container ID>. The session cookie holds session data and doesn't contain the client ID.
Segment anonymousId
var segmentAnonymousId = window.analytics && analytics.user().anonymousId();
PostHog
var posthogDistinctId = window.posthog && posthog.get_distinct_id();
var posthogDeviceId = window.posthog && posthog.get_property('$device_id');
HubSpot visitor token
function getHubspotUtk() {
var m = document.cookie.match(/(?:^|;\s*)hubspotutk=([^;]+)/);
return m ? m[1] : '';
}
Write into a HubSpot embedded form
Set the hidden field after the form renders, in plain JavaScript. This doesn't need jQuery or HubSpot's form callbacks, which current embeds don't always support:
<script>
function setRoadwayField() {
var field = document.querySelector('input[name="ga4_pseudo_user_id"]');
if (!field) return false;
field.value = getGa4PseudoId();
field.dispatchEvent(new Event('input', { bubbles: true }));
field.dispatchEvent(new Event('change', { bubbles: true }));
return true;
}
var tries = 0;
var timer = setInterval(function () {
if (setRoadwayField() || ++tries > 20) clearInterval(timer);
}, 500);
</script>
In a hidden field, HubSpot doesn't add an id, so select by name. Firing input and change is for your own code and HubSpot. The Roadway tag sets the value without firing events. Test it on your embed. It can't reach a form inside an iframe.
Write into a plain HTML form at submit time
// Select your form specifically, not the first form on the page
document.querySelector('#your-form-id').addEventListener('submit', function () {
var field = document.querySelector('input[name="ga4_pseudo_user_id"]');
if (field && !field.value) field.value = getGa4PseudoId();
});
Verify
Submit a test form and confirm the CRM property has the value. See Debug and verify the tag.
Vendor docs: Google tag reference: get, HubSpot forms embed options