data-querying
Data Querying
The analytics app connects to multiple data sources. This skill covers general patterns for querying data effectively.
Approach
- Orient catalog-first — before querying, consult what already exists: the injected
<data-dictionary>and data-source status tell you which sources are configured and which table/columns/join paths to use. Use them to pick the one source that owns the fact instead of fanning out blind queries. - Read the relevant provider skill first — check
.agents/skills/<provider>/SKILL.mdfor table names, column mappings, auth, and gotchas. For BigQuery, read.agents/skills/bigquery/SKILL.mdand usesearch-bigquery-schemabefore guessing table or column names. - Clarify if ambiguous — if the metric definition, date range, or grain is unclear and a wrong guess would change the numbers, use the
ask-questionclarifying tool (multiple-choice) before querying. Ask at most once per turn; skip it when the dictionary or the user already answered. - Use existing actions or connected provider MCP tools — call the provider action/tool with structured arguments, then filter or aggregate the returned records in your answer
- Write ad-hoc scripts — if no existing script covers the question, create one in
actions/ - Present data in chat — don't just say "check the dashboard" — actually query, get the data, and present it. Only present numbers you actually retrieved; never report a value you did not query.
For events recorded by the analytics template itself via its /track endpoint, use pnpm action query-agent-native-analytics --sql "SELECT ... FROM analytics_events ...". This includes pageviews, site/app traffic, template usage, app usage, and event counts collected by this analytics app. Pageviews and traffic can also live in GA4, BigQuery/warehouse tables, Mixpanel, PostHog, Amplitude, or another configured provider, so choose the source from the user's wording, connected-source status, existing dashboards, data dictionary, and user/org resources. Ask one concise clarification if multiple configured sources are plausible. Do not use db-query for data-source analysis; db-query is only for internal app tables and will confuse analytics questions. The shipped agent-native-templates-first-party SQL dashboard is the template engagement dashboard for the first-party collector source.
Example pageviews query for a local calendar day: