# Google Analytics > Obtiene reportes GA4, datos de tráfico e insights desde la Google Analytics Data API: tráfico, comportamiento de usuarios, canales de adquisición, conversiones y segmentos de audiencia. Fuente: https://skillsagentes.com/skills/openclaudia/openclaudia-skills/google-analytics Markdown: https://skillsagentes.com/skills/openclaudia/openclaudia-skills/google-analytics.md Repositorio: https://github.com/OpenClaudia/openclaudia-skills Autor: OpenClaudia Licencia: MIT Actualizado: hace 7 meses Coste de contexto: 96 tok instalada, 2.7k tok al activarse, 2.7k tok con todos los archivos del bundle Bundle: 1 archivo, 11 KB Permisos que pide: ninguno declarado ## Instalación Un skill son archivos markdown: los mismos archivos valen para cualquier agente y lo único que cambia es el directorio de destino, es decir la bandera `--agent`. Añade `-g` para instalarlo en todos los proyectos de la máquina. ```bash # Claude Code npx -y skills add OpenClaudia/openclaudia-skills --skill google-analytics --agent claude-code # Cursor npx -y skills add OpenClaudia/openclaudia-skills --skill google-analytics --agent cursor # Codex npx -y skills add OpenClaudia/openclaudia-skills --skill google-analytics --agent codex # Gemini CLI npx -y skills add OpenClaudia/openclaudia-skills --skill google-analytics --agent gemini # Windsurf npx -y skills add OpenClaudia/openclaudia-skills --skill google-analytics --agent windsurf # Cline npx -y skills add OpenClaudia/openclaudia-skills --skill google-analytics --agent cline ``` ## Qué hace - Consulta la API de datos de Google Analytics (GA4) mediante peticiones POST a runReport - Genera reportes de tráfico, adquisición, páginas top, engagement, conversiones y segmentos de audiencia - Compara periodos de tiempo y calcula tendencias - Construye un reporte mensual estructurado con tablas y recomendaciones - Parsea la respuesta JSON de GA4 con python3 o jq ## Cuándo usarla - Se pregunta sobre tráfico del sitio web, comportamiento de usuarios o canales de adquisición - Se pide un reporte mensual de analytics - Se necesitan métricas de conversión, engagement o segmentos de audiencia ## Qué la activa - "Dame un reporte de tráfico de los últimos 30 días en GA4" - "¿Cuáles son mis canales de adquisición con más sesiones?" - "Muéstrame las páginas más visitadas del sitio" - "Compara las conversiones de este mes contra el anterior" - "Genera el reporte mensual de Google Analytics" ## Antes de instalar - Requiere credenciales OAuth de Google (GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET) y un access token válido de la API de Google Analytics. - Necesita en el PATH: curl, python3 - Variables de entorno: GA_ACCESS_TOKEN, GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET - makes network requests - needs API credentials ## Archivos - SKILL.md — 11 KB ## SKILL.md Reproducido tal cual desde OpenClaudia/openclaudia-skills bajo MIT. Esta sección es el documento original y está en inglés. # Google Analytics (GA4) Pull reports and insights from GA4 using the Google Analytics Data API. ## Prerequisites Requires Google OAuth credentials: - `GOOGLE_CLIENT_ID` - `GOOGLE_CLIENT_SECRET` - A valid OAuth access token (refreshed as needed) Set credentials in `.env`, `.env.local`, or `~/.claude/.env.global`. ### Getting an Access Token ```bash # Step 1: Get authorization code (user must visit this URL in browser) echo "https://accounts.google.com/o/oauth2/v2/auth?client_id=${GOOGLE_CLIENT_ID}&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=https://www.googleapis.com/auth/analytics.readonly&response_type=code&access_type=offline" # Step 2: Exchange code for tokens curl -s -X POST "https://oauth2.googleapis.com/token" \ -d "code={AUTH_CODE}" \ -d "client_id=${GOOGLE_CLIENT_ID}" \ -d "client_secret=${GOOGLE_CLIENT_SECRET}" \ -d "redirect_uri=urn:ietf:wg:oauth:2.0:oob" \ -d "grant_type=authorization_code" # Step 3: Refresh an expired token curl -s -X POST "https://oauth2.googleapis.com/token" \ -d "refresh_token={REFRESH_TOKEN}" \ -d "client_id=${GOOGLE_CLIENT_ID}" \ -d "client_secret=${GOOGLE_CLIENT_SECRET}" \ -d "grant_type=refresh_token" ``` Store the refresh token securely. The access token expires after 1 hour. ### Finding Your GA4 Property ID ```bash curl -s -H "Authorization: Bearer ${GA_ACCESS_TOKEN}" \ "https://analyticsadmin.googleapis.com/v1beta/accountSummaries" \ | python3 -c " import json, sys data = json.load(sys.stdin) for acct in data.get('accountSummaries', []): for prop in acct.get('propertySummaries', []): print(f\"{prop['property']} | {prop.get('displayName','')} | Account: {acct.get('displayName','')}\") " ``` The property ID format is `properties/XXXXXXXXX`. --- ## API Base ``` POST https://analyticsdata.googleapis.com/v1beta/{property_id}:runReport ``` All report requests use POST with a JSON body. Always include `Authorization: Bearer {ACCESS_TOKEN}`. --- ## 1. Traffic Overview Report Get sessions, users, page views, and engagement rate over a date range. ### Example curl ```bash curl -s -X POST \ "https://analyticsdata.googleapis.com/v1beta/properties/{PROPERTY_ID}:runReport" \ -H "Authorization: Bearer ${GA_ACCESS_TOKEN}" \ -H "Content-Type: application/json" \ -d '{ "dateRanges": [{"startDate": "30daysAgo", "endDate": "today"}], "metrics": [ {"name": "sessions"}, {"name": "totalUsers"}, {"name": "newUsers"}, {"name": "screenPageViews"}, {"name": "engagementRate"}, {"name": "averageSessionDuration"}, {"name": "bounceRate"} ] }' ``` ### Date Range Shortcuts - `today`, `yesterday` - `7daysAgo`, `14daysAgo`, `28daysAgo`, `30daysAgo`, `90daysAgo` - Specific dates: `2024-01-01` - Compare periods by passing two dateRanges --- ## 2. User Acquisition Report See where users come from (channels, sources, campaigns). ```bash curl -s -X POST \ "https://analyticsdata.googleapis.com/v1beta/properties/{PROPERTY_ID}:runReport" \ -H "Authorization: Bearer ${GA_ACCESS_TOKEN}" \ -H "Content-Type: application/json" \ -d '{ "dateRanges": [{"startDate": "30daysAgo", "endDate": "today"}], "dimensions": [ {"name": "sessionDefaultChannelGroup"} ], "metrics": [ {"name": "sessions"}, {"name": "totalUsers"}, {"name": "engagementRate"}, {"name": "conversions"} ], "orderBys": [{"metric": {"metricName": "sessions"}, "desc": true}], "limit": 20 }' ``` ### Useful Acquisition Dimensions | Dimension | Description | |-----------|-------------| | `sessionDefaultChannelGroup` | Channel grouping (Organic, Paid, Social, etc.) | | `sessionSource` | Traffic source (google, facebook, etc.) | | `sessionMedium` | Medium (organic, cpc, referral, etc.) | | `sessionCampaignName` | UTM campaign name | | `firstUserSource` | First-touch attribution source | --- ## 3. Top Pages Report Find the highest-traffic pages on the site. ```bash curl -s -X POST \ "https://analyticsdata.googleapis.com/v1beta/properties/{PROPERTY_ID}:runReport" \ -H "Authorization: Bearer ${GA_ACCESS_TOKEN}" \ -H "Content-Type: application/json" \ -d '{ "dateRanges": [{"startDate": "30daysAgo", "endDate": "today"}], "dimensions": [ {"name": "pagePath"} ], "metrics": [ {"name": "screenPageViews"}, {"name": "totalUsers"}, {"name": "engagementRate"}, {"name": "averageSessionDuration"} ], "orderBys": [{"metric": {"metricName": "screenPageViews"}, "desc": true}], "limit": 25 }' ``` --- ## 4. Engagement Metrics Understand how users interact with your content. ```bash curl -s -X POST \ "https://analyticsdata.googleapis.com/v1beta/properties/{PROPERTY_ID}:runReport" \ -H "Authorization: Bearer ${GA_ACCESS_TOKEN}" \ -H "Content-Type: application/json" \ -d '{ "dateRanges": [{"startDate": "30daysAgo", "endDate": "today"}], "dimensions": [ {"name": "pagePath"} ], "metrics": [ {"name": "engagedSessions"}, {"name": "engagementRate"}, {"name": "averageSessionDuration"}, {"name": "screenPageViewsPerSession"}, {"name": "eventCount"} ], "orderBys": [{"metric": {"metricName": "engagedSessions"}, "desc": true}], "limit": 20 }' ``` ### Key Engagement Metrics | Metric | What It Measures | |--------|-----------------| | `engagementRate` | % of sessions that were engaged (>10s, 2+ pages, or conversion) | | `averageSessionDuration` | Mean session length in seconds | | `screenPageViewsPerSession` | Pages per session | | `bounceRate` | % of sessions with no engagement | | `eventCount` | Total events fired | --- ## 5. Conversion Tracking Report on conversion events (purchases, signups, etc.). ```bash curl -s -X POST \ "https://analyticsdata.googleapis.com/v1beta/properties/{PROPERTY_ID}:runReport" \ -H "Authorization: Bearer ${GA_ACCESS_TOKEN}" \ -H "Content-Type: application/json" \ -d '{ "dateRanges": [{"startDate": "30daysAgo", "endDate": "today"}], "dimensions": [ {"name": "eventName"} ], "metrics": [ {"name": "eventCount"}, {"name": "totalUsers"}, {"name": "eventValue"} ], "dimensionFilter": { "filter": { "fieldName": "eventName", "inListFilter": { "values": ["purchase", "sign_up", "generate_lead", "begin_checkout"] } } } }' ``` ### Conversion by Channel ```bash curl -s -X POST \ "https://analyticsdata.googleapis.com/v1beta/properties/{PROPERTY_ID}:runReport" \ -H "Authorization: Bearer ${GA_ACCESS_TOKEN}" \ -H "Content-Type: application/json" \ -d '{ "dateRanges": [{"startDate": "30daysAgo", "endDate": "today"}], "dimensions": [ {"name": "sessionDefaultChannelGroup"} ], "metrics": [ {"name": "sessions"}, {"name": "conversions"}, {"name": "totalRevenue"} ], "orderBys": [{"metric": {"metricName": "conversions"}, "desc": true}] }' ``` --- ## 6. Audience Segments Break down traffic by device, geography, and demographics. ### By Device Category ```bash curl -s -X POST \ "https://analyticsdata.googleapis.com/v1beta/properties/{PROPERTY_ID}:runReport" \ -H "Authorization: Bearer ${GA_ACCESS_TOKEN}" \ -H "Content-Type: application/json" \ -d '{ "dateRanges": [{"startDate": "30daysAgo", "endDate": "today"}], "dimensions": [{"name": "deviceCategory"}], "metrics": [ {"name": "sessions"}, {"name": "totalUsers"}, {"name": "engagementRate"}, {"name": "conversions"} ] }' ``` ### By Country Replace `deviceCategory` with `country` in the dimensions. ### By Landing Page + Source ```bash curl -s -X POST \ "https://analyticsdata.googleapis.com/v1beta/properties/{PROPERTY_ID}:runReport" \ -H "Authorization: Bearer ${GA_ACCESS_TOKEN}" \ -H "Content-Type: application/json" \ -d '{ "dateRanges": [{"startDate": "30daysAgo", "endDate": "today"}], "dimensions": [ {"name": "landingPage"}, {"name": "sessionSource"} ], "metrics": [ {"name": "sessions"}, {"name": "engagementRate"}, {"name": "conversions"} ], "orderBys": [{"metric": {"metricName": "sessions"}, "desc": true}], "limit": 30 }' ``` --- ## 7. Period Comparison Compare two time periods to identify trends. ```bash curl -s -X POST \ "https://analyticsdata.googleapis.com/v1beta/properties/{PROPERTY_ID}:runReport" \ -H "Authorization: Bearer ${GA_ACCESS_TOKEN}" \ -H "Content-Type: application/json" \ -d '{ "dateRanges": [ {"startDate": "30daysAgo", "endDate": "today", "name": "current"}, {"startDate": "60daysAgo", "endDate": "31daysAgo", "name": "previous"} ], "metrics": [ {"name": "sessions"}, {"name": "totalUsers"}, {"name": "conversions"}, {"name": "engagementRate"} ] }' ``` --- ## Response Parsing GA4 API returns JSON. Parse with python3 or jq: ```bash # Parse report into a table curl -s -X POST "..." | python3 -c " import json, sys data = json.load(sys.stdin) headers = [h['name'] for h in data.get('dimensionHeaders',[])] + [m['name'] for m in data.get('metricHeaders',[])] print(' | '.join(headers)) print('-' * (len(headers) * 20)) for row in data.get('rows', []): dims = [d['value'] for d in row.get('dimensionValues',[])] mets = [m['value'] for m in row.get('metricValues',[])] print(' | '.join(dims + mets)) " ``` --- ## Workflow: Monthly Analytics Report When asked for a monthly report: 1. Pull traffic overview (sessions, users, page views) with period comparison 2. Pull acquisition breakdown by channel 3. Pull top 20 pages by page views 4. Pull conversion summary by channel 5. Pull device and country breakdown Present as a structured report with tables, trends (up/down arrows), and recommendations: ``` ## Monthly Analytics Report: {Property Name} ### Period: {date range} vs {previous period} ### Traffic Summary | Metric | Current | Previous | Change | |--------|---------|----------|--------| | Sessions | X | Y | +Z% | | ... ### Top Channels ... ### Top Pages ... ### Conversion Summary ... ### Recommendations - [Based on data patterns] ``` ## Common Issues - **403 Forbidden**: User lacks access to the GA4 property - **Empty rows**: No data for the requested date range or filters - **Quota exceeded**: GA4 API has daily quotas; reduce date ranges or batch requests - **Property not found**: Verify the property ID format (`properties/XXXXXXXXX`) ## Dónde encaja - Categoría: [Datos y analítica](https://skillsagentes.com/categorias/datos-analitica.md) — Consulta, limpia y visualiza datos sin salir del agente. - Creador: [OpenClaudia](https://skillsagentes.com/creators/openclaudia.md) — 76 skills en el directorio - [Todas las skills](https://skillsagentes.com/skills.md) - [Ranking de instalaciones](https://skillsagentes.com/ranking.md) ## Otras skills del mismo repositorio - [Competitor Traffic Report](https://skillsagentes.com/skills/openclaudia/openclaudia-skills/competitor-traffic-report.md): Genera un informe HTML autocontenible de tráfico competitivo: visitas mensuales (SimilarWeb), tráfico orgánico y Domain Rating (Ahrefs), con gráficos ranked, tendencias y tabla de datos. - [Brand Dev](https://skillsagentes.com/skills/openclaudia/openclaudia-skills/brand-dev.md): Obtiene datos de marca (nombre, descripción, logos, industria) desde la API de brand.dev y guarda los logos localmente. - [Gsc Portfolio Audit](https://skillsagentes.com/skills/openclaudia/openclaudia-skills/gsc-portfolio-audit.md): Audita TODAS las propiedades de Google Search Console a la vez: ranking por clics e impresiones con deltas, y diff de keywords por sitio (nuevas, suben, bajan, perdidas, o bien rankeadas sin clics). - [Wechat Moments](https://skillsagentes.com/skills/openclaudia/openclaudia-skills/wechat-moments.md): Clasifica y resume el feed de WeChat Moments (朋友圈) del usuario para que los eventos reales y la información genuina destaquen sobre la promoción, ponderando según cuánto le escribe el usuario a cada autor. - [Podcast Edit](https://skillsagentes.com/skills/openclaudia/openclaudia-skills/podcast-edit.md): Edita audio o video de podcast: recorta charla previa/posterior, quita muletillas, corta silencios, mejora el audio y aplica el mismo corte a una versión en video. --- Skills Agentes · [Índice de páginas en markdown](https://skillsagentes.com/sitemap.md) · [Inicio](https://skillsagentes.com/index.md)