Skip to main content
Glama
Shin-sibainu

GA4 MCP Server

by Shin-sibainu

get_traffic_summary

Retrieve Google Analytics 4 traffic summaries including page views, users, sessions, and bounce rates for specified periods to monitor website performance.

Instructions

指定期間のトラフィック概要(PV数、ユーザー数、セッション数、直帰率など)を取得します。ダッシュボード的な使い方に最適です。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
propertyIdNoGA4プロパティID
periodYes集計期間

Implementation Reference

  • The main handler function that executes the get_traffic_summary tool. It queries GA4 for key traffic metrics using executeReport and formats them into a summary output including page views, users, sessions, bounce rate, etc.
    export async function getTrafficSummary(
      input: GetTrafficSummaryInput
    ): Promise<TrafficSummaryOutput> {
      const propertyId = getPropertyId(input.propertyId);
      const property = formatPropertyPath(propertyId);
      const dateRange = periodToDateRange(input.period);
    
      const response = await executeReport({
        property,
        dateRanges: [dateRange],
        metrics: [
          { name: "screenPageViews" },
          { name: "totalUsers" },
          { name: "sessions" },
          { name: "newUsers" },
          { name: "averageSessionDuration" },
          { name: "bounceRate" },
          { name: "engagementRate" },
          { name: "screenPageViewsPerSession" },
        ],
      });
    
      // 結果からメトリクス値を取得
      const metricValues = response.totals?.[0]?.metricValues || [];
      const getValue = (index: number): number => {
        const value = metricValues[index]?.value;
        return value ? parseFloat(value) : 0;
      };
    
      return {
        totalPageViews: Math.round(getValue(0)),
        totalUsers: Math.round(getValue(1)),
        totalSessions: Math.round(getValue(2)),
        newUsers: Math.round(getValue(3)),
        avgSessionDuration: formatDuration(getValue(4)),
        bounceRate: formatPercentageFromDecimal(getValue(5)),
        engagementRate: formatPercentageFromDecimal(getValue(6)),
        pagesPerSession: roundToDecimal(getValue(7)),
        period: dateRange,
      };
    }
  • Type definitions for the tool's input (GetTrafficSummaryInput: propertyId optional, period required) and output (TrafficSummaryOutput: structured traffic metrics).
    // get_traffic_summary
    export interface GetTrafficSummaryInput extends PropertyId {
      period: Period;
    }
    
    export interface TrafficSummaryOutput {
      totalPageViews: number;
      totalUsers: number;
      totalSessions: number;
      newUsers: number;
      avgSessionDuration: string;
      bounceRate: string;
      engagementRate: string;
      pagesPerSession: number;
      period: {
        startDate: string;
        endDate: string;
      };
    }
  • src/server.ts:204-220 (registration)
    Registers the tool in the MCP server's tools array with name, description, and input schema definition.
    {
      name: "get_traffic_summary",
      description:
        "指定期間のトラフィック概要(PV数、ユーザー数、セッション数、直帰率など)を取得します。ダッシュボード的な使い方に最適です。",
      inputSchema: {
        type: "object" as const,
        properties: {
          propertyId: { type: "string", description: "GA4プロパティID" },
          period: {
            type: "string",
            enum: ["today", "yesterday", "7days", "28days", "30days", "90days"],
            description: "集計期間",
          },
        },
        required: ["period"],
      },
    },
  • src/server.ts:620-631 (registration)
    In the handleToolCall function's switch statement, dispatches calls to the getTrafficSummary handler with parsed arguments.
    case "get_traffic_summary":
      return await getTrafficSummary({
        propertyId: args.propertyId as string | undefined,
        period: args.period as
          | "today"
          | "yesterday"
          | "7days"
          | "28days"
          | "30days"
          | "90days",
      });
  • Re-exports the getTrafficSummary handler from its module for convenient import in server.ts.
    export { getTrafficSummary } from "./getTrafficSummary.js";
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It describes the action ('取得します' - get) and output metrics, but doesn't mention critical behaviors like whether this is a read-only operation, requires authentication, has rate limits, or returns aggregated vs. raw data. For a data retrieval tool with zero annotation coverage, this is a significant gap in transparency.

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 concise with two sentences: one stating the purpose and one providing usage context. It's front-loaded with the core functionality. However, the second sentence ('ダッシュボード的な使い方に最適です') could be more specific, and there's some redundancy in mentioning '指定期間' (specified period) when the schema already covers it.

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?

Given no annotations and no output schema, the description is moderately complete. It covers the purpose and hints at usage, but lacks details on behavioral traits (e.g., read-only status, error handling) and output format. For a 2-parameter tool with 100% schema coverage, it's adequate but has clear gaps in transparency and output expectations.

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%, with both parameters ('propertyId' and 'period') well-documented in the schema. The description doesn't add any parameter-specific details beyond implying a '指定期間' (specified period) context. Since the schema does the heavy lifting, the baseline score of 3 is appropriate, as the description provides no extra semantic value for parameters.

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

Purpose4/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: '指定期間のトラフィック概要(PV数、ユーザー数、セッション数、直帰率など)を取得します' (Get traffic summary for a specified period including page views, users, sessions, bounce rate, etc.). It specifies the verb '取得します' (get) and resource 'トラフィック概要' (traffic summary) with concrete metrics. However, it doesn't explicitly differentiate from siblings like 'get_daily_trend' or 'get_hourly_traffic' beyond mentioning 'ダッシュボード的な使い方に最適です' (ideal for dashboard use).

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

Usage Guidelines3/5

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

The description provides some implied usage context: 'ダッシュボード的な使い方に最適です' (ideal for dashboard use), suggesting it's for high-level overviews. However, it doesn't explicitly state when to use this tool versus alternatives like 'get_daily_trend' for time-series data or 'run_report' for custom reports. No exclusions or clear alternatives are mentioned, leaving the agent to infer from sibling tool names.

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/Shin-sibainu/ga4-mcp-server'

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