#1222·rybbit

First visit is the earliest event in the selected range, on Users and on Retention

Author: zawaspCreated Sep 25, 2026Updated Sep 27, 2026

Describe the bug

Two screens compute "first visit" as min(timestamp) after a date bound, so a returning visitor looks new inside the current window.

Users

On the Users table, First Seen is the earliest event already filtered by the dashboard date range. Changing the date selector changes First Seen.

The column is labeled "First Seen" and the users guide says "when they first visited". That should be the earliest event we have for that user. Pageviews, sessions, events, and Last Seen can stay scoped to the range.

The same window is applied on the user detail summary (MIN(session_start) AS first_seen after the time predicate).

Retention

Retention has the same bug in its own query. UserFirstPeriod takes min(timestamp) only where timestamp >= addDays(today(), -{timeRange}) (default 90 days). Anyone active in that window is placed in the cohort of their earliest in-range event and counted as new. That inflates the oldest cohort and its return percentages.

The guide says a cohort is everyone who first visited on the same day or week. The range should only choose which of those cohorts to show.

To Reproduce

Users:

  1. Open a site that has a user with activity both before and inside a short window (for example last 24 hours, or a single day).
  2. Note that user's First Seen on Users with the date selector set to All time.
  3. Switch the date selector to a window that starts after their real first visit (Last 24 hours / Today).
  4. First Seen moves to the earliest event inside that window. Last Seen, pageviews, and sessions also shrink, which is expected for those columns.

Retention:

  1. Pick a visitor whose real first visit is older than the retention range, and who was also active inside it.
  2. Open Retention at the default 90 days.
  3. That visitor is counted in the oldest in-range cohort, as if that period were their first visit.

Expected behavior

First Seen stays at the user's actual first event, regardless of the selected date range. The date filter should still decide which users appear and should still scope pageviews, sessions, events, and Last Seen.

A retention cohort should contain only users whose real first visit falls in that day or week. The range selects which cohorts to display. Return activity can stay inside the window.

Where it happens

Users list, server/src/api/analytics/users/getUsers.ts:

  • getTimeStatement(query) is applied on the events subquery before aggregation.
  • first_seen is then min(timestamp) of those filtered rows.

The Users page always sends that window: useGetUsers uses useAnalyticsQuery with the default useTime: true.

User detail, server/src/api/analytics/users/getUserInfo.ts:

  • With a range set, first_seen is MIN(session_start) over sessions inside that range.

Retention, server/src/api/analytics/getRetention.ts:

  • UserFirstPeriod groups min(timestamp) under timestamp >= addDays(today(), -{timeRange}).
  • FEATURE_AUDIT.md already notes this: long-time users look new in the oldest in-window cohort.

Suggested fix

Users: keep the date filter on membership and on the range metrics, and compute First Seen from unscoped history.

Retention: compute min(timestamp) with no time bound, then keep a user only when that first event falls inside the range. Leave PeriodActivity bounded so return visits stay inside the window.

Additional context

#402 was timezone display of first/last seen, not this.

OS / browser: server query behavior, not client-specific.