get_landing_pages
Retrieve landing page analysis from Google Analytics 4 to identify entry points and understand initial user interactions for traffic optimization.
Instructions
ランディングページ(ユーザーが最初にアクセスしたページ)の分析結果を取得します。
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| propertyId | No | GA4プロパティID | |
| period | Yes | 集計期間 | |
| limit | No | 取得件数(デフォルト: 10) |
Implementation Reference
- The main handler function that executes the get_landing_pages tool logic by querying GA4 for landing pages report and processing the data.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 interfaces defining the input schema (GetLandingPagesInput), output structure (GetLandingPagesOutput), and related LandingPage type for the tool.// 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 the tool name, description, and input schema 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)Dispatch handler in the switch statement that calls the getLandingPages function with parsed arguments.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/tools/analytics/index.ts:7-7 (helper)Re-export of the getLandingPages handler from its implementation file for convenient import in server.ts.export { getLandingPages } from "./getLandingPages.js";