ga4 auth login --client-id <id> --client-secret <secret>
ga4 auth login --service-account <path>
ga4 auth status [-o json|table|csv]
ga4 auth logout
ga4 properties list [--filter <expr>] [--page-size <n>] [--page-token <token>] [-o json|table|csv]
ga4 properties get --property-id <id> [-o json|table|csv]
ga4 reports run --property-id <id> --metrics <m1,m2> --start-date <date> --end-date <date> [--dimensions <d1,d2>] [--limit <n>] [--offset <n>] [--order-by <field>] [-o json|table|csv]
ga4 realtime run --property-id <id> --metrics <m1,m2> [--dimensions <d1,d2>] [--limit <n>] [-o json|table|csv]
ga4 dimensions list --property-id <id> [--category <cat>] [--custom-only] [-o json|table|csv]
ga4 metrics list --property-id <id> [--category <cat>] [--custom-only] [-o json|table|csv]
OAuth2 (interactive): Requires Google Cloud project with Analytics API enabled.
- Set
GA4_CLIENT_IDandGA4_CLIENT_SECRETenv vars, then runga4 auth login - Or pass
--client-idand--client-secretflags
Service Account: Requires service account JSON key file.
- Run
ga4 auth login --service-account /path/to/key.json
Direct Token: For scripting/CI.
- Set
GA4_ACCESS_TOKENenv var - Or pass
--access-tokenflag on any command
Token resolution order: --access-token flag > GA4_ACCESS_TOKEN env > config file
ga4 properties list --output tablega4 reports run \
--property-id 123456 \
--metrics activeUsers,sessions,screenPageViews \
--dimensions date \
--start-date 7daysAgo \
--end-date today \
--output tablega4 reports run \
--property-id 123456 \
--metrics screenPageViews \
--dimensions pagePath \
--start-date 30daysAgo \
--end-date today \
--order-by -screenPageViews \
--limit 20 \
--output tablega4 realtime run \
--property-id 123456 \
--metrics activeUsers \
--dimensions country \
--output tablega4 reports run \
--property-id 123456 \
--metrics activeUsers,sessions \
--dimensions city,country \
--start-date 2024-01-01 \
--end-date 2024-01-31 \
--output csv > report.csvga4 dimensions list --property-id 123456 --output table
ga4 metrics list --property-id 123456 --category Session --output tableAll commands return arrays of flat objects:
[
{
"city": "New York",
"country": "United States",
"activeUsers": "1234",
"sessions": "5678"
}
]Report values are always strings (GA4 API returns strings for all values).
[
{
"property_id": "123456",
"name": "My Website",
"time_zone": "America/New_York",
"currency": "USD",
"industry": "TECHNOLOGY",
"service_level": "GOOGLE_ANALYTICS_STANDARD",
"created": "2024-01-01T00:00:00Z"
}
]| Code | Meaning | Action |
|---|---|---|
AUTH_FAILED |
Invalid or expired credentials | Run ga4 auth login |
RATE_LIMITED |
API rate limit exceeded | Wait and retry (auto-retry built in) |
API_ERROR |
General API error | Check error message for details |
- Google Analytics Data API: 10 concurrent requests, 10,000 requests per day per project
- Auto-retry with exponential backoff on 429 responses
- Use
--quietto suppress retry status messages
Reports support both absolute and relative dates:
- Absolute:
YYYY-MM-DD(e.g.,2024-01-01) - Relative:
today,yesterday,NdaysAgo(e.g.,7daysAgo,30daysAgo)