Skip to main content
Glama
ZLeventer

Google Analytics MCP Server

ga4_conversions_by_source

Retrieve conversions and key events by session source, medium, and channel group. Sorted by key events descending to identify top channels for performance analysis.

Instructions

Conversions and key events broken down by session source × medium × channel group. Sorted by key events desc.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
start_dateNoStart date: YYYY-MM-DD, NdaysAgo, yesterday, or today28daysAgo
end_dateNoEnd date: YYYY-MM-DD, NdaysAgo, yesterday, or todayyesterday
property_idNoOverride GA4_PROPERTY_ID env var for this call
limitNoMax rows to return

Implementation Reference

  • Handler function that queries GA4 for conversions by session source/medium/channel group, sorted by key events descending.
    export async function conversionsBySource(args: z.infer<z.ZodObject<typeof conversionsBySourceSchema>>) {
      const [res] = await getClient().runReport({
        property: getProperty(args.property_id),
        dateRanges: toDateRange(args.start_date, args.end_date),
        dimensions: [
          { name: "sessionSource" },
          { name: "sessionMedium" },
          { name: "sessionDefaultChannelGroup" },
        ],
        metrics: [
          { name: "sessions" },
          { name: "conversions" },
          { name: "keyEvents" },
          { name: "totalRevenue" },
        ],
        orderBys: [{ metric: { metricName: "keyEvents" }, desc: true }],
        limit: args.limit as unknown as number,
      });
      return formatReport(res);
    }
  • Schema definition (spread of dateRange which includes start_date, end_date, property_id, limit).
    export const conversionsBySourceSchema = { ...dateRange };
  • src/index.ts:118-125 (registration)
    Registration of the tool with the MCP server under the name 'ga4_conversions_by_source'.
    server.tool(
      "ga4_conversions_by_source",
      "Conversions and key events broken down by session source × medium × channel group. Sorted by key events desc.",
      conversionsBySourceSchema,
      async (args) => {
        try { return ok(await conversionsBySource(args)); } catch (e) { return err(e); }
      }
    );
  • Helper to convert date strings to GA4 date range objects.
    function toDateRange(start_date: string, end_date: string) {
      return [{ startDate: start_date, endDate: end_date }];
    }
  • Helper to format GA4 report response into row-based structure.
    function formatReport(res: any) {
      const rows = (res.rows ?? []).map((r: any) => {
        const out: Record<string, string | number> = {};
        (res.dimensionHeaders ?? []).forEach((h: any, i: number) => {
          out[h.name] = r.dimensionValues?.[i]?.value ?? "";
        });
        (res.metricHeaders ?? []).forEach((h: any, i: number) => {
          const v = r.metricValues?.[i]?.value ?? "0";
          const n = Number(v);
          out[h.name] = Number.isFinite(n) ? n : v;
        });
        return out;
      });
      return { rowCount: res.rowCount ?? rows.length, rows };
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description must disclose behavioral traits. It only states the output and sorting, but does not mention idempotency, auth needs, rate limits, or data freshness. The agent cannot infer safety or operational constraints.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise with two sentences. The first sentence delivers the key purpose upfront, and the second adds sorting detail. No superfluous information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The tool returns a report but has no output schema. The description gives a high-level idea of the output dimensions but lacks specifics like response format, column names, or whether it includes date range. Given the complexity of GA4 reports, this is mildly insufficient.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all parameters. The description adds no additional parameter details (e.g., meaning of 'key events', date range constraints). Baseline score of 3 is appropriate as the description does not improve parameter understanding.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: it breaks down conversions and key events by session source, medium, and channel group, and sorts by key events descending. This distinguishes it from sibling tools that focus on specific channels or campaigns (e.g., ga4_channel_performance, ga4_campaign_performance).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description does not provide guidance on when to use this tool versus alternatives. It lacks explicit context about when this breakdown is appropriate or when to prefer sibling tools like ga4_all_paid_performance or ga4_organic_search_performance. No when-not or prerequisite info is given.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ZLeventer/google-analytics-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server