Command-line interface for Google Analytics 4
Project description
GA CLI - Google Analytics Command Line Interface
A command-line interface tool for managing Google Analytics 4 properties, accounts, and data streams.
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
From source
cd ga-cli
pip install -e .
Using pip (when published)
pip install ga-cli
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 with Analytics Admin permissions
- Download the JSON credentials file
2. Initialize GA CLI
ga-cli config init
This will prompt you for the path to your service account JSON file and test the credentials.
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"
# Delete a property
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 <repository-url>
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.7+
- Click 8.0+
- google-analytics-admin 0.27.0+
- google-auth 2.0+
- rich 13.0+
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.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ga4_cli-0.1.0.tar.gz.
File metadata
- Download URL: ga4_cli-0.1.0.tar.gz
- Upload date:
- Size: 16.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a7a9d60a92487050ed405776f688c6841cd184c5e5af0d95459b91c5125d8495
|
|
| MD5 |
f73936b7157bf07a8fdc5c7986cf2438
|
|
| BLAKE2b-256 |
dd55fe60133f220ff31795e00046e7a8cd868334af17ec0bc37b0dc0083e7536
|
File details
Details for the file ga4_cli-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ga4_cli-0.1.0-py3-none-any.whl
- Upload date:
- Size: 23.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
99bf6594ea06ad531763e988a0381734d0a7fba3121dbe8f156d910998d7a0fa
|
|
| MD5 |
86523a54ad7f7275653c1dc45e5cde02
|
|
| BLAKE2b-256 |
4b33d8c71e0d7b03b529ca5bed16ff40b31c4557e22e4a867ddbf1963521238b
|