> ## Documentation Index
> Fetch the complete documentation index at: https://docs.manalens.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Explorer

> Run read-only SQL queries over your raw events to answer questions that dashboards do not cover.

The **Explorer** lets you query your project's raw events with SQL.

## When to use the Explorer

* **Ad-hoc analysis** for one specific question
* **Custom calculations** that are not in standard reports
* **Data validation** to check a metric or a new event
* **Debugging** event properties after an installation

## Run a query

1. Open your project in the dashboard.
2. Click **Explorer** in the left navigation, then **Data**.
3. Write a `SELECT` query over `raw_events` and click **Run query**.

The Explorer uses ClickHouse SQL. Every query reads only the current project's events.

## The `raw_events` table

| Column | Type | Description |
| - | - | - |
| `anonymous_id` | String | Persistent visitor ID. Empty before consent in consent mode. |
| `session_id` | String | Client session ID, as the SDK sent it. To count sessions, read [the `sessions` table](#the-sessions-table). |
| `user_id` | String | Identified user ID, if any |
| `channel` | String | Event origin: `web`, `server`, `stripe`, `paddle` and others |
| `type` | String | `page`, `track`, `identify` and provider event types |
| `event` | String | Custom event name (`track`) |
| `context` | String (JSON) | Page, referrer, campaign fields, country, device, OS, browser, locale, `channel_type` |
| `properties` | String (JSON) | Custom event properties |
| `original_timestamp` | DateTime64 | When the event happened |
| `received_at` | DateTime64 | When the collector received it |
| `message_id` | String | Unique event ID |

## The `sessions` table

`sessions` has one row for each [session](https://docs.manalens.dev/data/metrics.md#sessions) of the date range: the same sessions as on the Overview. Use it for sessions, bounce rate, session duration and sessions by source. Do not count sessions from `raw_events` (for example with `session_id` or time buckets): those numbers do not match the reports.

| Column | Type | Description |
| - | - | - |
| `anonymous_id` | String | The visitor of the session |
| `session_key` | String | The session. It is unique for one `anonymous_id`. |
| `day` | Date | UTC day of the first event. A session that crosses midnight is one row on its first day. |
| `first_at`, `last_at` | DateTime64 | First and last event. The duration is `dateDiff('second', first_at, last_at)`. |
| `pageviews` | UInt64 | Page views of the session. 0 for a [game session](https://docs.manalens.dev/data/metrics.md#game-sessions-in-the-sessions-metric) and for a website session with custom events only. |
| `custom_events` | UInt64 | Custom events of the session. A bounce is `pageviews = 1 AND custom_events = 0`. The bounce rate divides by `countIf(pageviews > 0)`. |
| `revenue` | Float64 | Revenue of the custom events of the session |
| `channel_type`, `utm_source`, `utm_medium`, `utm_campaign`, `referrer`, `ref`, `paid_source`, `country` | String | The landing columns: these fields of the first page view (of the first event that the website or the game sent, for a session with no page view). They are the source of the session. An empty `channel_type` is Direct. |
| `entry_page`, `exit_page` | String | Path of the first and of the last page view (empty for a session with no page view) |
| `landing_context` | String (JSON) | The landing columns and the entry page as one JSON object (`channel_type`, `utm_source`, `utm_medium`, `utm_campaign`, `referrer`, `ref`, `paid_source`, `country`, `page.path`). It is for queries that were written before the columns had names. Use the named columns: this column reads all of them. |

```sql theme={null}
SELECT
    if(channel_type != '', channel_type, 'Direct') AS channel,
    count() AS sessions,
    countIf(pageviews = 1 AND custom_events = 0) / countIf(pageviews > 0) AS bounce_rate
FROM sessions
GROUP BY channel
ORDER BY sessions DESC
```

* The table follows the date range in the page header (or the last 30 days). Do not add a date condition, and do not use `{{date_from}}` or `{{date_to}}` on it.
* It has no bot traffic.
* Name only the columns that you need. Each landing column that a query names uses memory, and `SELECT *` names all of them. A query has 256 MiB. On a project with about 2,000,000 page views and custom events in the date range, a query with one or two landing columns passes. If a query needs more memory, the message tells you to use a shorter date range or fewer landing columns.
* Other fields of the first page view (`device`, `browser`, `os`, `utm_content`, `utm_term`) are not in `sessions`. Read them from `raw_events`.
* A session ID that a client keeps for more than 24 hours is one session of at most 24 hours in `sessions`. The reports split such an ID by inactivity. The SDKs start a new session ID before that.
* `session_events` has one row for each page view and custom event of the same date range (`anonymous_id`, `message_id`, `type`, `event`, `user_id`, `channel`, `context`, `properties`, `original_timestamp`, `received_at`), with its `session_key` and `session_counted` (1 when the session counts). Use it when a query needs the events inside a session. It works out the sessions when the query runs, so it needs more memory than `sessions`: it passes for about 200,000 events in the date range.
* You cannot name a CTE `sessions`, `session_events`, `raw_events` or `fx_rates_daily`.

## Example queries

**Daily visitors over the last 30 days**

```sql theme={null}
SELECT
  toDate(original_timestamp) AS day,
  uniqExact(anonymous_id) AS visitors
FROM raw_events
WHERE type = 'page'
  AND anonymous_id != ''
  AND original_timestamp >= now() - INTERVAL 30 DAY
GROUP BY day
ORDER BY day
```

**Top custom events by plan**

```sql theme={null}
SELECT
  event,
  JSONExtractString(properties, 'plan') AS plan,
  count() AS events
FROM raw_events
WHERE type = 'track'
GROUP BY event, plan
ORDER BY events DESC
```

**Page views by channel**

```sql theme={null}
SELECT
  JSONExtractString(context, 'channel_type') AS channel,
  count() AS pageviews
FROM raw_events
WHERE type = 'page'
GROUP BY channel
ORDER BY pageviews DESC
```

## Date range

Use `{{date_from}}` and `{{date_to}}` to follow the date range in the page header. They become dates such as `'2026-01-31'`. Use both or neither. Without a header range, they cover the last 30 days.

```sql theme={null}
SELECT event, count() AS events
FROM raw_events
WHERE toDate(original_timestamp) BETWEEN {{date_from}} AND {{date_to}}
GROUP BY event
ORDER BY events DESC
```

## Limits

* Queries are read-only. Write one `SELECT` or `WITH` statement without comments.
* You can read `raw_events`, `sessions`, `session_events`, subqueries and CTEs that you define. Other datasources, `system` tables, table functions such as `url()`, `s3()`, `file()` and `numbers()`, and network, dictionary and server functions are refused.
* `SETTINGS`, `FORMAT` and `INTO OUTFILE` clauses are refused. The Explorer sets them for you.
* A `LIMIT` or `TOP` must be a plain number up to **10,000**. `LIMIT BY`, `WITH TIES` and `FETCH` are refused.
* A result has at most **200 rows** and **1 MB**.
* A query stops after **8 seconds** or **256 MiB** of memory.
* `sessions` and `session_events` use memory for each event in the date range. A range with up to about **200,000** page views and custom events passes; a larger range can stop with a memory error. A query that stops gives an error, never a wrong number. Use a shorter date range, or read `raw_events` when the query does not need sessions. The reports (Overview, Sources, Pages, User paths) do not have this limit.
* You can run 10 queries a minute, and a project can run 30 a minute.
* `raw_events` includes bot rows. Exclude them with `JSONExtractString(context, 'device') != 'bot'`.
* Rows can repeat when a client retries. Use `uniqExact(message_id)` when you need exact event counts.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.