ai-referral-analysis
How to track and measure traffic from ChatGPT, Claude, Perplexity, and Gemini in GA4. Exact dimension filters, regex patterns,…
Copy-paste filter templates for the GA4 Data API: exact match, beginsWith, contains, regex, AND/OR group expressions, and inListFilter structures.
Claude Code
$ npx -y skills add surendranb/google-analytics-mcp --skill filter-structures --agent claude-code
Codex
$ npx skills add surendranb/google-analytics-mcp --skill filter-structures -a codex -y
Cursor
$ npx skills add surendranb/google-analytics-mcp --skill filter-structures -a cursor -y
Gemini CLI
$ npx skills add surendranb/google-analytics-mcp --skill filter-structures -a gemini-cli -y
GitHub Copilot
$ npx skills add surendranb/google-analytics-mcp --skill filter-structures -a github-copilot -y
OpenCode
$ npx skills add surendranb/google-analytics-mcp --skill filter-structures -a opencode -y
Windsurf
$ npx skills add surendranb/google-analytics-mcp --skill filter-structures -a windsurf -y
name: filter-structures titleTag: "GA4 API Filter Expressions & Dimension Regex Syntax" description: "Copy-paste filter templates for the GA4 Data API: exact match, beginsWith, contains, regex, AND/OR group expressions, and inListFilter structures."
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 `fieldName` must be strictly **camelCase** (e.g. `sessionDefaultChannelGroup`, `pagePath`, `landingPage`). Snake_case values will be rejected with an `Unknown field for FilterExpression` error.
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:
How to track and measure traffic from ChatGPT, Claude, Perplexity, and Gemini in GA4. Exact dimension filters, regex patterns,…
Why session, user, and event metrics never match in GA4. Rules for pairing dimensions and metrics across user-scoped,…
Detect and filter automated bot spikes in Google Analytics 4. Patterns for datacenter ASN spikes, zero-second sessions, and…
How GA4 Default Channel Groups work, how to audit channel performance, and how to spot traffic falling into Unassigned or Direct…
Exact API field names for GA4 Data API queries. Avoid 400 errors from Universal Analytics names like ga:sessions or pageviews by…
Which dimensions and metrics can be queried together in GA4 without triggering incompatible scope errors. Matrix of user,…
Use this skill when the user requests to review, analyze, critique, or summarize academic papers, research articles, preprints,…
Research what people actually say about any topic in the last 30 days. Pulls posts and engagement from Reddit, X, YouTube,…
Estimates intracellular metabolic fluxes from steady-state carbon-13 isotope-tracing measurements using validated atom maps,…
Search literature across sources, verify or manage citations, and build MeSH strategies or citation-impact audits. Use for…