Skip to main content
Glama

get_traffic_summary

Retrieve Google Analytics 4 traffic summaries including pageviews, users, sessions, and bounce rates for specified time periods to monitor website performance.

Instructions

指定期間のトラフィック概要(PV数、ユーザー数、セッション数、直帰率など)を取得します。ダッシュボード的な使い方に最適です。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
propertyIdNoGA4プロパティID
periodYes集計期間

Implementation Reference

  • The primary handler function implementing the logic for the 'get_traffic_summary' tool. It queries GA4 for traffic metrics over a specified period and formats the output.
    export async function getTrafficSummary( input: GetTrafficSummaryInput ): Promise<TrafficSummaryOutput> { const propertyId = getPropertyId(input.propertyId); const property = formatPropertyPath(propertyId); const dateRange = periodToDateRange(input.period); const response = await executeReport({ property, dateRanges: [dateRange], metrics: [ { name: "screenPageViews" }, { name: "totalUsers" }, { name: "sessions" }, { name: "newUsers" }, { name: "averageSessionDuration" }, { name: "bounceRate" }, { name: "engagementRate" }, { name: "screenPageViewsPerSession" }, ], }); // 結果からメトリクス値を取得 const metricValues = response.totals?.[0]?.metricValues || []; const getValue = (index: number): number => { const value = metricValues[index]?.value; return value ? parseFloat(value) : 0; }; return { totalPageViews: Math.round(getValue(0)), totalUsers: Math.round(getValue(1)), totalSessions: Math.round(getValue(2)), newUsers: Math.round(getValue(3)), avgSessionDuration: formatDuration(getValue(4)), bounceRate: formatPercentageFromDecimal(getValue(5)), engagementRate: formatPercentageFromDecimal(getValue(6)), pagesPerSession: roundToDecimal(getValue(7)), period: dateRange, }; }
  • TypeScript interface definitions for the input (GetTrafficSummaryInput) and output (TrafficSummaryOutput) of the get_traffic_summary tool.
    // get_traffic_summary export interface GetTrafficSummaryInput extends PropertyId { period: Period; } export interface TrafficSummaryOutput { totalPageViews: number; totalUsers: number; totalSessions: number; newUsers: number; avgSessionDuration: string; bounceRate: string; engagementRate: string; pagesPerSession: number; period: { startDate: string; endDate: string; }; }
  • src/server.ts:205-220 (registration)
    Tool registration in the MCP server: defines the name, description, and input schema for 'get_traffic_summary'.
    name: "get_traffic_summary", description: "指定期間のトラフィック概要(PV数、ユーザー数、セッション数、直帰率など)を取得します。ダッシュボード的な使い方に最適です。", inputSchema: { type: "object" as const, properties: { propertyId: { type: "string", description: "GA4プロパティID" }, period: { type: "string", enum: ["today", "yesterday", "7days", "28days", "30days", "90days"], description: "集計期間", }, }, required: ["period"], }, },
  • src/server.ts:620-630 (registration)
    Dispatch handler in the MCP server's tool call switch statement that invokes getTrafficSummary.
    case "get_traffic_summary": return await getTrafficSummary({ propertyId: args.propertyId as string | undefined, period: args.period as | "today" | "yesterday" | "7days" | "28days" | "30days" | "90days", });
  • Re-export of the getTrafficSummary handler from its module for use in server imports.
    export { getTrafficSummary } from "./getTrafficSummary.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