Skip to main content
Glama

get_exit_pages

Retrieve exit page analytics from Google Analytics 4 to identify where users leave your site. Analyze final page views to optimize user retention and content strategy.

Instructions

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

Input Schema

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

Implementation Reference

  • The main handler function getExitPages that executes the tool logic. It queries GA4 using pagePath dimension and screenPageViews/sessions metrics to approximate exit pages, calculates exit rates, and returns the 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 (GetExitPagesInput), inner type (ExitPage), and output (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-396 (registration)
    Tool registration in the tools array, defining name, description, and inputSchema for get_exit_pages.
    { 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)
    Dispatch handler in the switch statement that calls the getExitPages function when the tool is invoked.
    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, });
  • Re-export of the getExitPages handler from its implementation file for use in server.ts.
    export { getExitPages } from "./getExitPages.js";

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