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-jsinstalled 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
-
Call
identifyas 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' });identifymerges the anonymous person into the identified person. Past events from the anonymous ID are attributed to the merged person. Events keep their originaldistinct_id, and PostHog usesperson_idto show the merged view. -
Call
identifyonce per session. PostHog ignores repeated identical calls without a page reload. -
Call
reset()on logout so the next person on that device isn't merged with this one:posthog.reset(); -
Don't call
identifywithnull,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
- Open your site in a clean profile and run
posthog.get_distinct_id()in the console. - Sign in as a test user, then run it again. It should now return your user ID.
- In PostHog, open Activity and confirm the person profile shows both IDs.
- 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