← 返回
未分类 Key 中文

Google-analytics-GA4

Query Google Analytics GA4 properties for realtime and historical user metrics, dimensions, and metadata using the official Data API.
通过官方 Data API 查询 Google Analytics GA4 属性的实时及历史用户指标、维度和元数据。
whosc whosc 来源
未分类 clawhub v1.0.0 1 版本 100000 Key: 需要
★ 1
Stars
📥 491
下载
💾 8
安装
1
版本
#latest

概述

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

  1. Open Google Cloud Console.
  2. Create or select a project.
  3. Enable Google Analytics Data API.
  4. Create a service account: IAM & AdminService AccountsCreate service account.
    • Optional GCP role: BigQuery Job User (only if you also use BigQuery).
  5. Finish the wizard.

2. Create a JSON key

  1. Open the service account → Keys.
  2. Add keyCreate new keyJSON.
  3. Download the file and save it as ga-credentials.json (or any path you pass via --credentials / GOOGLE_APPLICATION_CREDENTIALS).

3. Grant GA4 access

  1. Open Google Analytics.
  2. Select the property.
  3. Admin (gear) → Property access management.
  4. Add users → enter the service account email (…@….iam.gserviceaccount.com).
  5. Role: at least Viewer.

4. Credentials location

Either:

  • A. Place ga-credentials.json in this skill directory, or
  • B. Set GOOGLE_APPLICATION_CREDENTIALS to 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

ArgumentDescriptionDefault
--------------------------------
--property-idNumeric GA4 property IDRequired (except list-properties)
--credentialsService account JSON pathga-credentials.json

Realtime

ArgumentDescriptionDefault
--------------------------------
--metricsComma-separated metricsactiveUsers
--dimensionsComma-separated dimensions(none)
--minute-rangeMinutes ago window, e.g. 0-300-30

Historical

ArgumentDescriptionDefault
--------------------------------
--start-dateStart (YYYY-MM-DD or relative)Required
--end-dateEndRequired
--metricsComma-separated metricsactiveUsers
--dimensionsComma-separated dimensions(none)
--limitMax rows10000
--offsetPaging offset0

Common metrics

NameMeaning
------------------------------------------------------------
activeUsersActive users
sessionsSessions
eventCountEvent count
engagementRateEngagement rate
averageSessionDurationAvg session duration (seconds)
screenPageViewsPage / screen views
conversionsConversions
totalRevenueRevenue

Common dimensions

NameMeaning
---------------
countryCountry
cityCity
deviceCategorydesktop / mobile / tablet
eventNameEvent name
pagePathPage path
sourceTraffic source
mediumMedium
campaignCampaign
dateDate

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

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-03-31 00:20 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

data-analysis

Stock Watcher

robin797860
管理和监控个人股票自选列表,支持利用同花顺数据添加、删除、列出股票及汇总近期表现。适用于用户希望追踪特定股票、获取表现汇总或管理自选列表时。
★ 112 📥 46,035
data-analysis

AdMapix

fly0pants
AdMapix 原始数据层,提供广告创意、应用、排名、下载/收入及市场元数据。返回 AdMapix API 的结构化 JSON;调用方...
★ 296 📥 139,595
data-analysis

Tavily 搜索

jacky1n7
通过 Tavily API 进行网页搜索(Brave 替代方案)。当用户要求搜索网页、查找来源或链接,且 Brave 网页搜索不可用时使用。
★ 273 📥 100,205