Track users with Segment
Send identify calls from your app, then make the Segment warehouse tables available to Roadway.
Send identify calls
If Segment is your sessions and users source, Roadway reads page views from the pages table and sign-ups from the identifies table.
The link from a visitor's anonymousId to your userId comes from page calls made after identify.
You need:
- Segment Analytics.js installed on your site, with
analytics.page()firing on page loads. - A Segment warehouse destination. See Segment in your warehouse.
- A user ID that isn't PII.
How Roadway uses identify
- The first
identifycall peruser_idmarks the sign-up (the conversion event). Later identify calls for the same user don't change the sign-up time. - After identify, later
pagecalls carry the userId on the same anonymousId. Roadway uses those to copy the user ID back onto earlier page views, so make sure ananalytics.page()runs after identify. - Traits don't become user dimensions by default. Custom dimensions need Roadway to map them for your workspace; tell Roadway which traits you want. Don't send PII as traits.
First identify equals sign-up date. If you only start calling
identifyafter you adopt Roadway, existing users will look like they signed up on their first login after that date. Backfill identify calls for existing users, or provide a custom users table.
Steps
-
Call
identifywhen a user signs up, passing your database user ID as the first argument:analytics.identify('usr_8f2c', { plan: 'trial', persona: 'smb' });Don't call
identifywith an email address or other PII as theuserId. -
Call
identifyagain on login so the browser is tied to the user on later visits:analytics.identify(user.id); -
Call
reset()on logout so the next person on that browser isn't merged with this one:analytics.reset(); -
If you send
identifyfrom your server, send theuserId. Roadway doesn't read the anonymous ID on that call. The link to earlier visits comes from browserpagecalls after the user is identified in the browser:// server (Node.js) analytics.identify({ userId: 'usr_8f2c', traits: { plan: 'trial' } });
Know when the anonymous ID changes
Segment generates a new anonymousId if:
- The user clears cookies and local storage.
- Your code calls
analytics.reset(). - You call
analytics.identify()with auserIddifferent from the cached one.
Don't call identify with a different ID than the one already stored for that browser unless the person really is different. If you must merge two IDs, use analytics.alias().
Verify
-
Open your site in a clean browser profile and run
analytics.user().anonymousId()in the console. Note the value. -
Sign up as a test user.
-
In Segment's Debugger, confirm an
identifyevent with theuserId, followed by apageevent that carries both theuserIdand the sameanonymousId. -
After the warehouse sync, run:
SELECT anonymous_id, user_id, timestamp FROM your_segment_schema.pages WHERE user_id = 'usr_8f2c' ORDER BY timestamp; -
Confirm page views before sign-up carry the same
anonymous_idinpages. Roadway copies the user ID back onto them.
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
| Users never linked to visits | No page call carries the userId |
Call analytics.page() after identify in the browser |
Two anonymous_id values for one sign-up |
identify with a changed userId, or reset() before sign-up |
Avoid resetting before identify |
| Wrong sign-up dates | First identify happens later than real sign-up | Backfill identify calls or use a custom users table |
Vendor docs: Identify spec, Best practices for identifying users, Managing identity in Analytics.js
Segment in your warehouse
For a warehouse-native implementation with Segment, Roadway reads two tables that Segment's warehouse destination creates: pages and identifies.
You need:
- A Segment source for your website, with Analytics.js collecting
pageandidentifycalls. See Send Segment identify calls. - A warehouse destination (Snowflake, BigQuery, Redshift, or other) connected to that source.
Tables Roadway reads
| Table | Used for | Fields Roadway uses |
|---|---|---|
pages |
Page views, and the link from visitors to users | anonymous_id, user_id, original_timestamp, timestamp, context_page_url, context_page_referrer, context_page_path, context_page_title and context_campaign_*. Keep these in any PII-free view. |
identifies |
The sign-up time | user_id, timestamp |
identifies supplies the sign-up time. The link comes from user_id on pages.
Segment puts each custom property in its own column on pages and identifies, converted from camelCase to snake_case. Each source has its own schema, named after the source.
Steps
- In Segment, open Connections > Destinations and add your warehouse.
- Choose the source that carries your website events.
- Complete the destination setup, then confirm a first sync.
- Give Roadway read access to the Segment schema. See your warehouse guide: Snowflake, BigQuery, Redshift.
- Tell Roadway the schema name.
Verify
-- Snowflake or Redshift syntax. In BigQuery use DATE_SUB(CURRENT_DATE(), INTERVAL 7 DAY).
-- Page views should have an anonymous_id, a timestamp, and a URL
SELECT COUNT(*) AS rows_total,
COUNT(anonymous_id) AS with_anonymous_id,
COUNT(user_id) AS identified
FROM your_segment_schema.pages
WHERE received_at >= CURRENT_DATE - 7;
identified should be greater than zero and grow as users sign in.
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
pages is empty |
analytics.page() isn't called |
Add it to your page-load or route-change code |
| URL column has no query string | Page URL properties were overridden | Don't override url in page() calls |
identified is zero |
identify isn't called |
See Send Segment identify calls |
Vendor docs: Warehouse schema (Segment)