KosmoKrator

analytics

Google Analytics CLI for AI Agents

Use the Google Analytics CLI from KosmoKrator to call Google Analytics tools headlessly, return JSON, inspect schemas, and automate workflows from coding agents, scripts, and CI.

4 functions 4 read 0 write OAuth browser flow auth

Google Analytics CLI Setup

Google Analytics can be configured headlessly with `kosmokrator integrations:configure google_analytics`.

# Install KosmoKrator first if it is not available on PATH.
curl -fsSL https://raw.githubusercontent.com/OpenCompanyApp/kosmokrator/main/install.sh | bash

# Configure and verify this integration.
kosmokrator integrations:configure google_analytics --set access_token="$GOOGLE_ANALYTICS_ACCESS_TOKEN" --enable --read allow --write ask --json
kosmokrator integrations:doctor google_analytics --json
kosmokrator integrations:status --json

Credentials

Authentication type: OAuth browser flow oauth2_authorization_code. Configure credentials once, then use the same stored profile from scripts, coding CLIs, Lua code mode, and the MCP gateway.

KeyEnv varTypeRequiredLabel
access_token GOOGLE_ANALYTICS_ACCESS_TOKEN OAuth token oauth yes Google Account

Call Google Analytics Headlessly

Use the generic call form when another coding CLI or script needs a stable universal interface.

kosmo integrations:call google_analytics.google_analytics_list_properties '{}' --json

Use the provider shortcut form for shorter human-facing commands.

kosmo integrations:google_analytics google_analytics_list_properties '{}' --json

Agent Discovery Commands

These commands return structured output for coding agents that need to inspect capabilities before choosing a function.

kosmo integrations:docs google_analytics --json
kosmo integrations:docs google_analytics.google_analytics_list_properties --json
kosmo integrations:schema google_analytics.google_analytics_list_properties --json
kosmo integrations:search "Google Analytics" --json
kosmo integrations:list --json

All CLI Functions

Every function below can be called headlessly. The generic form is stable across all integrations; the provider shortcut is shorter but specific to Google Analytics.

google_analytics.google_analytics_list_properties

Read read

List all accessible GA4 properties with their IDs and names. Use this first to discover the propertyId needed for other Analytics tools.

Parameters
none

Generic CLI call

kosmo integrations:call google_analytics.google_analytics_list_properties '{}' --json

Provider shortcut

kosmo integrations:google_analytics google_analytics_list_properties '{}' --json

google_analytics.google_analytics_metadata

Read read

List all available dimensions and metrics for a GA4 property, including custom ones. Use this to discover what data can be queried in reports.

Parameters
property_id

Generic CLI call

kosmo integrations:call google_analytics.google_analytics_metadata '{"property_id":"example_property_id"}' --json

Provider shortcut

kosmo integrations:google_analytics google_analytics_metadata '{"property_id":"example_property_id"}' --json

google_analytics.google_analytics_realtime

Read read

Run a GA4 realtime report showing activity in the last 30 minutes. Common dimensions: country, city, deviceCategory, unifiedScreenName (page/screen), platform. Common metrics: activeUsers, screenPageViews, eventCount, conversions.

Parameters
property_id, metrics, dimensions, limit

Generic CLI call

kosmo integrations:call google_analytics.google_analytics_realtime '{"property_id":"example_property_id","metrics":"example_metrics","dimensions":"example_dimensions","limit":1}' --json

Provider shortcut

kosmo integrations:google_analytics google_analytics_realtime '{"property_id":"example_property_id","metrics":"example_metrics","dimensions":"example_dimensions","limit":1}' --json

google_analytics.google_analytics_report

Read read

Run a GA4 analytics report. Returns rows of dimension/metric data for the specified date range. Common dimensions: sessionSource, sessionMedium, sessionDefaultChannelGroup (traffic source); pagePath, pageTitle, landingPage (pages); country, city (geo); deviceCategory, browser, operatingSystem (device); date, dateHour, month (time); newVsReturning (user); eventName (events). Common metrics: sessions, totalUsers, newUsers, activeUsers (traffic); screenPageViews, bounceRate, averageSessionDuration, engagementRate, sessionsPerUser (engagement); eventCount, conversions (events); purchaseRevenue, totalRevenue (e-commerce). Dates: YYYY-MM-DD or relative: "today", "yesterday", "7daysAgo", "28daysAgo", "30daysAgo", "90daysAgo", "365daysAgo". Filter operators: exact, contains, begins_with, ends_with, regex, in_list. Metric filter operators: equal, less_than, greater_than, less_than_or_equal, greater_than_or_equal.

Parameters
property_id, metrics, dimensions, start_date, end_date, compare_start_date, compare_end_date, filters, metric_filters, order_by, order_direction, limit, offset

