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
| Name | Required | Description | Default |
|---|---|---|---|
| propertyId | No | GA4プロパティID | |
| period | Yes | 集計期間 | |
| limit | No | 取得件数(デフォルト: 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 }; }
- src/types.ts:253-269 (schema)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,