RoadwayDocs

Track users with PostHog

PostHog gives every visitor an anonymous distinct_id and a $device_id.

When you call posthog.identify, PostHog links the anonymous identity to your user ID. The Roadway attribution tag can copy PostHog IDs into CRM form fields.

PostHog can be your page-view source, your users source, or both. Roadway uses $device_id as the anonymous ID and the identified distinct_id as the user ID. Connect PostHog Cloud (US or EU) in the app (Admin › Integrations): sign in with PostHog and enter your project ID. Roadway sets up PostHog batch exports for you. Self-hosted PostHog isn't supported.

Sign-ups are the event you name during setup, or the first $identify for each user. Page views must come from posthog-js in the browser. Server-side page views count as anonymous.

Before you begin

  • The PostHog JavaScript snippet or posthog-js installed on your site.
  • A user ID that isn't PII. PostHog's own docs allow email as distinct_id, but for Roadway use a surrogate ID so it matches your other systems.

Steps

  1. Call identify as soon as you know who the user is. That's usually right after sign-up and after login, and on app load if the user is already signed in:

    posthog.identify('usr_8f2c', { plan: 'trial' });
    

    identify merges the anonymous person into the identified person. Past events from the anonymous ID are attributed to the merged person. Events keep their original distinct_id, and PostHog uses person_id to show the merged view.

  2. Call identify once per session. PostHog ignores repeated identical calls without a page reload.

  3. Call reset() on logout so the next person on that device isn't merged with this one:

    posthog.reset();
    
  4. Don't call identify with null, true, or generic strings. Identical IDs across users merge their data.

IDs the tag can fill

The attribution tag fills two optional hidden fields:

Hidden field name Value Changes at identify?
posthog_distinct_id (or posthog_distinct_id__c) posthog.get_distinct_id() Yes. After identify, it becomes your user ID.
posthog_device_id (or posthog_device_id__c) $device_id No. Stable per browser.

The tag keeps overwriting these fields while the page is open, because distinct_id changes when identify runs. Capture posthog_device_id. Roadway joins it to PostHog page views. Tell Roadway the property name, because the CRM default is the GA4 field. See the field reference.

Verify

  1. Open your site in a clean profile and run posthog.get_distinct_id() in the console.
  2. Sign in as a test user, then run it again. It should now return your user ID.
  3. In PostHog, open Activity and confirm the person profile shows both IDs.
  4. Run posthog.get_property('$device_id') before and after login. The value should not change.

Troubleshooting

Problem Cause Fix
Hidden field is empty posthog-js doesn't load on the page and its persisted state isn't readable Load posthog-js on the form page. See tag troubleshooting
Two people merged into one Same distinct_id used for different users Use unique IDs. Call reset() on logout
IDs differ between sessions Cookies cleared or private window Expected

Vendor docs: Identifying users (PostHog), Identity resolution, Device bucketing and $device_id