Skip to main content

Command-line interface for Google Analytics 4

Project description

GA CLI

Command-line interface for Google Analytics 4.

Manage GA4 accounts, properties, data streams, and run reports — all from your terminal.

Features

  • Authentication — OAuth 2.0 (browser-based) and service account support
  • Account management — List, inspect, and update GA4 accounts
  • Property management — List, create, inspect, update, and delete GA4 properties
  • Data stream management — List, create, inspect, update, and delete web, Android, and iOS data streams
  • Custom dimensions & metrics — List, create, update, and archive custom definitions
  • Key events — List, create, update, and delete key events (conversions)
  • Reporting — Run custom reports, pivot reports, real-time reports with live polling, check compatibility, and build reports interactively
  • Flexible output — Table (default), JSON, and compact output formats
  • Self-update — Check for and install updates via ga upgrade
  • Schema introspectionga --describe outputs JSON Schema for all commands (agent/MCP-ready)
  • Shell completions — Generate completion scripts for bash, zsh, and fish
  • Interactive setup — Guided configuration wizard via ga config setup

Installation

From PyPI (recommended)

# pipx (recommended for CLI tools — isolated env)
pipx install google-analytics-cli

# uv
uv tool install google-analytics-cli

# pip
pip install google-analytics-cli

Quick install (script)

curl -fsSL https://raw.githubusercontent.com/daidalytics/google-analytics-cli/master/install.sh | bash

From GitHub

# With uv
uv pip install git+https://github.com/daidalytics/google-analytics-cli.git

# With pip
pip install git+https://github.com/daidalytics/google-analytics-cli.git

From source

git clone https://github.com/daidalytics/google-analytics-cli.git
cd google-analytics-cli
uv sync
uv run ga --help

One-off execution (no install)

uvx --from git+https://github.com/daidalytics/google-analytics-cli.git ga --help

Quick Start

# 1. Authenticate
ga auth login

# 2. List your accounts
ga accounts list

# 3. List properties for an account
ga properties list --account-id 123456789

# 4. Run a report
ga reports run --property-id 987654321 \
  --metrics sessions,totalUsers \
  --dimensions date \
  --start-date 7daysAgo

Setup

1. Create OAuth credentials

Create an OAuth 2.0 Client ID in the Google Cloud Console:

  1. Go to APIs & Services > Credentials
  2. Click Create Credentials > OAuth client ID
  3. Choose Desktop app as the application type
  4. Download the JSON file

Make sure the following APIs are enabled in your GCP project:

  • Google Analytics Admin API
  • Google Analytics Data API

2. Configure client credentials

Copy the downloaded client_secret.json to the GA CLI config directory:

mkdir -p ~/.config/ga-cli
cp /path/to/client_secret.json ~/.config/ga-cli/client_secret.json

Alternatively, set environment variables:

export GA_CLI_CLIENT_ID="your-client-id"
export GA_CLI_CLIENT_SECRET="your-client-secret"

3. Authenticate

ga auth login

This opens your browser for Google OAuth consent and stores the token locally at ~/.config/ga-cli/credentials.json.

Service account (alternative)

ga auth login --service-account /path/to/key.json

Or set an environment variable:

export GA_CLI_SERVICE_ACCOUNT="/path/to/key.json"

Command Reference

Command Subcommands Description
ga auth login, logout, status Manage authentication
ga config setup, get, set, unset, path, reset Manage CLI configuration
ga accounts list, get, update List, inspect, and update GA4 accounts
ga account-summaries list Quick overview of all accounts and properties
ga properties list, get, create, update, delete Manage GA4 properties
ga custom-dimensions list, get, create, update, archive Manage custom dimensions
ga custom-metrics list, get, create, update, archive Manage custom metrics
ga data-streams list, get, create, update, delete Manage data streams
ga key-events list, get, create, update, delete Manage key events (conversions)
ga reports run, pivot, check-compatibility, metadata, realtime, build Run and build reports
ga upgrade --check, --force Check for and install updates
ga completions bash, zsh, fish Generate shell completion scripts

Use ga <command> --help for detailed usage of any command, or ga --describe for the full CLI schema as JSON.

Output formats

All read commands support --output (-o) to control output format:

ga accounts list --output json      # JSON output
ga accounts list --output table     # Table output (default)
ga accounts list --output compact   # Minimal ID + name output

Global Options

--help, -h      Show help
--version, -v   Show version
--quiet, -q     Suppress non-essential output
--no-color      Disable colored output
--describe      Show full CLI schema as JSON (for agents and tooling)

Shell Completions

ga completions bash > ~/.bash_completion.d/ga
ga completions zsh > ~/.zsh/completions/_ga
ga completions fish > ~/.config/fish/completions/ga.fish

Environment Variables

Variable Description
GA_CLI_SERVICE_ACCOUNT Path to service account key file
GOOGLE_APPLICATION_CREDENTIALS Standard GCP credential path (fallback)
GA_CLI_CONFIG_DIR Override config directory
GA_CLI_CLIENT_ID OAuth client ID (alternative to client_secret.json)
GA_CLI_CLIENT_SECRET OAuth client secret (alternative to client_secret.json)
NO_COLOR Disable colored output

CI/CD Integration

jobs:
  ga-report:
    runs-on: ubuntu-latest
    steps:
      - name: Install GA CLI
        run: pip install google-analytics-cli

      - name: Export daily report
        run: |
          echo '${{ secrets.GA_SERVICE_ACCOUNT_KEY }}' > /tmp/sa-key.json
          ga auth login --service-account /tmp/sa-key.json
          ga reports run -p ${{ vars.GA_PROPERTY_ID }} \
            --metrics sessions,users --dimensions date \
            --start-date 7daysAgo -o json > report.json
          rm /tmp/sa-key.json

Privacy

GA CLI stores authentication credentials locally on your machine. No data is sent to any third party — all communication is directly between your machine and Google's APIs.

Development

# Install with dev dependencies
uv sync

# Run the CLI
uv run ga --help

# Run tests
uv run pytest

# Lint
uv run ruff check src/ tests/

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

google_analytics_cli-0.1.0rc1.tar.gz (135.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

google_analytics_cli-0.1.0rc1-py3-none-any.whl (83.4 kB view details)

Uploaded Python 3

File details

Details for the file google_analytics_cli-0.1.0rc1.tar.gz.

File metadata

  • Download URL: google_analytics_cli-0.1.0rc1.tar.gz
  • Upload date:
  • Size: 135.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for google_analytics_cli-0.1.0rc1.tar.gz
Algorithm Hash digest
SHA256 290fb53c54d4bcc8e0cb87911168fcf2b0bbf9824b2f454c8dd06d34dff674bf
MD5 e5e1286b100041590bb1d8e8c8e49fc5
BLAKE2b-256 f661ae1763d2ff1dc7d8b6bb5babeb95839715e07ff766661820793e25dfcb9a

See more details on using hashes here.

File details

Details for the file google_analytics_cli-0.1.0rc1-py3-none-any.whl.

File metadata

  • Download URL: google_analytics_cli-0.1.0rc1-py3-none-any.whl
  • Upload date:
  • Size: 83.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for google_analytics_cli-0.1.0rc1-py3-none-any.whl
Algorithm Hash digest
SHA256 1c583205ac465296544efbfae2316f3b9e2564ffba86185ec3e560f56040b16f
MD5 b82a3ac1ae4224bc92f445ecab1edd42
BLAKE2b-256 7e4a70a070e016615d0d2555250e47dfa05751b3455120c8123c413c3ed99a39

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page