Skip to content

OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.

1.9 KB
Raw Blame
/**
 * Top-level filterable columns on the `events` table. These apply to
 * every event regardless of name and can be passed straight to
 * `getEventFiltersWhereClause` as filter / breakdown `name` values.
 *
 * Kept as a whitelist because the filter builder splices `name` into
 * SQL verbatim — only these are safe to expose through the AI /
 * MCP discovery surface.
 */
export const EVENT_COLUMNS = [
  'path',
  'origin',
  'referrer',
  'referrer_name',
  'referrer_type',
  'duration',
  'country',
  'city',
  'region',
  'os',
  'os_version',
  'browser',
  'browser_version',
  'device',
  'brand',
  'model',
  'sdk_name',
  'sdk_version',
  'profile_id',
  'session_id',
  'device_id',
  'revenue',
] as const;

export type IEventColumn = (typeof EVENT_COLUMNS)[number];

/** Every column `getEventList` can project. */
export const EVENT_LIST_COLUMNS = [
  'created_at',
  'project_id',
  'id',
  'name',
  'device_id',
  'profile_id',
  'session_id',
  'properties',
  'country',
  'city',
  'region',
  'longitude',
  'latitude',
  'os',
  'os_version',
  'browser',
  'browser_version',
  'device',
  'brand',
  'model',
  'path',
  'origin',
  'referrer',
  'referrer_name',
  'referrer_type',
  'imported_at',
  'sdk_name',
  'sdk_version',
  'revenue',
  'groups',
] as const;

export type EventListColumn = (typeof EVENT_LIST_COLUMNS)[number];

/** The `= value` columns `queryEventsCore` accepts. */
export const QUERY_EVENTS_EQUALITY_COLUMNS = [
  'path',
  'referrer',
  'referrer_name',
  'referrer_type',
  'device',
  'country',
  'city',
  'os',
  'browser',
] as const;

export type QueryEventsEqualityColumn =
  (typeof QUERY_EVENTS_EQUALITY_COLUMNS)[number];

/** The `event.pages` columns a client may sort by; the query sorts server-side. */
export const TOP_PAGES_SORT_COLUMNS = [
  'sessions',
  'pageviews',
  'bounce_rate',
  'avg_duration',
] as const;
export type TopPagesSortColumn = (typeof TOP_PAGES_SORT_COLUMNS)[number];