RoadwayDocs

Roadway attribution tag

The Roadway attribution tag is an optional JavaScript file that fills hidden form fields with the visitor's anonymous ID.

The CRM contact a form creates then carries that ID, and Roadway joins leads, opportunities and deals back to the visits that produced them.

The tag doesn't record page views. Page views come from your own source: Segment, GA4, PostHog or a custom table. You don't need the tag to connect HubSpot or Salesforce. You can also capture the ID yourself.

You can read the live file at analytics.roadwayai.com/tag.js.

How it works

The tag works in three moments:

  1. Before the form. It reads the anonymous ID your analytics tool assigned to the browser.
  2. During the form. It writes that ID into hidden form fields that you've added to your forms.
  3. After the form. The submission becomes a CRM contact with the ID stored on it. When that contact reaches your warehouse or Roadway connector, Roadway joins the contact to the visitor's earlier page views.

What the tag reads

Source How the tag reads it
GA4 user_pseudo_id Parses the last two dot-separated parts of the _ga cookie
Segment anonymousId Calls analytics.user().anonymousId()
PostHog distinct_id and $device_id Calls the PostHog SDK, or reads PostHog's persisted state from cookies or local storage
HubSpot visitor token Reads the hubspotutk cookie (used in the form-submission event)

What the tag writes

The tag fills the first input for each recognized name, such as ga4_pseudo_user_id or segment_anon_id. On pages with several forms, only the first is filled. It also sends a hubspot_form_submission event to GA4 and PostHog when any form on the page is submitted, not only HubSpot forms. See the field reference and HubSpot form-submission event.

What it doesn't do

  • It doesn't record page views or visits. Your analytics tool does.
  • It doesn't create the hidden fields or CRM properties. You add those. See Capture IDs in forms.
  • It makes no network requests of its own. Loading it fetches tag.js from analytics.roadwayai.com.
  • It doesn't create IDs. If your analytics tool isn't installed or is blocked, there's nothing to copy.
  • It doesn't backfill contacts created before it was installed.

Timing and performance

  • The script loads with defer, so it doesn't block rendering.
  • It checks for forms every 1.5 seconds, so forms that load late are still filled.

Setup path

  1. Install the tag.
  2. Add hidden fields and CRM properties for your form provider. See Capture IDs in forms.
  3. Verify.

Install the tag

Install the optional tag on every page with a form you want to attribute.

It takes about 15 minutes. After this, add hidden fields to your forms. See Capture IDs in forms.

You need:

  • Edit access to your site's <head> or to Google Tag Manager.
  • Your analytics tool (GA4, Segment, or PostHog) already installed. The tag reads IDs from it.
  • If you use a Content Security Policy (CSP), permission to allow analytics.roadwayai.com in script-src.

The snippet

<script defer src="//analytics.roadwayai.com/tag.js"></script>

The URL is protocol-relative. On an HTTPS site it loads over HTTPS.

Install directly

  1. Open the template or layout that renders your site's <head>.
  2. Paste the snippet inside <head>, after your analytics snippet if possible.
  3. Deploy.

Install with Google Tag Manager

  1. In GTM, go to Tags > New.
  2. Name it Roadway Attribution Tag.
  3. Under Tag Configuration, choose Custom HTML and paste the snippet.
  4. Under Triggering, choose All Pages (or Initialization - All Pages if your forms render on first paint).
  5. Save, click Preview, and confirm the tag fires.
  6. Submit and publish the container.

Install in common site builders

Platform Where to paste
Webflow Site settings > Custom code > Head code, then publish
WordPress A header-scripts plugin or your theme's header.php
Squarespace Settings > Advanced > Code Injection > Header
Next.js next/script with strategy="afterInteractive" in your root layout
Shopify theme.liquid, before </head>

For single-page apps, install once at the app root. The tag keeps scanning for forms, so route changes are covered.

Content Security Policy

Add the Roadway analytics host to script-src:

script-src 'self' https://analytics.roadwayai.com ...;

