Google Analytics 技能:管理媒体资源与数据报表 - Openclaw Skills
作者:互联网
2026-04-07
什么是 Google Analytics?
Google Analytics 技能提供了一个与 Google Analytics Admin API 和 Data API 交互的流线型界面。通过利用 Maton 网关,开发者可以绕过手动处理 OAuth 的复杂性,直接管理账号、媒体资源和数据流。对于希望自动化报告工作流程或通过编程方式配置 GA4 环境而无需担心令牌管理开销的开发者来说,此 Openclaw Skills 集成至关重要。
该技能专为现代分析栈构建,仅支持 GA4 媒体资源。它允许在管理任务(如创建自定义维度)和分析任务(如运行实时报告)之间进行无缝切换。通过将其集成到您的 Openclaw Skills 库中,您可以获得一个专业级的驱动数据自动化的工具。
下载入口:https://github.com/openclaw/skills/tree/main/skills/rich-song/google-analytics-api
安装与下载
1. ClawHub CLI
从源直接安装技能的最快方式。
npx clawhub@latest install google-analytics-api
2. 手动安装
将技能文件夹复制到以下位置之一
全局模式~/.openclaw/skills/
工作区
/skills/
优先级:工作区 > 本地 > 内置
3. 提示词安装
将此提示词复制到 OpenClaw 即可自动安装。
请帮我使用 Clawhub 安装 google-analytics-api。如果尚未安装 Clawhub,请先安装(npm i -g clawhub)。
Google Analytics 应用场景
- 为新客户项目自动化创建和配置 GA4 媒体资源。
- 针对会话、用户和转化自动生成每周性能报告。
- 监控实时活跃用户数以触发警报或仪表板更新。
- 在多个账号中扩展自定义维度和转化事件的管理。
- 将网站流量数据直接集成到自定义商业智能工具中。
- 用户提供 Maton API 密钥,通过安全网关授权请求。
- 通过简单的 POST 请求为 Admin API 或 Data API 建立托管 OAuth 连接。
- 网关将传入的请求代理到官方 Google Analytics 端点(analyticsadmin.googleapis.com 或 analyticsdata.googleapis.com)。
- 系统自动在请求头中注入正确的 OAuth 令牌,静默处理刷新周期。
- Google 返回结构化的 JSON 响应,允许立即进行处理或可视化。
Google Analytics 配置指南
要开始使用此技能,请将您的 Maton API 密钥设置为环境变量并建立连接。
# 设置您的 API 密钥
export MATON_API_KEY="YOUR_API_KEY"
# 创建 Admin API 连接
curl -s -X POST "https://ctrl.maton.ai/connections" r
-H "Content-Type: application/json" r
-H "Authorization: Bearer $MATON_API_KEY" r
-d '{"app": "google-analytics-admin"}'
运行命令后,在浏览器中打开提供的 URL 以授权您的 Google 账号。
Google Analytics 数据架构与分类体系
该技能通过两个主要 API 网关和一个连接管理层组织交互:
| 组件 | 端点基址 | 功能 |
|---|---|---|
| Admin API | /google-analytics-admin/v1beta/ |
管理账号、媒体资源和数据流 |
| Data API | /google-analytics-data/v1beta/ |
执行报告、实时查询和元数据检索 |
| Connections | https://ctrl.maton.ai/connections |
管理 OAuth 会话生命周期和多账号映射 |
name: google-analytics
description: |
Google Analytics API integration with managed OAuth. Manage accounts, properties, and data streams (Admin API). Run reports on sessions, users, page views, and conversions (Data API). Use this skill when users want to configure or query Google Analytics. For other third party apps, use the api-gateway skill (https://clawhub.ai/byungkyu/api-gateway).
compatibility: Requires network access and valid Maton API key
metadata:
author: maton
version: "1.0"
Google Analytics
Access Google Analytics with managed OAuth authentication. This skill covers both the Admin API (manage accounts, properties, data streams) and the Data API (run reports on metrics).
Quick Start
# List account summaries (Admin API)
curl -s -X GET "https://gateway.maton.ai/google-analytics-admin/v1beta/accountSummaries" -H "Authorization: Bearer $MATON_API_KEY"
# Run a report (Data API)
curl -s -X POST "https://gateway.maton.ai/google-analytics-data/v1beta/properties/{propertyId}:runReport" -H "Content-Type: application/json" -H "Authorization: Bearer $MATON_API_KEY" -d '{"dateRanges": [{"startDate": "30daysAgo", "endDate": "today"}], "dimensions": [{"name": "city"}], "metrics": [{"name": "activeUsers"}]}'
Base URLs
Admin API (manage accounts, properties, data streams):
https://gateway.maton.ai/google-analytics-admin/{native-api-path}
Data API (run reports):
https://gateway.maton.ai/google-analytics-data/{native-api-path}
Replace {native-api-path} with the actual Google Analytics API endpoint path. The gateway proxies requests to analyticsadmin.googleapis.com and analyticsdata.googleapis.com and automatically injects your OAuth token.
Authentication
All requests require the Maton API key in the Authorization header:
Authorization: Bearer $MATON_API_KEY
Environment Variable: Set your API key as MATON_API_KEY:
export MATON_API_KEY="YOUR_API_KEY"
Getting Your API Key
- Sign in or create an account at maton.ai
- Go to maton.ai/settings
- Copy your API key
Connection Management
Manage your Google OAuth connections at https://ctrl.maton.ai.
Important: The Admin API and Data API use separate connections:
google-analytics-admin- Required for Admin API endpoints (manage accounts, properties, data streams)google-analytics-data- Required for Data API endpoints (run reports)
Create the connection(s) you need based on which API you want to use.
List Connections
# List Admin API connections
curl -s -X GET "https://ctrl.maton.ai/connections?app=google-analytics-admin&status=ACTIVE" -H "Authorization: Bearer $MATON_API_KEY"
# List Data API connections
curl -s -X GET "https://ctrl.maton.ai/connections?app=google-analytics-data&status=ACTIVE" -H "Authorization: Bearer $MATON_API_KEY"
Create Connection
# Create Admin API connection (for managing accounts, properties, data streams)
curl -s -X POST "https://ctrl.maton.ai/connections" -H "Content-Type: application/json" -H "Authorization: Bearer $MATON_API_KEY" -d '{"app": "google-analytics-admin"}'
# Create Data API connection (for running reports)
curl -s -X POST "https://ctrl.maton.ai/connections" -H "Content-Type: application/json" -H "Authorization: Bearer $MATON_API_KEY" -d '{"app": "google-analytics-data"}'
Get Connection
curl -s -X GET "https://ctrl.maton.ai/connections/{connection_id}" -H "Authorization: Bearer $MATON_API_KEY"
Response:
{
"connection": {
"connection_id": "21fd90f9-5935-43cd-b6c8-bde9d915ca80",
"status": "ACTIVE",
"creation_time": "2025-12-08T07:20:53.488460Z",
"last_updated_time": "2026-01-31T20:03:32.593153Z",
"url": "https://connect.maton.ai/?session_token=...",
"app": "google-analytics-admin",
"metadata": {}
}
}
Open the returned url in a browser to complete OAuth authorization.
Delete Connection
curl -s -X DELETE "https://ctrl.maton.ai/connections/{connection_id}" -H "Authorization: Bearer $MATON_API_KEY"
Specifying Connection
If you have multiple Google Analytics connections, specify which one to use with the Maton-Connection header:
curl -s -X GET "https://gateway.maton.ai/google-analytics-admin/v1beta/accountSummaries" -H "Authorization: Bearer $MATON_API_KEY" -H "Maton-Connection: 21fd90f9-5935-43cd-b6c8-bde9d915ca80"
If omitted, the gateway uses the default (oldest) active connection.
Admin API Reference
Accounts
GET /google-analytics-admin/v1beta/accounts
GET /google-analytics-admin/v1beta/accounts/{accountId}
GET /google-analytics-admin/v1beta/accountSummaries
Properties
GET /google-analytics-admin/v1beta/properties?filter=parent:accounts/{accountId}
GET /google-analytics-admin/v1beta/properties/{propertyId}
Create Property
POST /google-analytics-admin/v1beta/properties
Content-Type: application/json
{
"parent": "accounts/{accountId}",
"displayName": "My New Property",
"timeZone": "America/Los_Angeles",
"currencyCode": "USD"
}
Data Streams
GET /google-analytics-admin/v1beta/properties/{propertyId}/dataStreams
Create Web Data Stream
POST /google-analytics-admin/v1beta/properties/{propertyId}/dataStreams
Content-Type: application/json
{
"type": "WEB_DATA_STREAM",
"displayName": "My Website",
"webStreamData": {"defaultUri": "https://example.com"}
}
Custom Dimensions
GET /google-analytics-admin/v1beta/properties/{propertyId}/customDimensions
Create Custom Dimension
POST /google-analytics-admin/v1beta/properties/{propertyId}/customDimensions
Content-Type: application/json
{
"parameterName": "user_type",
"displayName": "User Type",
"scope": "USER"
}
Conversion Events
GET /google-analytics-admin/v1beta/properties/{propertyId}/conversionEvents
POST /google-analytics-admin/v1beta/properties/{propertyId}/conversionEvents
Data API Reference
Run Report
POST /google-analytics-data/v1beta/properties/{propertyId}:runReport
Content-Type: application/json
{
"dateRanges": [{"startDate": "30daysAgo", "endDate": "today"}],
"dimensions": [{"name": "city"}],
"metrics": [{"name": "activeUsers"}]
}
Run Realtime Report
POST /google-analytics-data/v1beta/properties/{propertyId}:runRealtimeReport
Content-Type: application/json
{
"dimensions": [{"name": "country"}],
"metrics": [{"name": "activeUsers"}]
}
Batch Run Reports
POST /google-analytics-data/v1beta/properties/{propertyId}:batchRunReports
Content-Type: application/json
{
"requests": [
{
"dateRanges": [{"startDate": "7daysAgo", "endDate": "today"}],
"dimensions": [{"name": "country"}],
"metrics": [{"name": "sessions"}]
}
]
}
Get Metadata
GET /google-analytics-data/v1beta/properties/{propertyId}/metadata
Common Report Examples
Page Views by Page
{
"dateRanges": [{"startDate": "30daysAgo", "endDate": "today"}],
"dimensions": [{"name": "pagePath"}],
"metrics": [{"name": "screenPageViews"}],
"orderBys": [{"metric": {"metricName": "screenPageViews"}, "desc": true}],
"limit": 10
}
Users by Country
{
"dateRanges": [{"startDate": "30daysAgo", "endDate": "today"}],
"dimensions": [{"name": "country"}],
"metrics": [{"name": "activeUsers"}, {"name": "sessions"}]
}
Traffic Sources
{
"dateRanges": [{"startDate": "30daysAgo", "endDate": "today"}],
"dimensions": [{"name": "sessionSource"}, {"name": "sessionMedium"}],
"metrics": [{"name": "sessions"}, {"name": "conversions"}]
}
Common Dimensions
date,country,city,deviceCategorypagePath,pageTitle,landingPagesessionSource,sessionMedium,sessionCampaignName
Common Metrics
activeUsers,newUsers,sessionsscreenPageViews,bounceRate,averageSessionDurationconversions,eventCount
Date Formats
- Relative:
today,yesterday,7daysAgo,30daysAgo - Absolute:
2026-01-01
Code Examples
JavaScript
// List account summaries (Admin API)
const accounts = await fetch(
'https://gateway.maton.ai/google-analytics-admin/v1beta/accountSummaries',
{
headers: {
'Authorization': `Bearer ${process.env.MATON_API_KEY}`
}
}
);
// Run a report (Data API)
const report = await fetch(
'https://gateway.maton.ai/google-analytics-data/v1beta/properties/123456:runReport',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${process.env.MATON_API_KEY}`
},
body: JSON.stringify({
dateRanges: [{ startDate: '30daysAgo', endDate: 'today' }],
dimensions: [{ name: 'country' }],
metrics: [{ name: 'activeUsers' }]
})
}
);
Python
import os
import requests
# List account summaries (Admin API)
accounts = requests.get(
'https://gateway.maton.ai/google-analytics-admin/v1beta/accountSummaries',
headers={'Authorization': f'Bearer {os.environ["MATON_API_KEY"]}'}
)
# Run a report (Data API)
report = requests.post(
'https://gateway.maton.ai/google-analytics-data/v1beta/properties/123456:runReport',
headers={'Authorization': f'Bearer {os.environ["MATON_API_KEY"]}'},
json={
'dateRanges': [{'startDate': '30daysAgo', 'endDate': 'today'}],
'dimensions': [{'name': 'country'}],
'metrics': [{'name': 'activeUsers'}]
}
)
Notes
- GA4 properties only (Universal Analytics not supported)
- Property IDs are numeric (e.g.,
properties/521310447) - Use
accountSummariesto quickly list all accessible properties - Use
updateMaskfor PATCH requests in Admin API - Use metadata endpoint to discover available dimensions/metrics
- IMPORTANT: When using curl commands, use
curl -gwhen URLs contain brackets (fields[],sort[],records[]) to disable glob parsing - IMPORTANT: When piping curl output to
jqor other commands, environment variables like$MATON_API_KEYmay not expand correctly in some shell environments. You may get "Invalid API key" errors when piping.
Error Handling
| Status | Meaning |
|---|---|
| 400 | Missing Google Analytics connection |
| 401 | Invalid or missing Maton API key |
| 429 | Rate limited (10 req/sec per account) |
| 4xx/5xx | Passthrough error from Google Analytics API |
Resources
- Admin API Overview
- Accounts
- Properties
- Data Streams
- Data API Overview
- Run Report
- Realtime Report
相关推荐
专题
+ 收藏
+ 收藏
+ 收藏
+ 收藏
+ 收藏
+ 收藏
最新数据
相关文章
Git 统计:分析仓库速率与活跃度 - Openclaw Skills
Hotjar: 用户行为分析与热力图 API - Openclaw Skills
GraphQL TypeScript 生成器:自动化模式类型生成 - Openclaw Skills
AI 重构助手:自动化代码质量优化 - Openclaw Skills
AI 架构提议者:自动化系统设计 - Openclaw Skills
Excel:自动化表格数据与分析 - Openclaw Skills
eBay Trading API 技能:自动化卡片与收藏品刊登 - Openclaw Skills
客户管理器:终极自由职业 CRM - Openclaw Skills
热狗还是非热狗:AI 视觉食物分类 - Openclaw Skills
Trends CLI:在 Solana 上发行和交易 Memecoin - Openclaw Skills
AI精选
「JS全栈AI Agent学习」六、当AI遇到矛盾,该自己决定还是问你?—— Human-in-the-Loop
工程师眼中的Prompt提示词
从零创建 skill:Skill Creator 项目全解析
Claude降智再被实锤!推理能力严重下滑,用户连夜跑路 Codex
OpenClaw 教程:新 Mac 从 0 配到国产 AI、飞书微信和无人值守
Mac 本地部署 Ollama 并运行 Gemma 4 模型
MCP (Model Context Protocol) 原理与实战
LLM应用的“外挂大脑”:Embedding、向量数据库与RAG
