Skip to main content
Glama
ZLeventer

Google Analytics MCP Server

ga4_organic_search_performance

Retrieve organic search traffic metrics: sessions, users, engagement, and conversions. Break down results by landing page, source, country, or device for SEO analysis.

Instructions

SEO: sessions/users/engagement/conversions for Organic Search traffic, broken down by landing page (default), source, country, or device.

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
breakdownNoDimension to break organic traffic down bylandingPage

Implementation Reference

  • src/index.ts:55-62 (registration)
    Registration of the ga4_organic_search_performance tool via server.tool(), linking it to organicSearchSchema and the organicSearchPerformance handler.
    server.tool(
      "ga4_organic_search_performance",
      "SEO: sessions/users/engagement/conversions for Organic Search traffic, broken down by landing page (default), source, country, or device.",
      organicSearchSchema,
      async (args) => {
        try { return ok(await organicSearchPerformance(args)); } catch (e) { return err(e); }
      }
    );
  • Zod schema defining the input parameters for the organic search performance tool: start_date, end_date, property_id, limit, and breakdown (with enum options).
    export const organicSearchSchema = {
      start_date: z.string().default(DEFAULT_START).describe("Start date: YYYY-MM-DD, NdaysAgo, yesterday, or today"),
      end_date: z.string().default(DEFAULT_END).describe("End date: YYYY-MM-DD, NdaysAgo, yesterday, or today"),
      property_id: z.string().optional().describe("Override GA4_PROPERTY_ID env var for this call"),
      limit: z.number().int().positive().max(10000).default(50).describe("Max rows to return"),
      breakdown: z
        .enum(["landingPage", "sessionSource", "pagePath", "country", "deviceCategory"])
        .default("landingPage")
        .describe("Dimension to break organic traffic down by"),
    };
  • Main handler function that calls GA4 Data API runReport with Organic Search dimension filter, returning rows with dimension and metric values.
    export async function organicSearchPerformance(args: z.infer<z.ZodObject<typeof organicSearchSchema>>) {
      const [res] = await getClient().runReport({
        property: getProperty(args.property_id),
        dateRanges: [{ startDate: args.start_date, endDate: args.end_date }],
        dimensions: [{ name: args.breakdown }],
        metrics: [
          { name: "sessions" },
          { name: "totalUsers" },
          { name: "newUsers" },
          { name: "engagementRate" },
          { name: "averageSessionDuration" },
          { name: "conversions" },
          { name: "keyEvents" },
        ],
        dimensionFilter: {
          filter: {
            fieldName: "sessionDefaultChannelGroup",
            stringFilter: { value: "Organic Search" },
          },
        },
        orderBys: [{ metric: { metricName: "sessions" }, desc: true }],
        limit: args.limit as unknown as number,
      });
      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 };
    }
Behavior3/5

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

No annotations are provided, so the description must carry the burden. It describes what data is returned (metrics and breakdowns) but does not disclose behavioral traits such as rate limits, authentication requirements, or data freshness. For a reporting tool, it is adequate but not comprehensive.

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?

A single sentence front-loaded with key information: tool purpose, metrics, and breakdown options. No wasted words; efficient and scannable.

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

Completeness5/5

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

Given the schema fully describes parameters and no output schema is provided, the description sufficiently tells what the tool returns and how to break down the data. It is complete for a straightforward reporting tool with good sibling context.

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

Parameters4/5

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

The schema covers 100% of parameters with descriptions, but the description adds value by explaining the breakdown options and metrics in context. It clarifies that the default breakdown is landing page and lists the available dimensions, going beyond the schema's technical descriptions.

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 is for Organic Search traffic, listing key metrics (sessions, users, engagement, conversions) and breakdown dimensions. It uses 'SEO' as a prefix and 'Organic Search' to distinguish from paid or channel-specific tools among siblings.

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

Usage Guidelines4/5

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

The description implies usage for organic search performance analysis, but lacks explicit guidance on when to use vs alternatives like paid search or campaign tools. Sibling names provide context, but no direct exclusions or preconditions are stated.

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