/ga-cli:gafrom ga-cli
Read-only Google Analytics 4 CLI (`ga`) for pulling aggregate traffic data from any GA4 property the authorized Google account can see. Wraps the GA Admin API (property discovery) and Data API (runReport / getMetadata) behind Typer, with JSON-by-default output and a --pretty Rich renderer. Use this whenever you need to analyze GA4 traffic, acquisition channels, or source attribution; break down referrers / source-medium; find top pages/posts by views; see geo or daily session trends; or run an arbitrary metric×dimension GA4 report. Triggers: "analyze traffic", "where is traffic coming from", "acquisition channels", "top referrers", "top pages", "traffic trend", "GA4 report", "sessions/users last N days". READ-ONLY, aggregate-only (no user-level/PII). Requires GA OAuth (scope analytics.readonly) — see references/auth-setup.md.
Ships in ga-cli. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
ga is a self-contained Python CLI (Typer + Rich) wrapping two Google Analytics 4
APIs, read-only:
accountSummaries, listDataStreams) → ga properties, ga datastreamsrunReport, getMetadata) → ga report + all canned reportsEvery command prints JSON to stdout by default (pipe into jq); add --pretty
for a Rich table. Errors are emitted as {"error": true, "message": "..."} JSON on
stderr with exit 1, so stdout stays clean and pipeable even on failure.
Auth: user OAuth, scope analytics.readonly only. Cached token at
~/.config/ga-cli/token.json. --help works with no credentials — auth is only
touched when a command actually hits the API. See references/auth-setup.md (and
the 7-day token caveat below).
Property: No default property ID is hardcoded. Set --property <ID> on any
command, or export GA_PROPERTY_ID=<ID>. Run ga properties to discover the
numeric IDs accessible to the authenticated account.
analytics.readonly only — no write/admin-write commands exist.client_secret.json or token.json.| Command | What it does |
|---|---|
ga properties | List accessible properties (account + property names + numeric id) via Admin accountSummaries. |
ga datastreams | List data streams for a property -- measurement ID (G-XXXXXXXXXX), URI, display name. |
ga auth [--reauth] | Load/refresh creds from the cached token; --reauth forces fresh browser consent. Prints authorized / token cached status only. |
ga report --metrics … | Generic runReport (any metrics × dimensions). See flags below. |
ga acquisition | Sessions + users by sessionDefaultChannelGroup. |
ga referrers | Sessions + users by sessionSourceMedium, top N. |
ga top-pages | screenPageViews + sessions by pagePath (+pageTitle), top N. |
ga geo | Sessions + users by country. |
ga trend | Sessions + users by date (daily), ascending. |
ga metadata | Dump all available dimensions & metrics for the property (getMetadata) as JSON. |
Canned reports (acquisition, referrers, top-pages, geo, trend) share:
--days N (trailing window), --property <ID>, --limit N, --pretty.
ga report flags| Flag | Default | Description |
|---|---|---|
--metrics m1,m2 | (required) | Comma-separated metrics, e.g. sessions,totalUsers. |
--dimensions d1,d2 | — | Comma-separated dimensions. |
--start | 28daysAgo | Start date (YYYY-MM-DD or NdaysAgo). |
--end | today | End date (YYYY-MM-DD or today). |
--days N | — | Convenience: sets start=NdaysAgo (overrides --start). |
--property <ID> | GA_PROPERTY_ID env (required if unset) | Target property numeric ID. |
--limit N | 100 | Max rows. |
--order-by field | — | Order by a field; prefix - for descending (e.g. -sessions). |
--pretty | off | Rich table instead of JSON. |
First, discover your property ID:
ga properties | jq -r '.rows[] | [.property_id, .account, .property] | @tsv'
Then set it once (or pass --property on each call):
export GA_PROPERTY_ID=<your-numeric-id>
ga datastreams --property 123456789
# → {"property_id": "123456789", "rows": [{"display_name": "My Site", "stream_id": "...", "type": "1", "measurement_id": "G-XXXXXXXXXX", "default_uri": "https://example.com"}], "count": 1}
ga datastreams --property 123456789 | jq -r '.rows[0].measurement_id'
# → G-XXXXXXXXXX
ga acquisition --days 28 --pretty
# Total sessions + users across all channels:
ga acquisition --days 28 \
| jq '{sessions: ([.rows[].sessions|tonumber]|add), users: ([.rows[].totalUsers|tonumber]|add)}'
ga referrers --days 28 --limit 10 \
| jq -r '.rows[] | [.sessions, .sessionSourceMedium] | @tsv'
ga top-pages --days 28 --limit 10 \
| jq -r '.rows[] | [.screenPageViews, .pagePath] | @tsv'
ga geo --days 28 --limit 5 | jq -c '.rows[]'
ga trend --days 14 | jq -r '.rows[] | [.date, .sessions, .totalUsers] | @tsv'
# Sessions + users by channel group, ordered desc, as a table:
ga report --metrics sessions,totalUsers \
--dimensions sessionDefaultChannelGroup \
--days 28 --order-by -sessions --pretty
# New vs returning users by device category over 90 days, JSON:
ga report --metrics activeUsers,newUsers \
--dimensions deviceCategory --days 90 \
| jq '.rows'
# Engagement rate + avg session duration, last 7 days:
ga report --metrics engagementRate,averageSessionDuration --days 7
# What can I query?
ga metadata | jq '{dims: .dimension_count, metrics: .metric_count}'
# Search for a metric by name:
ga metadata | jq -r '.metrics[] | select(.api_name|test("user";"i")) | .api_name'
# Search dimensions:
ga metadata | jq -r '.dimensions[] | select(.api_name|test("source";"i")) | .api_name'
ga acquisition --property <other-id> --days 28
# or:
GA_PROPERTY_ID=<other-id> ga acquisition --days 28
report and every canned report return:
{
"property_id": "123456789",
"date_range": {"start": "28daysAgo", "end": "today"},
"dimensions": ["sessionDefaultChannelGroup"],
"metrics": ["sessions", "totalUsers"],
"row_count": 10,
"rows": [
{"sessionDefaultChannelGroup": "Organic Social", "sessions": "4921", "totalUsers": "4739"}
]
}
Rows are flat dicts (dimension columns + metric columns), so jq '.rows[]' and
--pretty tables Just Work. Metric values are strings (GA4 returns them as
strings) — use tonumber in jq before arithmetic.
{"error": true, "message": "..."} JSON on stderr, exit 1.
stdout stays empty/clean so pipelines don't ingest garbage.PermissionDenied (403) → the account can't see that --property; check ga properties.--metrics) → Click usage error on stderr, exit 2.--property or GA_PROPERTY_ID.ga auth --reauth
(see the 7-day caveat).The OAuth consent screen is in Testing mode by default, so Google issues refresh
tokens that expire ~7 days after issue. Interactive use is fine (just re-consent),
but this breaks unattended/daemon/scheduled runs after a week. Fix before any
headless wiring: publish the consent screen (Testing → In production) or use a
service account (grant it Viewer on the property) for the scheduled leg. Details
in references/auth-setup.md.
skills/ga/
├── SKILL.md
├── scripts/
│ ├── ga # bash entrypoint (SCRIPT_DIR-relative; chmod +x)
│ ├── requirements.txt # pinned Python deps
│ └── ga_cli/
│ ├── __init__.py
│ ├── __main__.py # `python -m ga_cli`
│ ├── app.py # Typer root app + centralized error wrap
│ ├── client.py # get_creds(), config/auth resolution,
│ │ # admin+data client factories, output helpers
│ ├── auth.py # `ga auth`, `ga properties`
│ ├── report.py # generic `report` + canned reports
│ └── streams.py # `ga datastreams`
└── references/
└── auth-setup.md # GCP setup + the 7-day token caveat
references/auth-setup.md (opens in a new tab)scripts/ga (opens in a new tab)scripts/ga_cli/__init__.py (opens in a new tab)scripts/ga_cli/__main__.py (opens in a new tab)scripts/ga_cli/app.py (opens in a new tab)scripts/ga_cli/auth.py (opens in a new tab)scripts/ga_cli/client.py (opens in a new tab)scripts/ga_cli/report.py (opens in a new tab)scripts/ga_cli/streams.py (opens in a new tab)scripts/requirements.txt (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
Generated from the plugin's indexed repository (griffinwork40/ga-cli) — no native marketplace selected
npx claudepluginhub p/griffinwork40-ga-cli