Skip to content

Guide · Agent skill

How to use the Google Analytics Data API Basics agent skill

Updated · written with AI from the project's own documentation and checked against our catalogue data

This guide explains the Google Analytics Data API Basics agent skill: what it changes about how your coding agent works, how to install it, and how to ask for help with GA4 reporting. It is written for readers who have never used an agent skill before. By the end you will know how to install the skill, enable the Analytics Data API in a Google Cloud project, authenticate, and run a Python report that pulls active users and sessions by city and date.

Google Analytics Data API Basicsgoogle/skills · Apache-2.0

Quick start

  1. 1Download and unzip the skill. Download the ZIP from this page and unzip it so you have the google-analytics-data-api-basics folder with SKILL.md and references.
  2. 2Place the skill folder. Put the folder in ~/.claude/skills/ for personal use, or in a project's .claude/skills/ folder. In the Claude apps, you can instead upload it under Settings → Capabilities → Skills.
  3. 3Enable the API. Run gcloud services enable analyticsdata.googleapis.com --quiet, then confirm it with gcloud services list --enabled.
  4. 4Log in with ADC. Run gcloud auth application-default login with the cloud-platform and analytics.readonly scopes.
  5. 5Install the client library. Run pip install google-analytics-data, or the equivalent package for your language from its setup guide.
  6. 6Run the report. Replace YOUR-PROPERTY-ID with your GA property ID and run the script to print active users and sessions by city and date.

What the skill makes the agent do

Once installed, the skill gives the agent working knowledge of the Google Analytics Data API (v1beta) for a Google Cloud project. The agent can run gcloud commands to enable the API and check that it is enabled, walk you through Application Default Credentials login, and choose the right client library setup guide for your programming language.

It can also write a working Python script that pulls active users and sessions by city and date from a Google Analytics property, and it checks that dimension and metric names are valid before you run the report.

  • Enables and verifies the analyticsdata.googleapis.com API with gcloud
  • Guides Application Default Credentials login with the required scopes
  • Points to setup references for Python, Java, PHP, Node.js, Go, .NET and Ruby
  • Writes a Python RunReportRequest example and checks dimension and metric names
  • Does not manage GA properties, users or tracking code

Install the skill from the ZIP download

Download the ZIP for this skill from this page and unzip it. The skill is a folder that contains SKILL.md and a references folder with one setup guide per language.

For a personal install, place the unzipped folder in ~/.claude/skills/. For a single project, place it in the project's .claude/skills/ folder instead. Alternatively, in the Claude apps, open Settings, go to Capabilities, and upload the skill under Skills.

  • Personal: ~/.claude/skills/
  • Project only: .claude/skills/ inside your project
  • Claude apps: Settings → Capabilities → Skills, then upload

Set up Google Cloud before the first report

Before making API calls, the Google Analytics Data API must be enabled in your Google Cloud project. If the gcloud command is not found, install the Google Cloud CLI first.

Enable the API, then verify that it shows as enabled.

gcloud services enable analyticsdata.googleapis.com --quiet gcloud services list --enabled --filter="analyticsdata.googleapis.com"

Authenticate with Application Default Credentials

The client library authenticates using Application Default Credentials (ADC). Run the login command below in your terminal. It requests the Cloud Platform scope and the Google Analytics read-only scope, so your account must have read access to the GA property you want to query.

gcloud auth application-default login --scopes="https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/analytics.readonly"

Ask for a report with natural requests

You do not need to name the skill. Describe what you want in plain language and mention the language you use if it matters. The skill is meant to be used for requests such as checking whether the API is enabled, querying metrics like activeUsers or screenPageViews, or grouping results by dimensions like city or date.

For a Python report, install the client library and run the example. Replace YOUR-PROPERTY-ID with your numeric GA property ID, for example 1234567.

  • "Check that the Google Analytics Data API is enabled in my Cloud project."
  • "Write a Python script that gets active users and sessions by city and date for my GA property."
  • "Which setup guide should I use for Go?"
  • "Is the dimension deviceCategory compatible with sessions in one report?"
pip install google-analytics-data

Run the Python example

The skill's Python example creates a BetaAnalyticsDataClient, sends a RunReportRequest with the city and date dimensions and the activeUsers and sessions metrics, and prints each row. The date range starts on 2026-05-01 and ends on today; change these values to suit your report.