Verify

  1. Open a page with the tag installed and add ?roadway_debug to the URL.
  2. Open the browser console. You should see [Roadway Tag] messages.
  3. In the Network tab, confirm tag.js loaded with status 200.

See Debug and verify the tag for more.

Troubleshooting

Problem Cause Fix
tag.js blocked CSP or ad blocker Allow analytics.roadwayai.com
No [Roadway Tag] console messages Missing ?roadway_debug parameter, or tag not installed Add the parameter and reload
Tag loads on some pages only Snippet placed in a page-specific template Move it to a global template or All Pages trigger

Field reference

The tag fills the first <input> on the page whose name attribute matches each of the names below.

On pages with several forms, only the first matching field is filled. Add the hidden fields that match your analytics tool.

Recognized field names

Analytics tool Hidden field name values ID written Fill behavior
GA4 ga4_pseudo_user_id, ga4_pseudo_user_id__c, user_pseudo_id, pseudo_user_id GA4 user_pseudo_id, parsed from the _ga cookie Fills only if the field is empty. A GA4 field with a default value is never filled.
Segment segment_anon_id, segment_anon_id__c analytics.user().anonymousId() Overwrites on every cycle
PostHog (distinct ID) posthog_distinct_id, posthog_distinct_id__c distinct_id Overwrites, because it changes when posthog.identify runs
PostHog (device ID) posthog_device_id, posthog_device_id__c $device_id Overwrites

The __c names are for Salesforce custom fields, whose API names end in __c.

Recommended names. Use ga4_pseudo_user_id for GA4, segment_anon_id for Segment, and posthog_device_id plus posthog_distinct_id for PostHog. They're the names Roadway's guides use. For PostHog, Roadway joins on posthog_device_id.

CRM property names

Create a contact property with the same name as the form field. Then the CRM stores the submitted value on the contact.

System Property naming
HubSpot Create a contact property whose internal name matches the field, for example ga4_pseudo_user_id. The label can differ, but the internal name must match.
Salesforce Create a custom field whose API name is the field name with __c, for example ga4_pseudo_user_id__c. Field type Text, length 255.

Roadway reads one visitor-ID property per CRM, agreed during onboarding: ga4_pseudo_user_id for GA4 (the default), segment_anon_id for Segment, or posthog_device_id for PostHog. In Salesforce, add __c, for example ga4_pseudo_user_id__c. Roadway doesn't combine several properties, so there is no precedence between them. Tell Roadway if you use Segment or PostHog IDs. Your HubSpot contact Record ID is contact_id.

How the IDs are read

GA4

The _ga cookie looks like GA1.1.1234567890.1700000000. The tag takes the last two dot-separated parts: 1234567890.1700000000. That is GA4's user_pseudo_id. GA4 stores a separate session cookie (_ga_<container ID>) that holds session data, not the client ID. Don't use it for this purpose.

Segment

The tag reads window.analytics.user().anonymousId(). Segment creates an ID if none exists, so the tag always gets a value once Analytics.js is loaded.

PostHog

The tag first asks the PostHog SDK (get_distinct_id, get_property('$device_id')). If the SDK isn't reachable yet, it reads PostHog's persisted state from the ph_<project token>_posthog cookie or local storage. If posthog-js doesn't load on the page and its persisted state isn't readable, the field stays empty.

Example hidden inputs

<form action="/contact" method="post">
  <input type="email" name="email" required>
  <input type="hidden" name="ga4_pseudo_user_id">
  <input type="hidden" name="segment_anon_id">
  <input type="hidden" name="posthog_device_id">
  <input type="hidden" name="posthog_distinct_id">
  <button type="submit">Submit</button>
</form>

Include only the fields that match your analytics tools.

Debug and verify

Run these checks after you install the tag and add hidden fields.

Turn on debug mode

Add roadway_debug as a query parameter to any page URL:

https://www.example.com/contact?roadway_debug

The tag then logs messages prefixed with [Roadway Tag] to the browser console. The messages show whether the analytics ID was found, whether form fields were filled, and how events were sent.

