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.

Google Analytics CLI Setup

Google Analytics can be configured headlessly with `kosmokrator integrations:configure google-analytics`.

Install, configure, and verify
# 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 reuse the same stored profile from scripts, coding CLIs, Lua, and MCP.

KeyEnv varTypeRequiredLabel
access_token GOOGLE_ANALYTICS_ACCESS_TOKEN OAuth token oauth yes Google Account

Command Patterns

The generic command is stable across every integration. The provider shortcut is shorter for humans.

Generic CLI call
kosmo integrations:call google-analytics.google_analytics_list_properties '{}' --json
Provider shortcut
kosmo integrations:google-analytics google_analytics_list_properties '{}' --json

Discovery

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

Discovery commands
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

Automation Contexts

The same configured command surface works in these environments. The command does not change unless the host wrapper, credentials, or permissions change.

CLI Functions

Every function below can be called headlessly. Commands are highlighted, copyable, and scroll horizontally when payloads are long.

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.

Read read
Parameters
none
Generic call
kosmo integrations:call google-analytics.google_analytics_list_properties '{}' --json
Shortcut
kosmo integrations:google-analytics google_analytics_list_properties '{}' --json

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.

Read read
Parameters
property_id
Generic call
kosmo integrations:call google-analytics.google_analytics_metadata '{"property_id":"example_property_id"}' --json
Shortcut
kosmo integrations:google-analytics google_analytics_metadata '{"property_id":"example_property_id"}' --json

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.

Read read
Parameters
property_id, metrics, dimensions, limit
Generic call
kosmo integrations:call google-analytics.google_analytics_realtime '{"property_id":"example_property_id","metrics":"example_metrics","dimensions":"example_dimensions","limit":1}' --json
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

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.

Read read
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 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
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

google-analytics.google_analytics_check_compatibility

Check whether GA4 dimensions and metrics can be combined in a report request.

Read read
Parameters
property_id, metrics, dimensions, filters, metric_filters, compatibility_filter
Generic call
kosmo integrations:call google-analytics.google_analytics_check_compatibility '{"property_id":"example_property_id","metrics":"example_metrics","dimensions":"example_dimensions","filters":"example_filters","metric_filters":"example_metric_filters","compatibility_filter":"example_compatibility_filter"}' --json
Shortcut
kosmo integrations:google-analytics google_analytics_check_compatibility '{"property_id":"example_property_id","metrics":"example_metrics","dimensions":"example_dimensions","filters":"example_filters","metric_filters":"example_metric_filters","compatibility_filter":"example_compatibility_filter"}' --json

google-analytics.google_analytics_pivot_report

Run a GA4 pivot report for advanced cross-tabbed dimension and metric analysis.

Read read
Parameters
property_id, metrics, dimensions, pivots, start_date, end_date, filters, metric_filters, limit
Generic call
kosmo integrations:call google-analytics.google_analytics_pivot_report '{"property_id":"example_property_id","metrics":"example_metrics","dimensions":"example_dimensions","pivots":"example_pivots","start_date":"example_start_date","end_date":"example_end_date","filters":"example_filters","metric_filters":"example_metric_filters"}' --json
Shortcut
kosmo integrations:google-analytics google_analytics_pivot_report '{"property_id":"example_property_id","metrics":"example_metrics","dimensions":"example_dimensions","pivots":"example_pivots","start_date":"example_start_date","end_date":"example_end_date","filters":"example_filters","metric_filters":"example_metric_filters"}' --json

google-analytics.google_analytics_batch_run_reports

Run multiple GA4 standard report requests in one batchRunReports call.

Read read
Parameters
property_id, requests
Generic call
kosmo integrations:call google-analytics.google_analytics_batch_run_reports '{"property_id":"example_property_id","requests":"example_requests"}' --json
Shortcut
kosmo integrations:google-analytics google_analytics_batch_run_reports '{"property_id":"example_property_id","requests":"example_requests"}' --json

google-analytics.google_analytics_batch_run_pivot_reports

Run multiple GA4 pivot report requests in one batchRunPivotReports call.

Read read
Parameters
property_id, requests
Generic call
kosmo integrations:call google-analytics.google_analytics_batch_run_pivot_reports '{"property_id":"example_property_id","requests":"example_requests"}' --json
Shortcut
kosmo integrations:google-analytics google_analytics_batch_run_pivot_reports '{"property_id":"example_property_id","requests":"example_requests"}' --json

Function Schemas

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

google-analytics.google_analytics_list_properties 0 parameters
Schema command
kosmo integrations:schema google-analytics.google_analytics_list_properties --json
ParameterTypeRequiredDescription
No parameters.
google-analytics.google_analytics_metadata 1 parameters
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 4 parameters
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 13 parameters
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).
google-analytics.google_analytics_check_compatibility 6 parameters
Schema command
kosmo integrations:schema google-analytics.google_analytics_check_compatibility --json
ParameterTypeRequiredDescription
property_id string yes GA4 property ID.
metrics array no Metric names to check.
dimensions array no Dimension names to check.
filters array no Dimension filters matching the report request.
metric_filters array no Metric filters matching the report request.
compatibility_filter string no Optional compatibility filter accepted by the Data API.
google-analytics.google_analytics_pivot_report 9 parameters
Schema command
kosmo integrations:schema google-analytics.google_analytics_pivot_report --json
ParameterTypeRequiredDescription
property_id string yes GA4 property ID.
metrics array yes Metric names to measure.
dimensions array no Dimension names used by pivots.
pivots array no Data API pivot definitions. If omitted, one pivot is built from dimensions.
start_date string no Start date. Default: 28daysAgo.
end_date string no End date. Default: yesterday.
filters array no Dimension filters.
metric_filters array no Metric filters.
limit integer no Default pivot limit when pivots are omitted.
google-analytics.google_analytics_batch_run_reports 2 parameters
Schema command
kosmo integrations:schema google-analytics.google_analytics_batch_run_reports --json
ParameterTypeRequiredDescription
property_id string yes GA4 property ID.
requests array yes Array of Data API RunReportRequest bodies.
google-analytics.google_analytics_batch_run_pivot_reports 2 parameters
Schema command
kosmo integrations:schema google-analytics.google_analytics_batch_run_pivot_reports --json
ParameterTypeRequiredDescription
property_id string yes GA4 property ID.
requests array yes Array of Data API RunPivotReportRequest bodies.

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.