Skip to main content

Example Queries

Find change-state events

SELECT
*
FROM session_events_view
WHERE timestamp BETWEEN '2025-08-10' AND '2025-08-11'
AND organization_name = 'my organization'
AND venue = 'my venue'
AND action = 'change-state';

Aggregate product-sessions

Users start their journey on one device and continue on another. Such a session may contain two "product-sessions" (ie. two sessions with distinct context). For example, a customer might begin by using a directory to search for a store, then scan a QR code to get directions on their mobile phone. This query splits such sessions apart and counts the number of events that occurred in each product-session.

SELECT
count(*) AS number_of_events_in_session,
session_id,
context
-- other fields whose value remains constant throughout a product-session
FROM session_events_view
WHERE timestamp BETWEEN '2025-08-10' AND '2025-08-11'
AND organization_name = 'my organization'
GROUP BY ALL;

Result

NUMBER_OF_EVENTS_IN_SESSIONSESSION_IDCONTEXT
16XaGW8ggviPjasUkrqgoOGvBxZ+YZfR/XyXwz7O+Dkp0=Directory
14HhkF9om5R6dd/3LsNpn3B+Q/iEa/5N7D2xIg43BCBKg=Premium Directory
27HdCYKU6c90WBmfYiO/uLwwxsd+mMzWNDw9IFLZyboFw=Web
4domPic+L2h+IqOrTrtJrs9o4NnZPpLoJwwYIN5XQkns=Web

Compact Searches

This query simplifies your data by combining multiple consecutive searches into a single search event, then shows you exactly what the user selected afterward - whether it was a specific location or a category.

You can see the complete picture of search behavior - not just what people search for, but what they actually choose. This helps you understand:

  • Which search results are most effective
  • Whether users find what they're looking for quickly
  • How to improve your search functionality to better match user intent
SELECT
timestamp,
context,
action,
query,
next_action,
location_id_found,
category_id_found,
is_completed_search
FROM (
SELECT
*,
data:query::STRING AS query,
LEAD(action) OVER (
PARTITION BY session_id, context
ORDER BY timestamp ASC
) AS next_action,
LEAD(data) OVER (
PARTITION BY session_id, context
ORDER BY timestamp ASC
) AS next_data,
action = 'search' AND COALESCE(next_action = 'search', FALSE) AS is_ignored,
next_data:location::STRING AS location_id_found,
next_data:category::STRING AS category_id_found,
action = 'search' AND next_action IN ('select-location', 'select-category') AS is_completed_search
FROM session_events_view
WHERE timestamp BETWEEN '2025-08-10' AND '2025-08-11'
AND organization_name = 'my organization'
)
WHERE action = 'search'
AND is_ignored = FALSE;

Result

TIMESTAMPCONTEXTACTIONQUERYNEXT_ACTIONLOCATION_ID_FOUNDCATEGORY_ID_FOUNDIS_COMPLETED_SEARCH
2025-08-10 22:42:52.617 +0000WebsearchSushi jirochange-stateFALSE
2025-08-10 22:42:52.617 +0000WebsearchBraselect-location5b0f85d2e9b85720eb59729dTRUE
2025-08-10 20:12:09.616 +0000WebsearchBrandschange-stateFALSE
2025-08-10 20:12:09.616 +0000WebsearchCheeseselect-category6c0f85d2e9b85720eb5972deTRUE