Docs / Reports and insights

Analytics with SQL

Use fourteen read-only analytics views for custom analysis and reports.

Overview

Datum exposes fourteen read-only analytics views. Anyone in the workspace can query them with SQL. Your agent can inspect the views and write queries for you.

The views support analysis rather than personal lookups. They exclude email addresses, profile URLs, handles, locations, message text, connection settings and credentials. Every query runs within your workspace with read-only access and a time limit.

Basics

Start with describe

Run describe before writing a query.

ocmgr analytics describe --json

The response lists views, columns, metric definitions and limits.

Ask your agent to inspect this response before it writes SQL.

The views

All views use the analytics schema.

View One row per
members Person after merging
activity Activity event, with is_team and is_contribution
daily_activity, member_months Person per day or month with activity
segments, segment_memberships Segment or period of membership
tags Tag
organisations Derived organization
connections Connected source
events Community event, such as a meetup or webinar
presence Person seen on a source on a day
threads Conversations described by a source or observed in activity
event_rsvps Whether a member is still registered for a Circle event
usage_days Usage metric per day; see Usage

members.display_name remains empty unless your workspace includes personal data in events. Include personal data in events, under Event content in Settings → Destinations, controls this setting. Disabling it takes effect on the next query.

Run a query

Run the following query to count contributors.

ocmgr analytics query \
  'select count(distinct member_id)::int as members from analytics.activity where not is_team and is_contribution' \
  --json

Use not is_team to exclude your staff. Standard Datum metrics exclude them.

Use is_contribution when counting active members. Contributions exclude channel joins and account events. The daily_activity and member_months aggregates include all activity, including joins.

Pass values through positional parameters such as $1, $2 and $3. Use --param 1=2026-08-01 2=2026-09-01 in the CLI. Use "params": {"1": "2026-08-01", "2": "2026-09-01"} in MCP or REST.

Times use UTC. Include the start of a time window. Exclude its end.

Save it as a report

Create a report for queries you use repeatedly. Supply the SQL and a short definition. Add a chart if required. Pin the report to Home for quick access.

Limits and the read-only guard

Datum validates every query before execution. The CLI, REST, MCP and saved reports share these rules.

Limit Result
One SELECT over analytics views Datum rejects other statements
10,000 rows Datum truncates the result and reports truncation
4 MB of results Datum stops at the last complete row that fits
5 seconds Datum cancels the query
Estimated planner cost above 100,000 Datum rejects the query before execution

The validator supports a restricted SQL subset. It rejects side effects, multiple statements, system catalogues and functions outside its permitted list. It also rejects these forms:

  • EXCEPT, INTERSECT and = ANY(…).
  • JSON -> and ->> operators.
  • Unbounded builders: concat, ||, array_agg, string_agg and array subqueries.
  • ORDER BY or LIMIT immediately after UNION.

Use joins or EXISTS instead of the unsupported set operations. Wrap a union in a subquery before ordering it.

Unknown syntax returns a usage error. Rewrite the query to use supported syntax. Additional access cannot bypass these restrictions.

Bigint and numeric result columns can be JSON strings to preserve precision. Check the returned column types before using them in calculations.

The community-metrics skill

The Claude Code plugin includes the community-metrics skill. It defines standard metrics and supplies SQL examples.

Examples cover active members, new and returning members, retention, reactivation, responsiveness, contributor stages, segment movement, organization coverage and source mix. The skill also includes event and weekly summaries.

Ask a question after installing the plugin, such as “How many people returned in September after no contributions in August?”.

This skill is available in Claude Code with the plugin installed. A hosted MCP connection alone does not supply its metric definitions or SQL files. The skill inspects the views, adapts a query and checks its result. It can save the result as a report with a PNG.

From your terminal or agent

Describe and query operations require only read access.

ocmgr analytics describe --json
ocmgr analytics query 'select source, count(distinct member_id)::int as members
  from analytics.activity
  where not is_team and is_contribution and occurred_at >= $1 and occurred_at < $2
  group by source' --param 1=2026-08-01 2=2026-09-01 --json

See describe_analytics and run_query for all parameters.

FAQ

How fresh are the numbers?

Member and activity views read live data. Merges, erasures and team changes take effect immediately. The daily_activity and member_months aggregates refresh hourly, so they can lag by an hour.

Why can't I group activity by its title to find threads?

Titles do not identify threads. Use thread_id to link an event to its thread and analytics.threads. Threads inferred from activity include webhook and Slack conversations. Their posted_at is the earliest observed event, while origin and answered are null unless the source supplies that metadata.

Can I query another workspace?

No. Queries use the workspace associated with your key, session or agent.

How can I reduce a query that exceeds the cost limit?

Narrow the date range. Alternatively, aggregate earlier in the query or use analytics.daily_activity instead of individual activity rows.

The estimate is PostgreSQL planner cost, not a row count. A query over millions of rows can stay below this cost limit; the five-second timeout and result limits still apply. Timestamp columns in results use ISO 8601 with a UTC offset (Z).