Skip to main content
Glama
ruchernchong

mcp-server-google-analytics

by ruchernchong

getUserBehavior

Retrieve user behavior metrics such as session duration and bounce rate from Google Analytics 4 data for specified date ranges to analyze website engagement patterns.

Instructions

Get user behavior metrics like session duration and bounce rate

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
startDateYesStart date in YYYY-MM-DD format
endDateYesEnd date in YYYY-MM-DD format

Implementation Reference

  • Handler for the getUserBehavior tool. Extracts date range from arguments, validates it, and fetches analytics data for average session duration, bounce rate, sessions per user, grouped by date.
    case "getUserBehavior": {
      const { startDate, endDate } = args as {
        startDate: string;
        endDate: string;
      };
    
      validateDateRange(startDate, endDate);
    
      return fetchAnalyticsData({
        dateRanges: [{ startDate, endDate }],
        metrics: [
          { name: "averageSessionDuration" },
          { name: "bounceRate" },
          { name: "sessionsPerUser" },
        ],
        dimensions: [{ name: "date" }],
      });
    }
  • src/index.ts:240-258 (registration)
    Registration of the getUserBehavior tool in the listTools handler, including name, description, and input schema requiring startDate and endDate.
    {
      name: "getUserBehavior",
      description:
        "Get user behavior metrics like session duration and bounce rate",
      inputSchema: {
        type: "object",
        properties: {
          startDate: {
            type: "string",
            description: "Start date in YYYY-MM-DD format",
          },
          endDate: {
            type: "string",
            description: "End date in YYYY-MM-DD format",
          },
        },
        required: ["startDate", "endDate"],
      },
    },

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/ruchernchong/mcp-server-google-analytics'

If you have feedback or need assistance with the MCP directory API, please join our Discord server