ai-referral-analysis
How to track and measure traffic from ChatGPT, Claude, Perplexity, and Gemini in GA4. Exact dimension filters, regex patterns,β¦
Mapping table from Universal Analytics (UA) field names to Google Analytics 4 (GA4) Data API names. Replace ga:pageviews, ga:bounces, and ga:users correctly.
Claude Code
$ npx -y skills add surendranb/google-analytics-mcp --skill ua-to-ga4 --agent claude-code
Codex
$ npx skills add surendranb/google-analytics-mcp --skill ua-to-ga4 -a codex -y
Cursor
$ npx skills add surendranb/google-analytics-mcp --skill ua-to-ga4 -a cursor -y
Gemini CLI
$ npx skills add surendranb/google-analytics-mcp --skill ua-to-ga4 -a gemini-cli -y
GitHub Copilot
$ npx skills add surendranb/google-analytics-mcp --skill ua-to-ga4 -a github-copilot -y
OpenCode
$ npx skills add surendranb/google-analytics-mcp --skill ua-to-ga4 -a opencode -y
Windsurf
$ npx skills add surendranb/google-analytics-mcp --skill ua-to-ga4 -a windsurf -y
name: ua-to-ga4 titleTag: "Universal Analytics to GA4 Field Name Mapping" description: "Mapping table from Universal Analytics (UA) field names to Google Analytics 4 (GA4) Data API names. Replace ga:pageviews, ga:bounces, and ga:users correctly."
Universal Analytics (UA) was sunset on July 1, 2023. Language models trained on legacy documentation frequently guess deprecated UA field names (e.g., `ga:sessions`, `pageviews`, `uniquePageviews`, `conversions`) that cause hard 400 validation errors in the Google Analytics 4 Data API.
Additionally, on May 6, 2024, Google officially renamed **conversions** to **key events** across GA4. Use this mapping table to translate legacy dimensions and metrics into their valid GA4 Data API equivalents.
| Legacy UA Name (Invalid) | GA4 Data API Name (Valid) | Type | Notes | |---|---|---|---| | `users` | `totalUsers` or `activeUsers` | Metric | `activeUsers` is GA4's primary user metric | | `pageviews` | `screenPageViews` | Metric | Total pages viewed across web and app | | `uniquePageviews` | `screenPageViews` | Metric | GA4 does not track unique views; use sessions per page | | `avgSessionDuration` | `averageSessionDuration` | Metric | Average duration in seconds | | `timeOnPage` / `avgTimeOnPage` | `userEngagementDuration` | Metric | Total engagement time in seconds | | `conversions` / `goalCompletionsAll` | `keyEvents` | Metric | Renamed from conversions on May 6, 2024 | | `conversionRate` / `sessionConversionRate` | `sessionKeyEventRate` | Metric | Percentage of sessions with a key event | | `userConversionRate` | `userKeyEventRate` | Metric | Percentage of users who triggered a key event | | `transactions` / `purchases` | `ecommercePurchases` | Metric | Number of completed e-commerce purchases | | `transactionRevenue` / `revenue` | `purchaseRevenue` | Metric | Total purchase revenue | | `revenuePerTransaction` | `averagePurchaseRevenue` | Metric | Average purchase revenue per transaction | | `itemQuantity` | `itemsViewed` or `itemsPurchased` | Metric | Specify viewed or purchased | | `entrances` | `sessions` | Metric | Use session count with landingPage | | `bounces` | `bounceRate` | Metric | GA4 calculates bounce rate as (1 - engagementRate) |
| Legacy UA Name (Invalid) | GA4 Data API Name (Valid) | Scope | Notes | |---|---|---|---| | `channelGrouping` | `sessionDefaultChannelGroup` | Session | Organic Search, Direct, Paid, Referral | | `source` | `sessionSource` | Session | Domain or entity driving the session | | `medium` | `sessionMedium` | Session | organic, cpc, referral, email | | `sourceMedium` | `sessionSourceMedium` | Session | Combined source / medium | | `campaign` | `sessionCampaignName` | Session | UTM campaign name | | `keyword` | `sessionManualTerm` | Session | UTM term | | `landingPagePath` | `landingPage` | Event | Landing page path without query parameters | | `pagePath` | `pagePath` | Event | Page path including directories | | `pageTitle` | `pageTitle` | Event | Page HTML title tag | | `deviceCategory` | `deviceCategory` | Event | desktop, mobile, tablet | | `operatingSystem` | `operatingSystem` | Event | iOS, Android, Windows, Macintosh | | `browser` | `browser` | Event | Chrome, Safari, Firefox, Edge | | `country` | `country` | Event | Full country name | | `city` | `city` | Event | Full city name | | `userType` | `newVsReturning` | User | 'new' or 'returning' |
All GA4 Data API field names are strictly **camelCase**. Using snake_case will cause an invalid field error.
| Wrong (snake_case) | Correct (camelCase) | |---|---| | `page_path` | `pagePath` | | `session_source` | `sessionSource` | | `device_category` | `deviceCategory` | | `event_name` | `eventName` | | `total_users` | `totalUsers` | | `screen_page_views` | `screenPageViews` |
GA4 splits attribution into three distinct scopes: 1. **Session Scope (`session*`)**: Attributes the visit (e.g., `sessionSource`, `sessionMedium`). Use for traffic acquisition. 2. **First User Scope (`firstUser*`)**: Attributes the person across their lifetime (e.g., `firstUserSource`). Use for user acquisition. 3. **Event Scope (no prefix)**: Attributes the specific action (e.g., `pagePath`, `eventName`). Use for page and event analytics.
Never mix user-scoped dimensions with session-scoped metrics in the same query. Consult the [Compatible Combinations Guide](/skills/compatible-combinations/) for valid groupings.
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β¦