Business operating system for Claude Code — 57 skills, 21 agents, smart daemon. Unified inbox (WhatsApp/Email/Slack/Telegram), autonomous PR merge, full-AWS monitoring, revenue (Stripe+RevenueCat), e-commerce (Shopify), marketing (Klaviyo/Meta/GA4), voice (Bland/ElevenLabs), APM (Datadog/NewRelic/OTEL), YOLO mode.
phase: "13-ga4" plan: "01" subsystem: ops-marketing tags: [ga4, google-analytics, realtime, funnel, cohort, audience, pivot, data-api] dependency_graph: requires: [] provides: [ga4-realtime, ga4-funnel, ga4-cohort, ga4-audience, ga4-pivot] affects: [ops-marketing/SKILL.md]
Phase 13 Plan 01: GA4 Advanced Analytics
Goal
Extend ops-marketing/SKILL.md with five advanced GA4 Data API sub-commands beyond the existing basic ga4 overview: realtime active users + top pages/events, open/closed conversion funnels with completion/abandonment rates, weekly retention cohort grid by device category, async audience creation with status polling, and multi-dimensional channel × device × conversions pivot table.
Requirements Addressed
GA4-01throughGA4-05: Advanced analytics surface beyond basic session/user counts
Runtime Prerequisites
STOP — the following credentials must be configured before this plan can execute:
| Credential | Where to get it |
|---|---|
GA4_PROPERTY_ID |
GA4 Admin → Property Settings → Property ID (numeric, e.g. 123456789) |
GA4_SERVICE_ACCOUNT_KEY |
Google Cloud Console → IAM → Service Accounts → create key (JSON format) for a service account granted Viewer role on the GA4 property; path stored in preferences.json as analytics.ga4.service_account_key_path |
Alternative credential: OAuth2 user token with analytics.readonly scope (same pattern as Google Ads OAuth — can reuse setup wizard pattern from Phase 10).
API access note: GA4 Data API v1beta is GA (stable). The v1alpha runFunnelReport and createAudienceExport endpoints are in Alpha — they require whitelisting for production. Document this limitation in the funnel and audience sub-commands.
Deliverables
Files to Modify
claude-ops/skills/ops-marketing/SKILL.md— extend existing## ga4section with 5 new sub-command routes (realtime, funnel, cohort, audience, pivot); add authentication preamble for service account JWT flow
Task Breakdown
Task 0: GA4 Authentication Preamble
File: claude-ops/skills/ops-marketing/SKILL.md → ## ga4 section preamble
Add service account JWT authentication (or fall through to OAuth token if already set):
GA4_PROPERTY_ID="${ga4_property_id:-${GA4_PROPERTY_ID:-}}"
GA4_KEY_PATH="${ga4_service_account_key_path:-${GOOGLE_APPLICATION_CREDENTIALS:-}}"
if [ -n "$GA4_ACCESS_TOKEN" ]; then
: # already set (e.g. OAuth path)
elif [ -n "$GA4_KEY_PATH" ] && [ -f "$GA4_KEY_PATH" ]; then
# Service account: generate JWT → exchange for access token
GA4_ACCESS_TOKEN=$(python3 -c "
import json, time, base64, hashlib, hmac, urllib.request, urllib.parse
# ... JWT generation using RS256 from key file
# scope: https://www.googleapis.com/auth/analytics.readonly
" 2>/dev/null)
fi
Credential guard: if GA4_PROPERTY_ID or GA4_ACCESS_TOKEN empty, print setup hint and stop.
Extended routing table:
| Input | Action |
|---|---|
| (existing) overview / (empty) | Basic sessions, users, conversions |
| realtime | Active users (last 30 min) + top pages/events |
| funnel <EVENT1,EVENT2,...> | Open funnel with completion + abandonment rates |
| cohort [weeks] | Weekly retention cohort grid by device |
| audience <AUDIENCE_NAME> | Create audience export + poll status |
| pivot | Channel × device × conversions pivot |
Task 1: Realtime Sub-command
File: claude-ops/skills/ops-marketing/SKILL.md → ## ga4 section
POST to https://analyticsdata.googleapis.com/v1beta/properties/{GA4_PROPERTY_ID}:runRealtimeReport:
{
"dimensions": [{"name": "unifiedPagePathScreen"}],
"metrics": [{"name": "activeUsers"}],
"minuteRanges": [{"name": "last30min", "startMinutesAgo": 30, "endMinutesAgo": 0}],
"limit": 10
}
Second call for top events (same minuteRange, dimension eventName, metric eventCount, limit 10).
Output:
══ REALTIME — Active Users Last 30 Min ══
Active Users: 247
Top Pages:
/pricing 89 users
/docs 45 users
...
Top Events:
page_view 312
scroll 198
...
Task 2: Funnel Sub-command
File: claude-ops/skills/ops-marketing/SKILL.md → ## ga4 section
Collect funnel steps via AskUserQuestion (comma-separated GA4 event names, e.g. session_start,view_item,add_to_cart,purchase).
POST to https://analyticsdata.googleapis.com/v1alpha/properties/{GA4_PROPERTY_ID}:runFunnelReport:
{
"dateRanges": [{"startDate": "30daysAgo", "endDate": "today"}],
"funnelDefinition": {
"steps": [
{"name": "Step 1", "filterExpression": {"funnelEventFilter": {"eventName": "session_start"}}},
...
]
}
}
Output: per-step table showing users, completion rate vs. previous step, abandonment rate.
══ FUNNEL ANALYSIS — Last 30 Days ══
Step Users Completion Abandonment
session_start 45,231 — —
view_item 12,890 28.5% 71.5%
add_to_cart 3,412 7.5% 73.5%
purchase 891 2.0% 73.9%
Alpha API note: print warning if v1alpha returns 403 — link to GA4 alpha whitelist request.
Task 3: Cohort Retention Sub-command
File: claude-ops/skills/ops-marketing/SKILL.md → ## ga4 section
AskUserQuestion: number of weeks (default 6).
POST to /v1beta/properties/{GA4_PROPERTY_ID}:runReport with cohort spec:
{
"cohortSpec": {
"cohorts": [/* one per week for last N weeks */],
"cohortsRange": {"granularity": "WEEKLY", "startOffset": 0, "endOffset": N},
"cohortReportSettings": {"accumulate": false}
},
"dimensions": [
{"name": "cohort"},
{"name": "cohortNthWeek"},
{"name": "deviceCategory"}
],
"metrics": [{"name": "cohortActiveUsers"}, {"name": "cohortTotalUsers"}]
}
Render weekly retention grid:
══ WEEKLY RETENTION COHORT ══
Cohort (Week) W0 W1 W2 W3 W4
2026-W01 100% 28.3% 18.1% 12.4% 9.2%
2026-W02 100% 31.2% 19.8% 13.1% —
...
Task 4: Audience Export Sub-command
File: claude-ops/skills/ops-marketing/SKILL.md → ## ga4 section
AskUserQuestion: audience name or numeric audience ID, dimension for export (e.g. city, deviceCategory).
If the user supplies a name (not numeric ID), resolve it first: GET https://analyticsadmin.googleapis.com/v1beta/properties/{GA4_PROPERTY_ID}/audiences and match displayName → numeric <AUDIENCE_ID>; if multiple matches, AskUserQuestion to disambiguate; if user supplies a numeric ID directly, use it as <AUDIENCE_ID>.
POST to https://analyticsdata.googleapis.com/v1alpha/properties/{GA4_PROPERTY_ID}/audienceExports:
{
"audience": "properties/{GA4_PROPERTY_ID}/audiences/<AUDIENCE_ID>",
"dimensions": [{"dimensionName": "<dimension>"}]
}
Poll audienceExports/{exportId}:query until state == "ACTIVE" (max 12 polls, 5s intervals). Once active, run query and display row count + sample rows.
Print note: Audience Export requires an audience to already exist in GA4 Admin. Document how to get audience IDs.
Task 5: Pivot Sub-command
File: claude-ops/skills/ops-marketing/SKILL.md → ## ga4 section
POST to /v1beta/properties/{GA4_PROPERTY_ID}:runPivotReport:
{
"dateRanges": [{"startDate": "30daysAgo", "endDate": "today"}],
"dimensions": [
{"name": "sessionDefaultChannelGrouping"},
{"name": "deviceCategory"}
],
"metrics": [
{"name": "sessions"},
{"name": "conversions"},
{"name": "totalRevenue"}
],
"pivots": [
{"fieldNames": ["sessionDefaultChannelGrouping"], "limit": 6},
{"fieldNames": ["deviceCategory"], "limit": 3}
]
}
Render as cross-tab table with channel rows × device columns, showing conversions per cell:
══ PIVOT: Channel × Device × Conversions ══
Channel Desktop Mobile Tablet Total
Organic Search 1,234 891 123 2,248
Paid Search 456 312 45 813
Direct 234 567 34 835
...
Threat Model
| ID | Threat | Mitigation |
|---|---|---|
| T-13-01-01 | Service account key file on disk | Mitigated — path stored in prefs, file is user-owned; never committed; document backup exclusion |
| T-13-01-02 | v1alpha endpoints deprecated without notice | Documented — funnel and audience print alpha warning; note GA4 stable alternatives where available |
| T-13-01-03 | Cohort query on large properties may timeout | Mitigated — GA4 API has built-in 10-minute quota; no additional mitigation needed |
| T-13-01-04 | Audience export reveals user cohort info in terminal | Accepted — aggregate data only; no individual user PII; local terminal |
Dependencies
- Requires: GA4 credentials configured (service account key or OAuth token); GA4 property with data
- Provides:
ga4-realtime,ga4-funnel,ga4-cohort,ga4-audience,ga4-pivot
Success Criteria (Self-Check)
-
grep "runRealtimeReport" claude-ops/skills/ops-marketing/SKILL.md— PASS -
grep "runFunnelReport" claude-ops/skills/ops-marketing/SKILL.md— PASS -
grep "cohortNthWeek" claude-ops/skills/ops-marketing/SKILL.md— PASS -
grep "audienceExports" claude-ops/skills/ops-marketing/SKILL.md— PASS -
grep "runPivotReport" claude-ops/skills/ops-marketing/SKILL.md— PASS -
grep "v1alpha" claude-ops/skills/ops-marketing/SKILL.md— PASS (alpha warning documented) -
grep "GA4_PROPERTY_ID" claude-ops/skills/ops-marketing/SKILL.mdreturns ≥ 5