CLI for Google Analytics
Project description
Google Analytics CLI (Experimental)
This repo contains a local CLI that interacts with the Google Analytics Admin and Data APIs.
Join the discussion and ask questions on Discord.
Commands 🛠️
The CLI uses the Google Analytics Admin API and Google Analytics Data API to provide a set of commands.
Retrieve account and property information 🟠
account-summaries: Retrieves information about the user's Google Analytics accounts and properties.property-details: Returns details about a property.google-ads-links: Returns a list of links to Google Ads accounts for a property.property-annotations: Returns annotations for a property.
Run core reports 📙
report: Runs a Google Analytics report using the Data API.custom-dimensions-metrics: Retrieves the custom dimensions and metrics for a specific property.
Run realtime reports ⏳
realtime-report: Runs a Google Analytics realtime report using the Data API.
Setup instructions 🔧
✨ Watch the Google Analytics CLI Setup Tutorial on YouTube for a step-by-step walkthrough of these instructions.
Setup involves the following steps:
- Configure Python.
- Configure credentials for Google Analytics.
- Add credentials to a
.envfile.
Configure Python 🐍
Enable APIs in your project ✅
Follow the instructions to enable the following APIs in your Google Cloud project:
Configure credentials 🔑
Configure your Application Default Credentials (ADC). Make sure the credentials are for a user with access to your Google Analytics accounts or properties.
Credentials must include the Google Analytics read-only scope:
https://www.googleapis.com/auth/analytics.readonly
Check out Manage OAuth Clients for how to create an OAuth client.
Here are some sample gcloud commands you might find useful:
-
Set up ADC using user credentials and an OAuth desktop or web client after downloading the client JSON to
YOUR_CLIENT_JSON_FILE.gcloud auth application-default login \ --scopes https://www.googleapis.com/auth/analytics.readonly,https://www.googleapis.com/auth/cloud-platform \ --client-id-file=YOUR_CLIENT_JSON_FILE
-
Set up ADC using service account impersonation.
gcloud auth application-default login \ --impersonate-service-account=SERVICE_ACCOUNT_EMAIL \ --scopes=https://www.googleapis.com/auth/analytics.readonly,https://www.googleapis.com/auth/cloud-platform
When the gcloud auth application-default command completes, copy the
PATH_TO_CREDENTIALS_JSON file location printed to the console in the
following message. You'll need this for the next step!
Credentials saved to file: [PATH_TO_CREDENTIALS_JSON]
Configure .env
Copy .env.example to .env in the project root (or in your current working
directory), and set the path to your credentials JSON:
GOOGLE_APPLICATION_CREDENTIALS=/absolute/path/to/credentials.json
GOOGLE_PROJECT_ID=your-project-id
Try it out 🥼
Install and run:
pip install -e .
analytics-cli --help
Examples:
-
List account summaries:
analytics-cli account-summaries -
Get property details:
analytics-cli property-details 123456789
-
Run a core report:
analytics-cli report 123456789 \ --date-ranges '[{"start_date":"7daysAgo","end_date":"yesterday"}]' \ --dimension eventName \ --metric eventCount
-
Run a realtime report:
analytics-cli realtime-report 123456789 \ --dimension country \ --metric activeUsers
Contributing ✨
Contributions welcome! See the Contributing Guide.
Project details
Release history Release notifications | RSS feed
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 analytics_cli-0.1.1.tar.gz.
File metadata
- Download URL: analytics_cli-0.1.1.tar.gz
- Upload date:
- Size: 17.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"NixOS","version":"25.11","id":"xantusia","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30101a3fb3c87a5f9c68526747731da88ebe057682b5f9076287f1e3166eb8eb
|
|
| MD5 |
b2cfd541bee471db98e2fc3b5a3a3220
|
|
| BLAKE2b-256 |
2ea67fea790662483f37bf599dfd59d036f79f161b042086806d33ddf0632c00
|
File details
Details for the file analytics_cli-0.1.1-py3-none-any.whl.
File metadata
- Download URL: analytics_cli-0.1.1-py3-none-any.whl
- Upload date:
- Size: 22.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"NixOS","version":"25.11","id":"xantusia","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a0072639bbf91289cd2dca5846efd417f5dc0fc8c759e1ed1253c0b38730bc1c
|
|
| MD5 |
5f89047ab36c4b1400410927a6258784
|
|
| BLAKE2b-256 |
06700da478f8e5d608495782fd7b7af20b598a56beb409b58775d08305ca2b76
|