/install google-analytics-ga4
Google Analytics skill
Query GA4 properties using the Google Analytics Data API v1.
Capabilities
- Realtime metrics — e.g. active users in the last N minutes
- Historical reports — custom date ranges, metrics, dimensions, paging
- Metadata — discover valid dimension and metric API names
- Property list hint — Data API alone cannot enumerate properties; doc explains where to find the numeric ID
Setup
1. Create a service account
- Open Google Cloud Console.
- Create or select a project.
- Enable Google Analytics Data API.
- Create a service account: IAM & Admin → Service Accounts → Create service account.
- Optional GCP role: BigQuery Job User (only if you also use BigQuery).
- Finish the wizard.
2. Create a JSON key
- Open the service account → Keys.
- Add key → Create new key → JSON.
- Download the file and save it as
ga-credentials.json(or any path you pass via--credentials/GOOGLE_APPLICATION_CREDENTIALS).
3. Grant GA4 access
- Open Google Analytics.
- Select the property.
- Admin (gear) → Property access management.
- Add users → enter the service account email (
…@….iam.gserviceaccount.com). - Role: at least Viewer.
4. Credentials location
Either:
- A. Place
ga-credentials.jsonin this skill directory, or - B. Set
GOOGLE_APPLICATION_CREDENTIALSto the absolute path of the JSON key.
Never commit real keys. .gitignore excludes ga-credentials.json and config.json.
Examples
Property list guidance
python ga_query.py --action list-properties
Realtime (active users)
python ga_query.py --action realtime \
--property-id YOUR-GA4-PROPERTY-ID
Historical
python ga_query.py --action historical \
--property-id YOUR-GA4-PROPERTY-ID \
--start-date 7daysAgo \
--end-date yesterday \
--metrics activeUsers,sessions,eventCount \
--dimensions country,deviceCategory
Metadata
python ga_query.py --action metadata \
--property-id YOUR-GA4-PROPERTY-ID
Arguments
Common
| Argument | Description | Default |
|---|---|---|
--property-id |
Numeric GA4 property ID | Required (except list-properties) |
--credentials |
Service account JSON path | ga-credentials.json |
Realtime
| Argument | Description | Default |
|---|---|---|
--metrics |
Comma-separated metrics | activeUsers |
--dimensions |
Comma-separated dimensions | (none) |
--minute-range |
Minutes ago window, e.g. 0-30 |
0-30 |
Historical
| Argument | Description | Default |
|---|---|---|
--start-date |
Start (YYYY-MM-DD or relative) |
Required |
--end-date |
End | Required |
--metrics |
Comma-separated metrics | activeUsers |
--dimensions |
Comma-separated dimensions | (none) |
--limit |
Max rows | 10000 |
--offset |
Paging offset | 0 |
Common metrics
| Name | Meaning |
|---|---|
activeUsers |
Active users |
sessions |
Sessions |
eventCount |
Event count |
engagementRate |
Engagement rate |
averageSessionDuration |
Avg session duration (seconds) |
screenPageViews |
Page / screen views |
conversions |
Conversions |
totalRevenue |
Revenue |
Common dimensions
| Name | Meaning |
|---|---|
country |
Country |
city |
City |
deviceCategory |
desktop / mobile / tablet |
eventName |
Event name |
pagePath |
Page path |
source |
Traffic source |
medium |
Medium |
campaign |
Campaign |
date |
Date |
Date expressions
- Absolute:
2024-01-15 - Relative:
today,yesterday,7daysAgo,30daysAgo
Output
Default: Markdown tables. Use --output json for machine-readable output.
Dependencies
pip install google-analytics-data
Optional (traffic source report + DingTalk): pip install requests and set DINGTALK_WEBHOOK / DINGTALK_SECRET.
References
- 确保已安装 OpenClaw(本地或 Docker 部署)
- 在对话框中输入安装命令:
/install google-analytics-ga4 - 安装完成后,直接呼叫该 Skill 的名称或使用
/google-analytics-ga4触发 - 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
Google-analytics-GA4 是什么?
Query Google Analytics GA4 properties for realtime and historical user metrics, dimensions, and metadata using the official Data API. 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 176 次。
如何安装 Google-analytics-GA4?
在 OpenClaw 或 Claude Code 对话框中运行命令「/install google-analytics-ga4」即可一键安装,无需额外配置。
Google-analytics-GA4 是免费的吗?
是的,Google-analytics-GA4 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。
Google-analytics-GA4 支持哪些平台?
Google-analytics-GA4 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。
谁开发了 Google-analytics-GA4?
由 whao(@whosc)开发并维护,当前版本 v1.0.0。