Skip to main content
Glama
Shin-sibainu

GA4 MCP Server

by Shin-sibainu

get_landing_pages

Retrieve landing page analysis from Google Analytics 4 to identify entry points and understand initial user interactions.

Instructions

ランディングページ(ユーザーが最初にアクセスしたページ)の分析結果を取得します。

Input Schema

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

Implementation Reference

  • The core handler function that implements the get_landing_pages tool logic: queries GA4 report for landing pages, processes dimensions and metrics, formats data into LandingPage objects.
    export async function getLandingPages(
      input: GetLandingPagesInput
    ): Promise<GetLandingPagesOutput> {
      const propertyId = getPropertyId(input.propertyId);
      const property = formatPropertyPath(propertyId);
      const dateRange = periodToDateRange(input.period);
      const limit = input.limit || 10;
    
      const response = await executeReport({
        property,
        dateRanges: [dateRange],
        dimensions: [{ name: "landingPage" }],
        metrics: [
          { name: "sessions" },
          { name: "totalUsers" },
          { name: "bounceRate" },
          { name: "averageSessionDuration" },
        ],
        orderBys: [{ metric: { metricName: "sessions" }, desc: true }],
        limit,
      });
    
      const landingPages: LandingPage[] = [];
    
      for (const row of response.rows || []) {
        const dimensionValues = row.dimensionValues || [];
        const metricValues = row.metricValues || [];
    
        const getValue = (index: number): number => {
          const value = metricValues[index]?.value;
          return value ? parseFloat(value) : 0;
        };
    
        landingPages.push({
          pagePath: dimensionValues[0]?.value || "",
          entrances: Math.round(getValue(0)),
          users: Math.round(getValue(1)),
          bounceRate: formatPercentageFromDecimal(getValue(2)),
          avgSessionDuration: formatDuration(getValue(3)),
        });
      }
    
      return { landingPages };
    }
  • TypeScript type definitions for GetLandingPagesInput, LandingPage interface, and GetLandingPagesOutput.
    // get_landing_pages
    export interface GetLandingPagesInput extends PropertyId {
      period: ShortPeriod;
      limit?: number;
    }
    
    export interface LandingPage {
      pagePath: string;
      entrances: number;
      users: number;
      bounceRate: string;
      avgSessionDuration: string;
    }
    
    export interface GetLandingPagesOutput {
      landingPages: LandingPage[];
    }
  • src/server.ts:357-377 (registration)
    MCP tool registration entry defining name 'get_landing_pages', description, and inputSchema for validation.
    {
      name: "get_landing_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:688-693 (registration)
    Switch case in tool call handler that routes 'get_landing_pages' calls to the getLandingPages function with argument parsing.
    case "get_landing_pages":
      return await getLandingPages({
        propertyId: args.propertyId as string | undefined,
        period: args.period as "7days" | "28days" | "30days",
        limit: args.limit as number | undefined,
      });
  • src/server.ts:26-26 (registration)
    Import of getLandingPages handler from analytics tools index.
    getLandingPages,

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