RoadwayDocs

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 identify call per user_id marks the sign-up (the conversion event). Later identify calls for the same user don't change the sign-up time.
  • After identify, later page calls carry the userId on the same anonymousId. Roadway uses those to copy the user ID back onto earlier page views, so make sure an analytics.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 identify after 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

  1. Call identify when a user signs up, passing your database user ID as the first argument:

    analytics.identify('usr_8f2c', {
      plan: 'trial',
      persona: 'smb'
    });
    

    Don't call identify with an email address or other PII as the userId.

  2. Call identify again on login so the browser is tied to the user on later visits:

    analytics.identify(user.id);
    
  3. Call reset() on logout so the next person on that browser isn't merged with this one:

    analytics.reset();
    
  4. If you send identify from your server, send the userId. Roadway doesn't read the anonymous ID on that call. The link to earlier visits comes from browser page calls 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 a userId different 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

  1. Open your site in a clean browser profile and run analytics.user().anonymousId() in the console. Note the value.

  2. Sign up as a test user.

  3. In Segment's Debugger, confirm an identify event with the userId, followed by a page event that carries both the userId and the same anonymousId.

  4. After the warehouse sync, run:

    SELECT anonymous_id, user_id, timestamp
    FROM your_segment_schema.pages
    WHERE user_id = 'usr_8f2c'
    ORDER BY timestamp;
    
  5. Confirm page views before sign-up carry the same anonymous_id in pages. 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 page and identify calls. 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

  1. In Segment, open Connections > Destinations and add your warehouse.
  2. Choose the source that carries your website events.
  3. Complete the destination setup, then confirm a first sync.
  4. Give Roadway read access to the Segment schema. See your warehouse guide: Snowflake, BigQuery, Redshift.
  5. 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)