More in Product analytics
- Autocapture and the AI event inbox
- Build a funnel that explains drop-off
- Identify users across web, app and mini-programs
- What is autocapture, and how does it work?
- How do I review and accept events in the inbox?
- What are unplanned events, and how do I manage them?
- When should I use a funnel instead of a goal or path?
- How do I build a funnel?
- How do I read where a funnel drops off?
- What is identified mode, and should I turn it on?
- How do I call login to identify a user?
- How is one person merged across devices?
- How does identity work on apps and mini-programs?
- How do I track clicks on outbound links?
- How do I track file downloads?
- How do I track form submissions?
- How do I track custom events?
- How do I track button clicks?
- How do I create a heatmap?
- How do I track scroll depth?
- How do I track ecommerce purchases and revenue?
- How do I set up goals and track conversions?
- How do I create a custom metric?
- How do I analyze accounts with groups?
- How do I connect AI agents with MCP?
- How do I ask the AI assistant about my data?
- How do I create user segments?
- How do I run an RFM analysis?
- How do I record and watch session replays?
- How do I analyze user paths?
- How do I build a retention report?
- How do I analyze how an event is distributed?
- How do I create a tracking plan?
- How do I view a user’s profile and activity?
- How do I read the lifecycle report (new, returning, resurrecting, dormant)?
- How do I compare attribution models for a conversion?
- All guides in this category
Still have a question?
Could not find it? A person reads every message, usually within a few hours on business days.
Chat with usShort answer
In All-platform analytics › Behavior › Behavior analysis, open the SQL tab and write one SELECT against v_events, v_sessions, v_persons or v_autocapture, which are already scoped to the project and date range. Results return up to 50,000 rows with a 30-second timeout.
Short answer
Open All-platform analytics › Behavior › Behavior analysis and switch to the SQL tab. Write one SELECT (or WITH … SELECT) against the views v_events, v_sessions, v_persons or v_autocapture. They are already limited to the current project and the selected date range. Run with Command-Enter or Ctrl-Enter.
Use SQL for cross-tabs and one-off lists the built-in models do not give you. For a recurring ratio, save a custom metric instead.
The four views
| View | Scope | Useful columns |
|---|---|---|
v_events | Project, selected dates | ts, name, path, title, ref_channel, utm_source, utm_campaign, country, device_type, props, session_id, subject |
v_sessions | Project, by session start | id, started_at, entry_path, exit_path, pageviews, duration, channel, is_bounce, engaged, device_type, subject |
v_persons | Project, not cut by time | person_id, first_seen, last_seen, identified_by, device_count, props |
v_autocapture | Project, selected dates | kind, path, selector, el_text, x, y, depth |
subject is the person, visitor or account, depending on the identity chosen in the builder.
Two example queries
Sessions and engaged sessions by channel and device:
SELECT channel, device_type,
COUNT(*) AS sessions,
SUM(CASE WHEN engaged = 1 THEN 1 ELSE 0 END) AS engaged_sessions
FROM v_sessions
GROUP BY channel, device_type
ORDER BY sessions DESC
Entry pages of sessions that included a sign-up:
WITH signups AS (
SELECT DISTINCT session_id FROM v_events WHERE name = 'signup'
)
SELECT s.entry_path, COUNT(*) AS sessions
FROM v_sessions s
JOIN signups g ON s.id = g.session_id
GROUP BY s.entry_path
ORDER BY sessions DESC
LIMIT 20
To apply the builder's global filters, put {filters} in a WHERE clause: WHERE {filters}. It becomes a constant true when there are no filters, and only works on columns the view has. Return rewritten SQL shows the statement that actually ran.
Limits
- One
SELECTorWITHstatement. Comments, semicolons, backticks, writes and system tables are rejected, as are real table names. - At most 50,000 rows returned (the footer says when the result was cut), 30-second timeout, 20,000 characters of SQL.
- No breakdown control and no compare period; segment comparison is rejected.
- Members with hidden properties cannot run SQL.
Common errors
| Message | Fix |
|---|---|
| Must reference at least one view | Query v_events, v_sessions, v_persons or v_autocapture |
| Only the four views can be queried | Remove database or table names; use the views |
| Timeout | Narrow the date range, aggregate earlier, add LIMIT |
Need a file for someone else to download later? Use an export job; see export raw data.
Did this answer your question?
We use your answers to fix and expand this page.
Couldn’t send. Please try again in a minute.
Thanks for the feedback. We’ll use it to improve this page.You’ve already sent feedback on this page. Thanks.