The client reads your ADC login automatically, so the script does not contain credentials.

  • Dimensions used: city, date
  • Metrics used: activeUsers, sessions
  • Date range: start_date 2026-05-01 to end_date today
from google.analytics.data_v1beta import BetaAnalyticsDataClient from google.analytics.data_v1beta.types import DateRange, Dimension, Metric, RunReportRequest def sample_run_report(property_id: str): client = BetaAnalyticsDataClient() request = RunReportRequest( property=f"properties/{property_id}", dimensions=[Dimension(name="city"), Dimension(name="date")], metrics=[Metric(name="activeUsers"), Metric(name="sessions")], date_ranges=[DateRange(start_date="2026-05-01", end_date="today")], ) response = client.run_report(request) for row in response.rows: print( f"City: {row.dimension_values[0].value}, " f"Date: {row.dimension_values[1].value}, " f"Active Users: {row.metric_values[0].value}, " f"Sessions: {row.metric_values[1].value}" ) if __name__ == "__main__": sample_run_report("YOUR-PROPERTY-ID")

Choose valid dimensions and metrics

Dimension and metric names must match the API's names exactly. The skill lists commonly used ones, and the official Data API schema documentation is the full reference. Some fields cannot be combined in one request; if you get an INVALID_ARGUMENT error about incompatible fields, check the combination.

  • Dimensions: city, country, date (YYYYMMDD), deviceCategory, eventName, pageTitle
  • Metrics: activeUsers, eventCount, sessions, screenPageViews, totalRevenue

Safety notes: scripts and network access

This skill runs scripts and uses the network. Its commands call gcloud and pip, and the example script calls the Google Analytics Data API to fetch your report data. Review any command the agent proposes before you approve it, and only point the script at a property you are allowed to read.

The skill is scoped to read-only analytics access. It excludes the Admin API, so it will not create properties or manage users, and it excludes front-end tracking installation.

  • Read the proposed gcloud and pip commands before running them
  • Use the analytics.readonly scope the skill requests; do not broaden scopes without reason
  • The skill does not handle GA admin tasks or tracking tags

Tips for smoother results

Tell the agent your programming language at the start, so it reads the right setup guide. If a request fails, check first that the API is enabled, that you ran the ADC login, and that the account can read the property. Keep the property ID numeric, as in the example.

  • Mention your language in the first message
  • If gcloud is missing, install the Google Cloud CLI before continuing
  • If pip is missing, install pip before installing the client library
  • Start with a short date range to confirm the setup works

What people use it for

  • A developer builds a dashboard that shows daily active users by city.
  • An analyst writes a script that exports sessions by date to a spreadsheet-ready output.
  • A team checks that the Analytics Data API is enabled and configured in a new Cloud project.
  • An engineer asks which client library guide applies to a Node.js or Go service.

Frequently asked questions

How do I install the Google Analytics Data API agent skill?

Download the ZIP from this page and unzip it. Place the folder in ~/.claude/skills/ for personal use or in your project's .claude/skills/ folder, or upload it in the Claude apps under Settings → Capabilities → Skills.

What do I need before the skill can query my GA data?

You need the Google Cloud CLI (gcloud), Python with pip if you use the Python example, a Google Cloud project with the Analytics Data API enabled, your GA4 property ID, and an account with read access to that property. You also need to run gcloud auth application-default login with the required scopes.

Does the skill cost money or have a licence?

The skill is licensed under Apache-2.0. This page does not state any pricing for the Google Cloud or Analytics services it uses, so check those services' own terms.

Can this skill create GA properties or manage users?

No. The skill explicitly excludes Google Analytics Admin API operations such as creating properties or managing users, and it does not install website tracking tags.

Why does my report return INVALID_ARGUMENT?

Some dimensions and metrics cannot be queried together in the same request. Check that your dimension and metric names are valid and that the combination is compatible, using the official Data API schema documentation.

How does this compare with using the client library directly?

The skill saves setup time by enabling the API, guiding authentication, choosing the right language guide, and drafting a script. You still need the Cloud project, gcloud, and property access; the skill does not replace them.

New agent skills, repos and AI tools — every week

The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.

Our verdict

This skill suits developers building dashboards or automated reports from GA4 data, and analysts who want a starting script in one of several languages. It is a poor fit if you need to create properties, manage users, or install tracking tags, since it excludes those tasks. Anyone without a Google Cloud project and property access should set those up first.

Download the skill