GA4 Analytics (MCP)
Query Google Analytics 4 data for any of your sites directly from the BlackOps MCP server. Credentials are stored per-site, encrypted at rest, and never leave the server.
What it does
The MCP server exposes five tools for pulling GA4 reports from any AI assistant connected to BlackOps (Claude, ChatGPT, etc). Each tool takes a domain argument matching a BlackOps site you own.
ga4_traffic_overview— sessions, users, pageviews, bounce rate, average session durationga4_top_pages— top pages ranked by pageviews with title, path, and time on pagega4_traffic_sources— source/medium/channel breakdownga4_trend— daily time-series for sessions, users, pageviews, or newUsersga4_site_comparison— side-by-side metrics for multiple sites in one call
Setup
1. Create a Google Cloud service account
- Open the Google Cloud service accounts page and create a new service account (any project will do).
- Enable the Google Analytics Data API for that project (APIs & Services → Library → search "Analytics Data API" → Enable).
- On the service account, generate a new JSON key and download it.
2. Grant the service account access to your GA4 property
- In Google Analytics, go to Admin → Property Access Management.
- Add the service account email (looks like
name@project.iam.gserviceaccount.com) with the Viewer role. - While in Admin → Property Settings, copy the numeric Property ID (e.g.
123456789). This is not theG-XXXXmeasurement ID.
3. Save credentials in BlackOps
- Go to Admin → Sites and open the site you want to enable.
- Open the Analytics tab. Find the "GA4 Data API (MCP)" card.
- Paste the numeric Property ID and the full service account JSON.
- Click Save GA4 Credentials.
Once saved, the badge changes to Configured. The JSON is encrypted with AES-256-GCM and is never sent back to the browser. To rotate, paste new JSON and save. To remove, click Clear.
Example chats
From any MCP-connected AI (Claude Code, Claude Desktop, ChatGPT with the BlackOps connector), just ask in natural language. The AI picks the right tool and arguments for you. A few real-world prompts to copy:
Quick health check
"How is benenewton.com doing this month?"
→ ga4_traffic_overview returns sessions, users, pageviews, bounce rate, and average session duration.
Find your best content
"What are the top 10 pages on benenewton.com over the last 90 days, sorted by pageviews?"
→ ga4_top_pages returns title, path, pageviews, sessions, and average time on page. Great for identifying which posts to expand into series, refresh, or cross-link.
Where is traffic coming from?
"Show me the top traffic sources for blackopscenter.com this month. Break it down by source, medium, and channel."
→ ga4_traffic_sources shows organic search vs direct vs referral splits. Useful for seeing whether new campaigns or social posts are actually driving sessions.
Spot trends over time
"Plot daily sessions for benenewton.com over the last 30 days."
"How are new users trending on blackopscenter.com over 90 days?"
→ ga4_trend returns a daily time-series for sessions, users, pageviews, or newUsers. Claude can chart it inline or call out spikes, dips, and patterns.
Compare sites side by side
"Compare traffic across benenewton.com, blackopscenter.com, and vitalwall.com for the last 7 days."
→ ga4_site_comparison runs all three in parallel and returns a single table. Sites without GA4 configured appear with ok: false and an error instead of failing the whole call.
Multi-step workflows
Because the tools return structured data, the AI can chain them with other BlackOps tools to do real work — not just summarize.
"Find my top 3 blog posts from the last 60 days on benenewton.com, then write a tweet thread that references each one with its URL."
"Look at last week's traffic sources for blackopscenter.com. If LinkedIn is in the top 5, draft a follow-up LinkedIn post about the most-viewed article."
"Compare this month vs last month for benenewton.com. Save the summary as a Brain note tagged 'analytics' so I can find it later."
These chain ga4_* with post_tweets, post_linkedin, post_notes, etc. — the analytics become an editorial signal, not just a dashboard read.
Calling tools directly
If you're scripting against the MCP yourself, the JSON-RPC arguments look like this:
{
"name": "ga4_traffic_overview",
"arguments": {
"domain": "benenewton.com",
"days": 28
}
}
{
"name": "ga4_site_comparison",
"arguments": {
"domains": ["benenewton.com", "blackopscenter.com"],
"days": 7
}
}How it works under the hood
When the MCP receives a ga4_* call, it:
- Calls
GET /api/v2/analytics/ga4-credentials?domain=…with the user's bearer token. - The endpoint validates the token, confirms the user owns the site, decrypts the stored ciphertext, and returns the property ID + service account JSON.
- The MCP constructs a Google Auth client with read-only Analytics scope and runs the requested report against the GA4 Data API.
- The Google client is cached per-domain for the MCP process lifetime. To pick up rotated credentials, restart the MCP server.
Troubleshooting
"GA4 not configured for this site"
Either the property ID or the service account JSON is missing in site settings. Both are required.
"Server cannot decrypt credentials"
The EXT_TOKEN_ENCRYPTION_KEY environment variable is not set on the BlackOps app. Contact the platform admin.
403 / permission errors from Google
The service account email needs Viewer access on the GA4 property (Admin → Property Access Management).
404 from Google
The Property ID is wrong. Use the numeric ID from Admin → Property Settings, not the G-XXXX measurement ID.