How to run an analytics query
This guide gives you a query for each common analytics question. Copy one, put your own
project ID in the WHERE clause, and run it.
Every query must carry a tenant filter. See About PickedQL for why, and Data sources for every table.
Daily A/B test trend
SELECT
project_local_date,
control_users() AS control,
variant_users() AS variant
FROM metrics
WHERE project_id = '{{ your project ID }}'
AND project_local_date >= '2026-04-01'
GROUP BY project_local_date
ORDER BY project_local_dateResult:
| project_local_date | control | variant |
|---|---|---|
| 2026-04-11 | 4361 | 101 |
| 2026-04-12 | 4178 | 126 |
| 2026-04-13 | 5008 | 176 |
Conversion rate uplift by date
SELECT
project_local_date,
control_conversion_rate() AS control_conversion_rate,
variant_conversion_rate() AS variant_conversion_rate,
conversion_rate_uplift() AS conversion_rate_uplift_pct
FROM metrics
WHERE project_id = '{{ your project ID }}'
AND project_local_date >= '2026-04-01'
GROUP BY project_local_date
ORDER BY project_local_dateResult:
| project_local_date | control_conversion_rate | variant_conversion_rate | conversion_rate_uplift_pct |
|---|---|---|---|
| 2026-04-01 | 0.0322 | 0.0349 | 0.0349 |
| 2026-04-02 | 0.0398 | 0.0416 | 0.0416 |
| 2026-04-03 | 0.0462 | 0 | -0.0001 |
Custom conversion rate definition
Override the default conversion, which counts a purchase event, with your own
numerator and denominator. Use this when a form submission, a lead capture, or
another event of your own defines a conversion.
-- Lead capture conversion: form submissions / lead-capture step entries
SELECT
project_local_date,
control_conversion_rate(
numerator='event_type=form_submit_success',
denominator='step_id=lead-capture-step'
) AS control_lead_cr,
variant_conversion_rate(
numerator='event_type=form_submit_success',
denominator='step_id=lead-capture-step'
) AS variant_lead_cr
FROM events
WHERE project_id = '{{ your project ID }}'
AND client_local_date >= '2026-04-01'
GROUP BY project_local_date
ORDER BY project_local_dateYou can also combine multiple events with OR and group with parentheses:
-- A `checkout_complete` event or an `order_create` event counts as a conversion.
SELECT
control_conversion_rate(
'event_type=checkout_complete OR event_type=order_create'
) AS control_cr,
variant_conversion_rate(
'event_type=checkout_complete OR event_type=order_create'
) AS variant_cr
FROM events
WHERE project_id = '{{ your project ID }}'Your own segment with control_users and variant_users
On events, four functions take an optional filter string: control_users,
variant_users, control_sessions, and variant_sessions. The filter counts only a
user or a session that matches your expression. It applies together with the
variant_type filter that PickedQL adds.
-- The control users who fired an `app_initialize` event, by step.
SELECT
step_id,
control_users('event_type=app_initialize') AS control_initialized,
variant_users('event_type=app_initialize') AS variant_initialized
FROM events
WHERE project_id = '{{ your project ID }}'
AND client_local_date >= '2026-04-01'
GROUP BY step_id
ORDER BY control_initialized DESCThe named form (filter=) is also supported:
SELECT control_users(filter='event_type=form_submit AND step_id=lead-capture') FROM events
WHERE project_id = '{{ your project ID }}'Conversion rate from nested virtual functions
The numerator and the denominator can come from different segments. An example is the control users who fired an event of your own, divided by all users and not by the control users alone. For that, pass a virtual function call directly as an argument of the conversion rate:
-- The control users who fired `app_initialize`, over all users of every variant.
SELECT
control_conversion_rate(
control_users('event_type=app_initialize'),
all_users()
) AS control_initialize_rate
FROM events
WHERE project_id = '{{ your project ID }}'
AND client_local_date >= '2026-04-01'A/B test by device
SELECT
device_category,
control_users() AS control,
variant_users() AS variant
FROM metrics
WHERE project_id = '{{ your project ID }}'
GROUP BY device_categoryResult:
| device_category | control | variant |
|---|---|---|
| Phone | 193430 | 1723 |
| Desktop | 23423 | 309 |
| Tablet | 13294 | 65 |
Daily A/B test trend by device
Combine date and device dimensions to spot device-specific trends:
SELECT
project_local_date,
device_category,
control_users() AS control,
variant_users() AS variant
FROM metrics
WHERE project_id = '{{ your project ID }}'
AND project_local_date >= '2026-04-01'
GROUP BY project_local_date, device_category
ORDER BY project_local_date, device_categoryResult:
| project_local_date | device_category | control | variant |
|---|---|---|---|
| 2026-04-13 | Tablet | 175 | 2 |
| 2026-04-14 | Desktop | 37 | 1 |
| 2026-04-14 | Phone | 244 | 1 |
Purchase by UTM source
SELECT
utm_source,
all_users() AS users,
all_purchase_users() AS purchasers
FROM metrics
WHERE project_id = '{{ your project ID }}'
GROUP BY utm_sourceResult:
| utm_source | users | purchasers |
|---|---|---|
meta | 12031 | 101 |
fb | 3656 | 31 |
an | 100366 | 299 |
Step funnel for variant users
Count unique variant users per step to understand the conversion funnel:
SELECT
step_id,
variant_users() AS variant
FROM metrics
WHERE project_id = '{{ your project ID }}'
AND project_local_date >= '2026-04-01'
GROUP BY step_id
ORDER BY variant DESCResult:
| step_id | variant |
|---|---|
who-are-you-protecting-step | 1093 |
about-yourself-step | 533 |
date-of-birth-step | 435 |
employment-status-step | 408 |
nicotine-usage-step | 407 |
coverage-motivation-step | 405 |
lead-capture-step | 398 |
Sankey — overall user journey
A forward window from the starting step. A user who never reaches targeting_step
still gives edges, up to num_nodes_after_start.
SELECT source, target, users FROM experience_journey
WHERE project_id = '{{ your project ID }}'
AND starting_step = '{{ starting step ID }}'
AND targeting_step = '{{ target step ID }}'
AND num_nodes_after_start = 10Result:
| source | target | users |
|---|---|---|
001. step-start | 002. step-questionnaire-1 | 182 |
002. step-questionnaire-1 | 003. step-quote | 144 |
003. step-quote | 004. step-target | 121 |
Sankey — the top paths to a target step
A backward window anchored at the target. It also ranks the paths and keeps the ones with the most users.
SELECT source, target, users FROM experience_journey
WHERE project_id = '{{ your project ID }}'
AND experience_id = '{{ experience ID }}'
AND starting_step = '{{ starting step ID }}'
AND targeting_step = '{{ target step ID }}'
AND num_nodes_before_target = 5
AND top_n_path = 10Sankey — drop-off view
Starts at starting_step and emits every consecutive transition until num_nodes_after_start steps later (no target).
SELECT source, target, users FROM experience_journey
WHERE project_id = '{{ your project ID }}'
AND experience_id = '{{ experience ID }}'
AND starting_step = '{{ starting step ID }}'
AND num_nodes_after_start = 10List all control users for mobile (user-level)
Use events when you need data at the individual user level:
SELECT
device_category,
user_canonical_id
FROM events
WHERE project_id = '{{ your project ID }}'
AND device_category = 'Mobile'
AND variant_type = 'Control'Result:
| device_category | user_canonical_id |
|---|---|
| Mobile | 019cc336-5a6a-7c32-b638-cdcc983b3e70 |
| Mobile | 019cc336-5a6a-7d8f-994c-69bc28e5f550 |
| Mobile | 019cc80f-503c-7181-b2c6-986b1f76d496 |
Related
- About PickedQL — what the layer expands for you.
- Virtual functions — every function.
- Dimensions — every dimension column.
- Analytics events — every
event_typevalue that a filter can use. - Reports — the same data as an embedded dashboard.