Generic CLI call

kosmo integrations:call google_analytics.google_analytics_report '{"property_id":"example_property_id","metrics":"example_metrics","dimensions":"example_dimensions","start_date":"example_start_date","end_date":"example_end_date","compare_start_date":"example_compare_start_date","compare_end_date":"example_compare_end_date","filters":"example_filters"}' --json

Provider shortcut

kosmo integrations:google_analytics google_analytics_report '{"property_id":"example_property_id","metrics":"example_metrics","dimensions":"example_dimensions","start_date":"example_start_date","end_date":"example_end_date","compare_start_date":"example_compare_start_date","compare_end_date":"example_compare_end_date","filters":"example_filters"}' --json

Function Schemas

Use these parameter tables when building CLI payloads without calling integrations:schema first.

google_analytics.google_analytics_list_properties

List all accessible GA4 properties with their IDs and names. Use this first to discover the propertyId needed for other Analytics tools.

Operation
Read read
Schema command
kosmo integrations:schema google_analytics.google_analytics_list_properties --json
ParameterTypeRequiredDescription
No parameters.

google_analytics.google_analytics_metadata

List all available dimensions and metrics for a GA4 property, including custom ones. Use this to discover what data can be queried in reports.

Operation
Read read
Schema command
kosmo integrations:schema google_analytics.google_analytics_metadata --json
ParameterTypeRequiredDescription
property_id string yes GA4 property ID (numeric, e.g., "123456789"). Use google_analytics_list_properties to find it.

google_analytics.google_analytics_realtime

Run a GA4 realtime report showing activity in the last 30 minutes. Common dimensions: country, city, deviceCategory, unifiedScreenName (page/screen), platform. Common metrics: activeUsers, screenPageViews, eventCount, conversions.

Operation
Read read
Schema command
kosmo integrations:schema google_analytics.google_analytics_realtime --json
ParameterTypeRequiredDescription
property_id string yes GA4 property ID (numeric, e.g., "123456789"). Use google_analytics_list_properties to find it.
metrics array no Metric names (default: ["activeUsers"]). Common: activeUsers, screenPageViews, eventCount, conversions.
dimensions array no Dimension names to group by (e.g., ["country", "unifiedScreenName"]). Optional — omit for aggregate totals.
limit integer no Max rows to return (default 10).

google_analytics.google_analytics_report

Run a GA4 analytics report. Returns rows of dimension/metric data for the specified date range. Common dimensions: sessionSource, sessionMedium, sessionDefaultChannelGroup (traffic source); pagePath, pageTitle, landingPage (pages); country, city (geo); deviceCategory, browser, operatingSystem (device); date, dateHour, month (time); newVsReturning (user); eventName (events). Common metrics: sessions, totalUsers, newUsers, activeUsers (traffic); screenPageViews, bounceRate, averageSessionDuration, engagementRate, sessionsPerUser (engagement); eventCount, conversions (events); purchaseRevenue, totalRevenue (e-commerce). Dates: YYYY-MM-DD or relative: "today", "yesterday", "7daysAgo", "28daysAgo", "30daysAgo", "90daysAgo", "365daysAgo". Filter operators: exact, contains, begins_with, ends_with, regex, in_list. Metric filter operators: equal, less_than, greater_than, less_than_or_equal, greater_than_or_equal.

Operation
Read read
Schema command
kosmo integrations:schema google_analytics.google_analytics_report --json
ParameterTypeRequiredDescription
property_id string yes GA4 property ID (numeric, e.g., "123456789"). Use google_analytics_list_properties to find it.
metrics array yes Metric names to measure (e.g., ["sessions", "totalUsers"]).
dimensions array no Dimension names to group by (e.g., ["country", "pagePath"]). Optional — omit for aggregate totals.
start_date string no Start date: YYYY-MM-DD or relative ("7daysAgo", "28daysAgo", "yesterday", "today"). Default: "28daysAgo".
end_date string no End date: YYYY-MM-DD or relative. Default: "yesterday".
compare_start_date string no Comparison period start date (for period-over-period).
compare_end_date string no Comparison period end date.
filters array no Dimension filters: [{dimension, operator, value}]. Operators: exact, contains, begins_with, ends_with, regex, in_list.
metric_filters array no Metric filters: [{metric, operator, value}]. Operators: equal, less_than, greater_than, less_than_or_equal, greater_than_or_equal.
order_by string no Dimension or metric name to sort by.
order_direction string no "asc" or "desc" (default "desc").
limit integer no Max rows to return (default 10).
offset integer no Pagination offset (default 0).

Permissions

Headless calls still follow the integration read/write permission policy. Configure read/write defaults with integrations:configure. Add --force only for trusted automation that should bypass that policy.