SuperAPI AI 工具集

pp-google-analytics

数据与分析

查看项目

更新于 10-16 01:32

技能介绍

用途:在智能体需要 GA4 实时数据时使用本 CLI,涵盖获客与收入摘要、电商诊断、漏斗、周期对比、异常扫描和媒体资源访问诊断。Search Console 由 google-search-console-pp-cli 负责,不应使用旧的 GSC/GA4 合并 CLI。

安装与验证:先确认 google-analytics-pp-cli 已安装。安装命令为 npx -y @mvanhorn/printing-press-library install google-analytics --cli-only --bin-dir ~/.local/bin,随后用 google-analytics-pp-cli --version 验证,并确保 ~/.local/bin 在 $PATH 中。若 npx 失败,可用 Go 1.26.6 以上版本执行 go install github.com/mvanhorn/printing-press-library/library/marketing/google-analytics/cmd/google-analytics-pp-cli@latest,安装到 $GOPATH/bin。若 --version 报 command not found,说明运行时看不到该目录,验证成功前不要继续执行技能命令。

认证与属性:服务账号密钥用 --credentials,或设置 GOOGLE_APPLICATION_CREDENTIALS;权限范围为 https://www.googleapis.com/auth/analytics.readonly;属性用 --property 或设置 GA4_PROPERTY_ID;批量健康检查用 health --properties $GA4_PROPERTY_IDS --agent 或设置 GA4_PROPERTY_IDS。注意 Google Cloud API 访问权限不等于 GA4 属性权限,服务账号必须在 GA4 属性内被授予 Viewer 权限;若健康检查显示 token/admin 正常但属性检查返回 403/404,应修复 GA4 属性授权而非轮换凭据。

常用命令:agent-context --agent、health --properties $GA4_PROPERTY_IDS --agent、channels --property "$GA4_PROPERTY_ID" --start 28daysAgo --end yesterday --agent、sources、top-pages、compare --metric sessions,totalRevenue --period wow、whats-changed、revenue --by channel、funnel --steps view_item,add_to_cart,begin_checkout,purchase,均带 --property 和 --agent。低层逃生口提供 report、pivot、batch、realtime、metadata、compatibility、properties、property、streams,回答业务问题时应优先使用上述专用命令。

限制:仅面向 GA4;使用前须验证 CLI 与 PATH;需正确配置服务账号及属性权限;资料未提供收费、价格或具体效果数据。