Skip to main content
Glama
Shin-sibainu

GA4 MCP Server

by Shin-sibainu

get_conversion_funnel

Analyze conversion funnels in GA4 to identify drop-off points and calculate step-by-step completion rates for user journeys.

Instructions

コンバージョンファネルの分析を行います。各ステップの通過率や離脱率を確認できます。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
propertyIdNoGA4プロパティID
periodYes集計期間
stepsYesファネルのステップ定義(最低2つ必要)

Implementation Reference

  • The core handler function that implements the get_conversion_funnel tool logic. It fetches user counts for each funnel step using GA4 reports, computes dropoff rates and conversion rates relative to the first step, and returns the funnel analysis results.
    export async function getConversionFunnel(
      input: GetConversionFunnelInput
    ): Promise<GetConversionFunnelOutput> {
      const propertyId = getPropertyId(input.propertyId);
      const property = formatPropertyPath(propertyId);
      const dateRange = periodToDateRange(input.period);
    
      if (input.steps.length < 2) {
        throw new Error("ファネル分析には少なくとも2つのステップが必要です");
      }
    
      const funnel: FunnelStepResult[] = [];
      let previousUsers = 0;
      let firstStepUsers = 0;
    
      // 各ステップのユーザー数を取得
      for (let i = 0; i < input.steps.length; i++) {
        const step = input.steps[i];
    
        const response = await executeReport({
          property,
          dateRanges: [dateRange],
          dimensions: [{ name: "pagePath" }],
          metrics: [{ name: "totalUsers" }],
          dimensionFilter: {
            filter: {
              fieldName: "pagePath",
              stringFilter: {
                matchType: "BEGINS_WITH",
                value: step.pagePath,
              },
            },
          },
        });
    
        const users =
          response.totals?.[0]?.metricValues?.[0]?.value
            ? Math.round(parseFloat(response.totals[0].metricValues[0].value))
            : 0;
    
        if (i === 0) {
          firstStepUsers = users;
          previousUsers = users;
        }
    
        // 離脱率の計算
        const dropoffRate =
          i === 0
            ? "0%"
            : calculatePercentage(previousUsers - users, previousUsers);
    
        // コンバージョン率の計算(最初のステップからの通過率)
        const conversionRate = calculatePercentage(users, firstStepUsers);
    
        funnel.push({
          step: i + 1,
          name: step.name,
          users,
          dropoffRate,
          conversionRate,
        });
    
        previousUsers = users;
      }
    
      // 全体のコンバージョン率(最初のステップから最後のステップへの通過率)
      const lastStepUsers = funnel[funnel.length - 1]?.users || 0;
      const overallConversionRate = calculatePercentage(lastStepUsers, firstStepUsers);
    
      return {
        funnel,
        overallConversionRate,
      };
    }
  • src/server.ts:428-461 (registration)
    MCP tool registration entry for get_conversion_funnel, defining the tool name, description, and input schema used in the listTools response.
    {
      name: "get_conversion_funnel",
      description:
        "コンバージョンファネルの分析を行います。各ステップの通過率や離脱率を確認できます。",
      inputSchema: {
        type: "object" as const,
        properties: {
          propertyId: { type: "string", description: "GA4プロパティID" },
          period: {
            type: "string",
            enum: ["7days", "28days", "30days"],
            description: "集計期間",
          },
          steps: {
            type: "array",
            items: {
              type: "object",
              properties: {
                name: {
                  type: "string",
                  description: 'ステップ名(例: "商品詳細")',
                },
                pagePath: {
                  type: "string",
                  description: 'マッチするページパス(例: "/product/")',
                },
              },
              required: ["name", "pagePath"],
            },
            description: "ファネルのステップ定義(最低2つ必要)",
          },
        },
        required: ["period", "steps"],
      },
  • TypeScript type definitions for the get_conversion_funnel tool, including input interface (GetConversionFunnelInput), output interface (GetConversionFunnelOutput), and supporting types (FunnelStep, FunnelStepResult).
    // get_conversion_funnel
    export interface FunnelStep {
      name: string;
      pagePath: string;
    }
    
    export interface GetConversionFunnelInput extends PropertyId {
      period: ShortPeriod;
      steps: FunnelStep[];
    }
    
    export interface FunnelStepResult {
      step: number;
      name: string;
      users: number;
      dropoffRate: string;
      conversionRate: string;
    }
    
    export interface GetConversionFunnelOutput {
      funnel: FunnelStepResult[];
      overallConversionRate: string;
    }
  • src/server.ts:711-716 (registration)
    Dispatch handler in the switch statement that routes calls to the get_conversion_funnel tool handler function.
    case "get_conversion_funnel":
      return await getConversionFunnel({
        propertyId: args.propertyId as string | undefined,
        period: args.period as "7days" | "28days" | "30days",
        steps: args.steps as Array<{ name: string; pagePath: string }>,
      });
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 mentions analysis and checking rates, which implies a read-only operation, but doesn't specify data sources, permissions, rate limits, or output format. For a tool with 3 parameters and no annotations, this leaves significant behavioral gaps.

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 that directly state the tool's function. It's front-loaded with the main purpose and avoids unnecessary details. However, it could be slightly more structured by explicitly mentioning it's for GA4 data or linking to sibling tools.

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, no output schema, and 3 parameters with full schema coverage, the description is minimally adequate. It covers the basic purpose but lacks details on behavioral traits, usage context, and output format. For an analytics tool with potential complexity, more completeness is needed to guide effective use.

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 fully documents all parameters (propertyId, period, steps). The description adds no additional parameter semantics beyond what's in the schema, such as explaining how steps relate to funnel analysis. Baseline score of 3 is appropriate when schema does the heavy lifting.

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: 'analyzes conversion funnels' and 'checks step pass-through rates and dropout rates.' It specifies the verb (analyze/check) and resource (conversion funnels), but doesn't differentiate from sibling tools like 'get_user_journey' which might have overlapping analytics functions.

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?

No explicit guidance on when to use this tool versus alternatives is provided. The description doesn't mention prerequisites, context, or comparisons to sibling tools like 'get_user_journey' or 'run_report' that might offer similar functionality. Usage is implied through the description but not explicitly 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/Shin-sibainu/ga4-mcp-server'

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