GA CLI - Google Analytics Command Line Interface
A command-line interface tool for managing Google Analytics 4 properties, accounts, and data streams.
Note: The package is published as ga4-cli on PyPI, but the command is ga-cli.
Features
- List and manage Google Analytics accounts
- Create and manage GA4 properties
- Manage data streams and retrieve measurement IDs
- Beautiful table output with Rich
- JSON output support
- Authentication via service account credentials
Installation
Using pip
pip install ga4-cli
After installation, the command is available as ga-cli:
ga-cli --version
ga-cli --help
Using pipx (recommended for a global command)
pipx install ga4-cli
Using Docker (build locally)
docker build -t ga-cli .
# Run with credentials mounted
docker run -v /path/to/credentials.json:/credentials.json \
-v ~/.ga-cli:/root/.ga-cli \
ga-cli accounts list --credentials /credentials.json
Download Binary (No Python Required)
Download standalone binaries from GitHub Releases:
| File | Platform |
|---|---|
ga-cli-linux-amd64.tar.gz |
Linux x86_64 |
ga-cli-macos-arm64.tar.gz |
macOS Apple Silicon |
ga-cli-macos-amd64.tar.gz |
macOS Intel |
ga-cli-windows-amd64.exe.zip |
Windows x86_64 |
Linux/macOS:
# Pick the file for your platform from the table above
curl -L -o ga-cli.tar.gz https://github.com/sulimanbenhalim/ga-cli/releases/latest/download/ga-cli-macos-arm64.tar.gz
tar -xzf ga-cli.tar.gz
chmod +x ga-cli
sudo mv ga-cli /usr/local/bin/
Windows:
Download ga-cli-windows-amd64.exe.zip from the releases page, extract, and run.
From source
git clone https://github.com/sulimanbenhalim/ga-cli.git
cd ga-cli
pip install -e .
Setup
1. Get Google Service Account Credentials
- Go to Google Cloud Console
- Create or select a project
- Enable the Google Analytics Admin API
- Create a service account
- Download the JSON credentials file
- In Google Analytics, go to Admin > Account access management, click +, and add the service account's email (the
client_emailvalue in the JSON file) with the Editor role
2. Initialize GA CLI
ga-cli config init
This will prompt you for the path to your service account JSON file, test the credentials, and save the path. If you have not done step 6 yet, it prints the exact email to add and you can carry on afterwards without running init again.
Alternatively, set the environment variable:
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/credentials.json
Usage
Configuration
# Initialize with credentials
ga-cli config init
# Show current configuration
ga-cli config show
Accounts
# List all accounts
ga-cli accounts list
# Get account details
ga-cli accounts get <account-id>
# Output as JSON
ga-cli accounts list --format json
Properties
# List properties for an account
ga-cli properties list <account-id>
# Get property details
ga-cli properties get <property-id>
# Create a new property
ga-cli properties create <account-id> --name "My Website" --timezone "America/New_York" --currency "USD"
# Move a property to the trash (restorable from the GA Admin UI until purged)
ga-cli properties delete <property-id>
Data Streams
# List data streams for a property
ga-cli datastreams list <property-id>
# Get data stream details (including measurement ID)
ga-cli datastreams get <property-id> <stream-id>
# Create a new web data stream
ga-cli datastreams create <property-id> --name "Main Website" --url "https://example.com"
Examples
Quick workflow to create a new GA4 property
# 1. List your accounts to get the account ID
ga-cli accounts list
# 2. Create a new property
ga-cli properties create 123456789 --name "BOTCHA" --timezone "Africa/Tripoli"
# 3. Create a web data stream
ga-cli datastreams create 987654321 --name "BOTCHA Website" --url "https://botcha.example.com"
# 4. Get the measurement ID
ga-cli datastreams get 987654321 111222333
Get measurement ID quickly
# If you know your property and stream IDs
ga-cli datastreams get <property-id> <stream-id> | grep "Measurement ID"
Command Reference
Global Options
--credentials PATH- Path to service account credentials file--version- Show version--help- Show help message
Output Formats
Most list and get commands support:
--format table(default) - Beautiful table output--format json- JSON output
Development
Setup development environment
# Clone the repository
git clone https://github.com/sulimanbenhalim/ga-cli.git
cd ga-cli
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install in development mode
pip install -e .
Run tests
pytest tests/ -v
Project Structure
ga-cli/
├── ga_cli/
│ ├── __init__.py
│ ├── cli.py # Main CLI entry point
│ ├── auth.py # Authentication manager
│ ├── config.py # Configuration manager
│ ├── commands/
│ │ ├── accounts.py # Account commands
│ │ ├── properties.py # Property commands
│ │ ├── datastreams.py # Data stream commands
│ │ └── config.py # Config commands
│ └── formatters/
│ ├── table.py # Table formatter
│ └── json.py # JSON formatter
├── tests/
├── setup.py
├── requirements.txt
└── README.md
Requirements
- Python 3.10+
- Click 8.0+
- google-analytics-admin 0.27.0+
- google-auth 2.0+
- rich 13.0+ (up to 15.x)
- pytz 2023.3+
License
MIT License
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Support
For issues and questions, please open an issue on GitHub.
Release files for ga4-cli 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ga4_cli-0.2.0.tar.gz | 20.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ga4_cli-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 49.0 kB
Release files / ga4_cli-0.2.0.tar.gz
| Download URL | ga4_cli-0.2.0.tar.gz |
|---|---|
| Size | 20.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4a2036744405891398dd66801b06cda6f74ae2d9bdd368f9723be1f56c0e95c9
|
|
BLAKE2b-256 checksum How to use checksums |
dd128863c07e88cd2b01a26692d5a748d01b68ae22a57428a449940752fd6564
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 13, 2026.
Transparency logRelease files / ga4_cli-0.2.0-py3-none-any.whl
| Download URL | ga4_cli-0.2.0-py3-none-any.whl |
|---|---|
| Size | 28.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a2a0da9df037d61df6bc7d7e9d2bb4973f352fb76efbff21ba7adc0ccefba947
|
|
BLAKE2b-256 checksum How to use checksums |
ac90e0346d43767f04896a932fbaa9a3918d206a3afe56c2ae732a2b5e5e987a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 13, 2026.
Transparency log