/google-analytics-mcp:filter-structuresfrom google-analytics-mcp
Provides copy-paste filter templates for the GA4 Data API: exact match, beginsWith, contains, regex, AND/OR group expressions, and inListFilter structures.
Ships in google-analytics-mcp. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
The Google Analytics 4 Data API requires structured FilterExpression objects for dimension_filter. It does not accept raw SQL, plain strings, or unnested JSON.
Use these copy-paste templates to construct valid filters for exact matches, string containment, regular expressions, and boolean logic.
Every leaf filter must be nested inside a "filter" key. fieldName cannot appear at the top level of the JSON object.
// ❌ WRONG — fieldName at top level causes validation error:
{"fieldName": "sessionSource", "stringFilter": {"value": "google"}}
// ✔️ CORRECT — leaf filter wrapped inside "filter":
{"filter": {"fieldName": "sessionSource", "stringFilter": {"value": "google", "matchType": "EXACT"}}}
{
"filter": {
"fieldName": "sessionDefaultChannelGroup",
"stringFilter": {
"matchType": "EXACT",
"value": "Organic Search"
}
}
}
{
"filter": {
"fieldName": "pagePath",
"stringFilter": {
"matchType": "CONTAINS",
"value": "/blog/"
}
}
}
{
"filter": {
"fieldName": "sessionSource",
"stringFilter": {
"matchType": "PARTIAL_REGEXP",
"value": "chatgpt\\.com|perplexity\\.ai|claude\\.ai"
}
}
}
Allowed matchType values: EXACT, BEGINS_WITH, ENDS_WITH, CONTAINS, FULL_REGEXP, PARTIAL_REGEXP.
{
"andGroup": {
"expressions": [
{
"filter": {
"fieldName": "deviceCategory",
"stringFilter": {"matchType": "EXACT", "value": "mobile"}
}
},
{
"filter": {
"fieldName": "country",
"stringFilter": {"matchType": "EXACT", "value": "United States"}
}
}
]
}
}
{
"orGroup": {
"expressions": [
{
"filter": {
"fieldName": "sessionDefaultChannelGroup",
"stringFilter": {"matchType": "EXACT", "value": "Organic Search"}
}
},
{
"filter": {
"fieldName": "sessionDefaultChannelGroup",
"stringFilter": {"matchType": "EXACT", "value": "Organic Social"}
}
}
]
}
}
{
"notExpression": {
"filter": {
"fieldName": "sessionDefaultChannelGroup",
"stringFilter": {"matchType": "EXACT", "value": "Direct"}
}
}
}
Instead of nesting multiple OR expressions, use inListFilter to match against a collection of strings:
{
"filter": {
"fieldName": "country",
"inListFilter": {
"values": ["United States", "United Kingdom", "Canada", "Germany"]
}
}
}
| Invalid Key (Common Guess) | Valid GA4 Data API Key |
|---|---|
and_filter | andGroup |
or_filter | orGroup |
not_filter | notExpression |
filters | expressions |
field | fieldName |
stringFilter.exact | stringFilter.value with matchType: "EXACT" |
⚠️ Field Casing: Values inside
fieldNamemust be strictly camelCase (e.g.sessionDefaultChannelGroup,pagePath,landingPage). Snake_case values will be rejected with anUnknown field for FilterExpressionerror.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub surendranb/google-analytics-mcp --plugin google-analytics-mcp17 skills in this plugin
/ai-referral-analysisHow to track and measure traffic from ChatGPT, Claude, Perplexity, and Gemini in GA4. Exact dimension filters, regex patterns, and channel comparison rules./attribution-scopeWhy session, user, and event metrics never match in GA4. Rules for pairing dimensions and metrics across user-scoped, session-scoped, and event-scoped models./bot-traffic-detectionDetect and filter automated bot spikes in Google Analytics 4. Patterns for datacenter ASN spikes, zero-second sessions, and single-page screenPageViews./channel-acquisitionHow GA4 Default Channel Groups work, how to audit channel performance, and how to spot traffic falling into Unassigned or Direct due to broken UTM parameters./common-metric-namesExact API field names for GA4 Data API queries. Avoid 400 errors from Universal Analytics names like ga:sessions or pageviews by using valid GA4 schema./compatible-combinationsWhich dimensions and metrics can be queried together in GA4 without triggering incompatible scope errors. Matrix of user, session, and event-level pairings.Other plugins' skills for the same job