Skip to main content
Glama
ZLeventer

Google Analytics MCP Server

ga4_realtime_active_users

Retrieve real-time active users from the last 30 minutes, broken down by page, country, device, or audience, to monitor current engagement.

Instructions

Current active users (last 30 min) broken down by screen/page, country, device, or audience.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
property_idNoOverride GA4_PROPERTY_ID env var for this call
breakdownNoDimension to break active users down byunifiedScreenName
limitNo

Implementation Reference

  • The main handler function `realtimeActiveUsers` that calls the GA4 Realtime API, runs a realtime report with a breakdown dimension and activeUsers metric, then maps results into rows with rowCount.
    export async function realtimeActiveUsers(args: z.infer<z.ZodObject<typeof realtimeSchema>>) {
      const [res] = await getClient().runRealtimeReport({
        property: getProperty(args.property_id),
        dimensions: [{ name: args.breakdown }],
        metrics: [{ name: "activeUsers" }],
        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 };
    }
  • Schema definition `realtimeSchema` with property_id (optional), breakdown (enum of unifiedScreenName/country/deviceCategory/audienceName, default unifiedScreenName), and limit (positive int, max 1000, default 25).
    export const realtimeSchema = {
      property_id: z.string().optional().describe("Override GA4_PROPERTY_ID env var for this call"),
      breakdown: z
        .enum(["unifiedScreenName", "country", "deviceCategory", "audienceName"])
        .default("unifiedScreenName")
        .describe("Dimension to break active users down by"),
      limit: z.number().int().positive().max(1000).default(25),
    };
  • src/index.ts:127-134 (registration)
    Registration of the tool named 'ga4_realtime_active_users' using server.tool() with description, schema, and handler callback.
    server.tool(
      "ga4_realtime_active_users",
      "Current active users (last 30 min) broken down by screen/page, country, device, or audience.",
      realtimeSchema,
      async (args) => {
        try { return ok(await realtimeActiveUsers(args)); } catch (e) { return err(e); }
      }
    );
Behavior3/5

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

With no annotations, the description bears full burden. It states the time window (last 30 min) and breakdown options, but does not disclose output format, authentication needs, rate limits, or that it returns only one metric. Adequate but lacking depth.

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

Conciseness4/5

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

The description is a single 18-word sentence that conveys the core functionality efficiently. No unnecessary words, but could be slightly front-loaded with the action verb.

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

Completeness2/5

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

The description does not explain the return format (e.g., list of dimension-value pairs with count), nor does it contextualize the tool among siblings for realtime vs historical data. Given no output schema, more detail is needed.

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 coverage is 67% (property_id and breakdown described, limit not). The description adds value by explaining the breakdown concept and listing example dimensions, but does not detail property_id's override behavior or the limit parameter's purpose. Partially compensates.

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 retrieves current active users in the last 30 minutes, with explicit breakdown options (screen/page, country, device, or audience). This distinguishes it from sibling tools that focus on historical performance reports.

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 provides no guidance on when to use this tool versus alternatives like ga4_run_report or ga4_channel_performance. It does not mention that this is for realtime data while others cover longer time ranges.

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