Skip to main content
Glama
Shin-sibainu

GA4 MCP Server

by Shin-sibainu

get_exit_pages

Retrieve exit page analysis from Google Analytics 4 to identify where users leave your website. Analyze final page views to optimize user retention and reduce bounce rates.

Instructions

離脱ページ(ユーザーが最後に見たページ)の分析結果を取得します。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
propertyIdNoGA4プロパティID
periodYes集計期間
limitNo取得件数(デフォルト: 10)

Implementation Reference

  • The core handler function that executes the get_exit_pages tool logic. It queries GA4 for pagePath dimensions with screenPageViews and sessions metrics, approximates exit rates, and returns a list of exit pages.
    export async function getExitPages(
      input: GetExitPagesInput
    ): Promise<GetExitPagesOutput> {
      const propertyId = getPropertyId(input.propertyId);
      const property = formatPropertyPath(propertyId);
      const dateRange = periodToDateRange(input.period);
      const limit = input.limit || 10;
    
      // GA4では直接exitPageディメンションがないため、
      // pagePath と screenPageViews を使って近似する
      const response = await executeReport({
        property,
        dateRanges: [dateRange],
        dimensions: [{ name: "pagePath" }],
        metrics: [{ name: "screenPageViews" }, { name: "sessions" }],
        orderBys: [{ metric: { metricName: "screenPageViews" }, desc: true }],
        limit,
      });
    
      // 合計セッション数を取得
      const totalSessions =
        response.totals?.[0]?.metricValues?.[1]?.value
          ? parseFloat(response.totals[0].metricValues[1].value)
          : 0;
    
      const exitPages: ExitPage[] = [];
    
      for (const row of response.rows || []) {
        const dimensionValues = row.dimensionValues || [];
        const metricValues = row.metricValues || [];
    
        const pageViews = metricValues[0]?.value
          ? Math.round(parseFloat(metricValues[0].value))
          : 0;
    
        const sessions = metricValues[1]?.value
          ? Math.round(parseFloat(metricValues[1].value))
          : 0;
    
        // 離脱数をセッション数で近似(実際の離脱数とは異なる可能性あり)
        const exits = sessions;
    
        exitPages.push({
          pagePath: dimensionValues[0]?.value || "",
          exits,
          exitRate: calculatePercentage(exits, totalSessions),
        });
      }
    
      return { exitPages };
    }
  • TypeScript interfaces defining the input schema (GetExitPagesInput), data structure (ExitPage), and output schema (GetExitPagesOutput) for the get_exit_pages tool.
    // get_exit_pages
    export interface GetExitPagesInput extends PropertyId {
      period: ShortPeriod;
      limit?: number;
    }
    
    export interface ExitPage {
      pagePath: string;
      exits: number;
      exitRate: string;
    }
    
    export interface GetExitPagesOutput {
      exitPages: ExitPage[];
    }
  • src/server.ts:378-397 (registration)
    Registers the get_exit_pages tool in the MCP server's tools list, defining its name, description, and input schema.
    {
      name: "get_exit_pages",
      description: "離脱ページ(ユーザーが最後に見たページ)の分析結果を取得します。",
      inputSchema: {
        type: "object" as const,
        properties: {
          propertyId: { type: "string", description: "GA4プロパティID" },
          period: {
            type: "string",
            enum: ["7days", "28days", "30days"],
            description: "集計期間",
          },
          limit: {
            type: "number",
            description: "取得件数(デフォルト: 10)",
          },
        },
        required: ["period"],
      },
    },
  • src/server.ts:695-700 (registration)
    In the tool dispatch switch statement, handles calls to get_exit_pages by invoking the getExitPages handler with parsed arguments.
    case "get_exit_pages":
      return await getExitPages({
        propertyId: args.propertyId as string | undefined,
        period: args.period as "7days" | "28days" | "30days",
        limit: args.limit as number | undefined,
      });
Behavior2/5

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

No annotations are provided, so the description carries full burden for behavioral disclosure. The description only states what the tool retrieves but doesn't mention any behavioral traits: no information about permissions needed, rate limits, whether this is a read-only operation, what format the results come in, or any side effects. For a data retrieval tool with zero annotation coverage, this leaves significant gaps in understanding how it behaves.

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 a single, efficient sentence that directly states the tool's purpose without any unnecessary words. It's appropriately sized and front-loaded with the core functionality. Every word earns its place in conveying the essential information.

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?

Given the complexity of analytics tools and the lack of both annotations and output schema, the description is insufficiently complete. It doesn't explain what the analysis results contain, their format, or any important behavioral context. For a tool that retrieves analytical data with multiple parameters and no output schema, users need more information about what to expect from the tool's operation.

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 three parameters (propertyId, period, limit) with descriptions and enum values. The description doesn't add any additional meaning about parameters beyond what's in the schema. According to scoring rules, when schema coverage is high (>80%), the baseline is 3 even with no parameter information in the description.

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: '離脱ページ(ユーザーが最後に見たページ)の分析結果を取得します' (Get analysis results for exit pages, the last pages users viewed). It specifies the verb '取得します' (get/retrieve) and resource '離脱ページの分析結果' (exit page analysis results). However, it doesn't explicitly differentiate from sibling tools like 'get_landing_pages' or 'get_top_pages', which reduces it from a perfect score.

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. There are multiple sibling tools for analytics data (e.g., get_landing_pages, get_top_pages, get_engagement_metrics), but the description doesn't indicate when exit page analysis is specifically needed or when other tools might be more appropriate. No usage context or exclusions are mentioned.

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