ai-referral-analysis
Measure traffic arriving from AI tools — ChatGPT, Claude, Perplexity, Gemini, Copilot, and others — and understand how it behaves…
The correct shape for `dimension_filter` in `get_ga4_data`. Wrong structure returns an \"Invalid dimension_filter\" error. Use these templates.
$ npx -y skills add surendranb/google-analytics-mcp --skill filter-structures --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
/filter-structuresContext preview
The summary Claude sees to decide when to auto-load this skill.
The correct shape for `dimension_filter` in `get_ga4_data`. Wrong structure returns an \"Invalid dimension_filter\" error. Use these templates.
name: filter-structures description: "The correct shape for `dimension_filter` in `get_ga4_data`. Wrong structure returns an \"Invalid dimension_filter\" error. Use these templates."
The correct shape for `dimension_filter` in `get_ga4_data`. Wrong structure returns an "Invalid dimension_filter" error. Use these templates.
Every leaf filter **must** be wrapped in a `"filter"` key. `fieldName` never appears at the top level.
// WRONG — fieldName at top level
{"fieldName": "sessionSource", "stringFilter": {"value": "google"}}
// CORRECT — wrapped in "filter"
{"filter": {"fieldName": "sessionSource", "stringFilter": {"value": "google"}}}{
"filter": {
"fieldName": "DIMENSION_NAME",
"stringFilter": {
"value": "VALUE",
"matchType": "EXACT"
}
}
}`matchType` options: `EXACT`, `BEGINS_WITH`, `ENDS_WITH`, `CONTAINS`, `FULL_REGEXP`, `PARTIAL_REGEXP`
{
"andGroup": {
"expressions": [
{"filter": {"fieldName": "deviceCategory", "stringFilter": {"value": "mobile", "matchType": "EXACT"}}},
{"filter": {"fieldName": "country", "stringFilter": {"value": "United States", "matchType": "EXACT"}}}
]
}
}{
"orGroup": {
"expressions": [
{"filter": {"fieldName": "sessionDefaultChannelGroup", "stringFilter": {"value": "Organic Search", "matchType": "EXACT"}}},
{"filter": {"fieldName": "sessionDefaultChannelGroup", "stringFilter": {"value": "Organic Social", "matchType": "EXACT"}}}
]
}
}{
"notExpression": {
"filter": {
"fieldName": "sessionDefaultChannelGroup",
"stringFilter": {"value": "Direct", "matchType": "EXACT"}
}
}
}{
"filter": {
"fieldName": "country",
"inListFilter": {
"values": ["United States", "United Kingdom", "Canada"]
}
}
}| Wrong key | Correct key | |---|---| | `and_filter` | `andGroup` | | `or_filter` | `orGroup` | | `not_filter` | `notExpression` | | `filters` | `expressions` | | `field` | `fieldName` | | `stringFilter.exact` | `stringFilter.value` |
> ⚠️ **CRITICAL FILTER TRAP**: Field names in `dimension_filter` (inside `fieldName`) MUST be exact camelCase. Passing `page_path` or `session_default_channel_group` will fail with an `Unknown field for FilterExpression` error.
| Wrong (snake_case) | Correct (camelCase) | |---|---| | `page_path` | `pagePath` | | `session_default_channel_group` | `sessionDefaultChannelGroup` | | `session_source` | `sessionSource` | | `session_source_medium` | `sessionSourceMedium` | | `session_campaign_name` | `sessionCampaignName` | | `landing_page` | `landingPage` | | `device_category` | `deviceCategory` | | `event_name` | `eventName` |
If you use snake_case in `fieldName`, the filter will fail with an "Unknown field" error. Do NOT retry snake_case.
Only dimensions can be filtered with `dimension_filter`. To filter on metric values (e.g. sessions > 100), you must do this in post-processing — the GA4 Data API does not support metric filters in `RunReport`.
Model Context Protocol (MCP) server for Google Analytics 4: real-time query exploration, schema discovery, metric aggregation, and audience insights for AI agents. 🌐 Live Documentation & Web Portal:
Measure traffic arriving from AI tools — ChatGPT, Claude, Perplexity, Gemini, Copilot, and others — and understand how it behaves…
GA4 has three distinct attribution scopes. Using the wrong scope gives misleading results. Choose based on the question you are…
Identify and exclude bot, scraper, and spam sessions from GA4 data.
Break down sessions and users by traffic source, medium, and channel group to understand where your audience comes from and which…
The correct GA4 Data API names for fields models most often get wrong. Use these before calling `get_ga4_data` — wrong names…
GA4 enforces strict rules about which dimensions and metrics can appear in the same request. Incompatible combinations return a…