mcpField
G
google-analytics

google-analytics

github.com/acedatacloudMarketing & growth17168 installsUpdated today
Repository

About google-analytics

A skill for querying Google Analytics 4 data through its Admin and Data APIs using curl and jq. It helps analysts discover accessible properties, run reports, and inspect realtime activity with an OAuth token.

Key features

  1. 01Discover accessible GA4 properties
  2. 02Run reports with selected dimensions and metrics
  3. 03Query realtime activity
  4. 04Handle date ranges and paginated results
  5. 05Interpret API errors and token issues

Use cases

  1. 01Review page views and active users
  2. 02Analyze acquisition or geographic activity
  3. 03Inspect event counts and conversions
  4. 04Check current active users by country

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/acedatacloud/skills --skill google-analytics

After installing, type/google-analyticsin Claude Code to confirm it loaded.

Details

From the project README

Query Google Analytics 4 via curl + jq. The user's OAuth bearer token is in $GOOGLE_ANALYTICS_TOKEN (scope analytics.readonly); every call needs Authorization: Bearer $GOOGLE_ANALYTICS_TOKEN. Two APIs: the Admin API (analyticsadmin.googleapis.com/v1beta) to discover properties, and the Data API (analyticsdata.googleapis.com/v1beta) to run reports.

Failures are {"error":{"code","message","status"}} — show verbatim. 401 = re-install.

AUTH="Authorization: Bearer $GOOGLE_ANALYTICS_TOKEN"
# List the GA4 properties the user can access (via their account summaries)
curl -sS -H "$AUTH" "https://analyticsadmin.googleapis.com/v1beta/accountSummaries" \
  | jq '.accountSummaries[]?.propertySummaries[]? | {property, displayName}'

property looks like properties/123456789 — the number is the PROPERTY_ID.

Run a report

PID="123456789"
curl -sS -X POST -H "$AUTH" -H "Content-Type: application/json" -d '{
  "dateRanges":[{"startDate":"28daysAgo","endDate":"today"}],
  "dimensions":[{"name":"pagePath"}],
  "metrics":[{"name":"screenPageViews"},{"name":"activeUsers"}],
  "orderBys":[{"metric":{"metricName":"screenPageViews"},"desc":true}],
  "limit":10
}' "https://analyticsdata.googleapis.com/v1beta/properties/$PID:runReport" \
  | jq '.rows[] | {page: .dimensionValues[0].value, views: .metricValues[0].value, users: .metricValues[1].value}'

Swap dimensions/metrics for other reports: sessionDefaultChannelGroup + sessions (acquisition), country + activeUsers (geo), eventName + eventCount / conversions (events). Dates accept NdaysAgo, today, yesterday, or YYYY-MM-DD.

Realtime

curl -sS -X POST -H "$AUTH" -H "Content-Type: application/json" \
  -d '{"dimensions":[{"name":"country"}],"metrics":[{"name":"activeUsers"}]}' \
  "https://analyticsdata.googleapis.com/v1beta/properties/$PID:runRealtimeReport" | jq '.rows'

Gotchas

  • This is GA4 only (Data API v1). Old Universal Analytics (UA) is shut down — don't use the legacy analytics/v3 endpoints.
  • Valid dimension/metric API names matter (screenPageViews, not "Pageviews"). If a name 400s, it's the wrong API id — check the GA4 dimensions & metrics list.
  • Reports are capped by limit (default 10k rows); page with offset.

Comments

Markdown supported