Checks

1. The tag loaded

In Network, filter for tag.js and confirm status 200.

2. The analytics ID exists

Tool Console check Expected
GA4 document.cookie.split('; ').find(c => c.startsWith('_ga=')) A value like _ga=GA1.1.1234567890.1700000000
Segment analytics.user().anonymousId() A UUID
PostHog posthog.get_distinct_id() and posthog.get_property('$device_id') UUIDs

3. The hidden field is filled

On a page with a form, wait two seconds and run:

document.querySelectorAll('input[type="hidden"]').forEach(function (el) {
  if (/pseudo|anon|posthog/.test(el.name)) console.log(el.name, '=', el.value);
});

You should see your field names with values.

4. The value reaches the CRM

  1. Submit a test form with an email address you can look up.
  2. Open the new contact in your CRM.
  3. Confirm the contact property holds the same value you saw in step 3.

5. The value matches your sessions data

Query your sessions source for the same ID. For GA4 export:

SELECT COUNT(*) AS page_views
FROM `your_project.analytics_PROPERTY_ID.events_*`
WHERE user_pseudo_id = '1234567890.1700000000';

A non-zero count means the CRM ID joins to real visits.

Troubleshooting

See Troubleshoot the tag.

Troubleshoot the tag

Each row maps a symptom to its most likely cause.

The hidden field is empty on the page

Cause How to check Fix
Tag not installed or blocked Network tab: tag.js Install the tag. Allow it in your CSP and ad blockers
Analytics not installed, or blocked by consent Console checks in Debug and verify Install analytics and load it under the same consent category
Field name doesn't match Inspect the input's name Use a name from the field reference
Field isn't an <input> Inspect the element The tag fills input[name="..."] only
Form lives in an iframe The form is inside an <iframe> 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. For HubSpot iframe forms, Roadway can link submissions through the HubSpot form cookie (UTK), which Roadway enables per workspace. Roadway can enable this on request.
Several forms on one page Count the matching inputs The tag fills only the first matching field on the page. Set the field yourself on the other forms
A GA4 field has a pre-set value Inspect the input's value The tag never overwrites a GA4 field that already has a value. Remove the default
gtag config ID isn't G-... Check gtag('config', ...) The tag detects GA4 only from a G- measurement ID
Form renders after consent or user interaction Field appears late Expected. The tag retries every 1.5 seconds, so wait a few seconds
posthog-js doesn't load, and its persisted state isn't readable Run posthog.get_property('$device_id') in the console Load posthog-js on the form page

The hidden field is filled but the CRM property is empty

Cause Fix
The CRM property doesn't exist or the internal name differs Create it with the same internal name. See HubSpot forms or Salesforce
The field isn't on the form in the CRM Add the property to the form as a hidden field
The form-to-CRM mapping skips the field Add the mapping in your form integration
HubSpot-to-Salesforce sync doesn't include the property Add a field mapping. See HubSpot to Salesforce
Salesforce field-level security hides the field Grant read and edit access to the integration user's profile or permission set

The CRM value doesn't match any page view

Cause Fix
Field matches a different analytics tool than your sessions source Use the field for the tool that supplies your page views. GA4 sessions need ga4_pseudo_user_id. Segment sessions need segment_anon_id. PostHog sessions need posthog_device_id. Roadway's default CRM property is the GA4 one, so tell Roadway if you use another
Visitor changed browsers or cleared cookies between visit and form Expected for part of your traffic
Sessions source doesn't include that visitor (consent, ad blockers) Expected for part of your traffic
Your sessions table filters out that traffic Check your model

The GA4 event doesn't appear

Cause Fix
Page uses gtag('set') without a config call Add gtag('config', 'G-XXXXXXXXXX'). See HubSpot form-submission event
GTM isn't handling hubspot_form_submission Create the trigger and tag
Container not published Publish it

Still stuck

Send Roadway the page URL with ?roadway_debug, the console output, and a screenshot of the CRM contact's properties.