npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@iflow-mcp/hosakakeigo-mcp-server-ga4

v1.0.0

Published

MCP Server for Google Analytics 4 integration

Downloads

11

Readme

MCP Server for Google Analytics 4

Key Features

This server provides the following MCP functionalities:

Tools

  • get-page-views: Fetches page view metrics for a specified date range.
  • get-active-users: Fetches active user metrics for a specified date range.
  • get-events: Fetches event metrics for a specified date range.
  • get-user-behavior: Fetches user behavior metrics such as session duration and bounce rate.

Resources

  • ga4://property-info: Metadata for the GA4 property including available dimensions, metrics and comparisons.

The followings are more lightweight resources.

  • ga4://dimensions: List of available GA4 dimensions.
  • ga4://filters-help: Help documentation on using GA4 filters.
  • ga4://metrics: List of available GA4 metrics.

Prompts

  • analyze-data: Data analysis assistant.
  • create-report: Report generation template.
  • select-dimensions: Assists in selecting appropriate dimensions for analysis goals.

Setup

Prerequisites

  • A Google Analytics 4 property.
  • A Google Cloud service account with access to the GA4 API.
  • Node.js 20 or higher.
  • pnpm package manager.

Installation

# Clone the repository
git clone https://github.com/yourusername/mcp-server-ga4.git
cd mcp-server-ga4

# Install dependencies using pnpm
pnpm install

# Create the .env file
cp .env.example .env

# Edit the .env file and set your credentials
# GOOGLE_CLIENT_EMAIL=your-service-account-email@example.iam.gserviceaccount.com
# GOOGLE_PRIVATE_KEY=your-private-key
# GA_PROPERTY_ID=your-ga4-property-id

Auth

If GOOGLE_CLIENT_EMAIL and GOOGLE_PRIVATE_KEY are set, the server will authenticate with the service account. If not, it will use the default credentials.

Make sure your project enables the Google Analytics API and that your service account has the necessary permissions.(https://www.googleapis.com/auth/analytics.readonly

Here's how to set up Google Application Default Credentials:

  1. Install the Google Cloud SDK.
  2. Run the following command to authenticate:
gcloud auth application-default login --scopes=openid,https://www.googleapis.com/auth/userinfo.email,https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/analytics.readonly

# If you want to set a quota project
gcloud auth application-default set-quota-project <my-quota-project>

Build and Run

# Build the server
pnpm run build

# Run the server
pnpm start

Usage

Integration with Claude for Desktop

Add the following to your claude_desktop_config.json file:

{
  "mcpServers": {
    "ga4": {
      "command": "node",
      "args": ["/path/to/mcp-server-ga4/dist/index.js"],
      "env": {
        "GOOGLE_PROJECT_ID": "your-project-id",
        "GOOGLE_CLIENT_EMAIL": "[email protected]",
        "GOOGLE_PRIVATE_KEY": "your-private-key",
        "GA_PROPERTY_ID": "your-ga4-property-id"
      }
    }
  }
}

If you want to use the default credentials, set GOOGLE_APPLICATION_CREDENTIALS in your environment:

{
  "mcpServers": {
    "ga4": {
      "command": "node",
      "args": ["/path/to/mcp-server-ga4/dist/index.js"],
      "env": {
        "GOOGLE_PROJECT_ID": "your-project-id",
        "GA_PROPERTY_ID": "your-ga4-property-id",
        "GOOGLE_APPLICATION_CREDENTIALS": "/path/to/your/credentials.json"
      }
    }
  }
}

Filtering

You can use the filter parameter with all tools to narrow down results:

{
  "dimension": [
    {
      "name": "pagePath",
      "stringEquals": "/blog/article-1"
    }
  ],
  "metric": [
    {
      "name": "screenPageViews",
      "greaterThan": 100
    }
  ],
  "operator": "AND"
}

Pagination

When dealing with large amounts of data, use the limit and offset parameters:

// First page (items 1-50)
get-page-views with limit=50, offset=0

// Second page (items 51-100)
get-page-views with limit=50, offset=50

Troubleshooting

  • Authentication errors: Check your service account key and permissions.
  • No data showing: Verify the date range and property ID are correct.
  • Connection errors: Check your network settings and firewall.

Testing

Test using the MCP Inspector:

pnpm dlx @modelcontextprotocol/inspector node /path/to/mcp-server-ga4/dist/index.js

(Note: pnpm dlx is the equivalent of npx for executing packages)

License

MIT

Thanks

  • https://github.com/lapras-inc/lapras-mcp-server/tree/main
    • Owes to a class based structure of mcp implementation.
  • https://github.com/ruchernchong/mcp-server-google-analytics
    • Relies on basic implementation of Google Analytics API.