Tutorial · Beginner

Get plain answers about your website traffic without digging through Google Analytics

Finding one simple answer in GA4 reports takes too long. Ask Claude a question like "where did my visitors come from last month?" and get a short breakdown with the numbers, through a read-only login that can't change anything in your account.
[ The result ]

You ask Claude Code about your GA4 traffic in plain English and get the numbers explained, through Google's official MCP server and a read-only login that can't change your settings.

[ How it's wired ]
  1. Install the four command-line tools

    Google's official way to connect Analytics to an AI assistant is a free server that runs on your own computer, so the setup needs a few terminal commands. You do them once. Open a terminal. Check each tool by running the commands below. Each one should print a version number. 1) Python 3.10 or higher. The analytics-mcp server needs 3.10+. 2) pipx. On a Mac, install it with Homebrew: brew install pipx, then pipx ensurepath, then open a new terminal window. Homebrew brings its own Python, so this works whatever Python you have. If you install pipx with pip instead, you need Python 3.11 or higher, and Python 3.10 will give you an error. uv works too. 3) The Google Cloud CLI. Follow the install page for your system, then run gcloud init and sign in. 4) Claude Code. Follow the setup page, open a new terminal window and run claude --version. If a command isn't found, fix that tool before you go on. Every later step depends on these four.

    python3 --version
    pipx --version
    gcloud --version
    claude --version
  2. Enable the two Google Analytics APIs

    Open the Google Cloud console and create or select a project. Write down its project ID, which you'll need twice later. Then enable the Google Analytics Admin API and the Google Analytics Data API. You can do this in the console under APIs & Services, or run the command below in your terminal. Replace YOUR_PROJECT_ID with your ID. When it's done, both APIs show as enabled in the project.

    gcloud services enable analyticsadmin.googleapis.com \
      analyticsdata.googleapis.com \
      --project=YOUR_PROJECT_ID
  3. Check your access to the GA4 property

    In Google Analytics, open Admin, then go to property access management. Make sure the Google account you'll sign in with has at least the Viewer role on the property you want to ask about. Viewer is all this setup needs, because the server only reads reports.

  4. Sign in with the read-only scope

    Run the command below. A browser window opens. Pick the same Google account and allow access. The analytics.readonly scope lets this login read Analytics data and nothing else. The cloud-platform scope is there so the requests can use your Cloud project. When it finishes, the terminal prints a line like: Credentials saved to file: [PATH]. Copy that full path. On a Mac it usually looks like /Users/yourname/.config/gcloud/application_default_credentials.json. If Google blocks the sign-in, create an OAuth desktop client in your Cloud project and add --client-id-file=YOUR_CLIENT_JSON_FILE to the same command. Google's setup guide shows this option.

    gcloud auth application-default login \
      --scopes="https://www.googleapis.com/auth/analytics.readonly,https://www.googleapis.com/auth/cloud-platform"
  5. Add analytics-mcp to Claude Code

    Paste the command below. Replace PATH_TO_CREDENTIALS_JSON with the full path from the previous step and YOUR_PROJECT_ID with your project ID. Use the complete path. Don't use ~ or $HOME, because some MCP hosts don't expand them. --scope user makes the server available in every folder you open Claude Code in. Don't add the --allow-write flag. Without it, the server only offers read tools: account summaries, property details, reports, realtime, funnel and conversions reports. The read-only login is a second safety layer on top of that. If you use uv instead of pipx, replace the last line with: -- uvx --from analytics-mcp google-analytics-mcp

    claude mcp add analytics-mcp \
      --scope user \
      -e GOOGLE_APPLICATION_CREDENTIALS="PATH_TO_CREDENTIALS_JSON" \
      -e GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID" \
      -- pipx run analytics-mcp
  6. Check that Claude Code sees the server

    Run claude in your terminal, then type /mcp. You should see analytics-mcp in the list, marked as connected. The first start can take a moment while pipx downloads the package. Next, ask Claude to list your properties. When Claude asks for permission to use a tool, say yes. You should get back your GA accounts and properties with their IDs.

    What can the analytics-mcp server do? Then list my Google Analytics accounts and properties with their IDs.
  7. Ask three ready traffic questions

    Paste these one at a time. Replace the property name with yours. Claude picks the right report, runs it and explains the numbers in plain words. For example, you type question 1 and get back a top-10 list of pages with this week's and last week's views and the change in %. You type question 2 and get a breakdown of where visitors came from, with users and key events for each source. Ask Claude to show the dates it compared, so you can check the result against GA4. Question 3 uses a realtime report, which shows page titles, not page URLs.

    1) For my property "YOUR PROPERTY NAME", which pages lost the most views this week compared with last week? Show the top 10 with both numbers and the change in %.
    
    2) Where did my users come from in the last 28 days? Break it down by session source / medium and show users and key events for each.
    
    3) How many users are on the site right now, and which page titles are they viewing?
  8. Fix the common errors

    403 PERMISSION_DENIED: check that both APIs are enabled in the project you set as GOOGLE_CLOUD_PROJECT, and that your account has Viewer access on the property. "Request had insufficient authentication scopes": run the login command from step 4 again with both scopes. Missing quota project or ACCESS_NOT_CONFIGURED: make sure GOOGLE_CLOUD_PROJECT is set, or run the command below. 401 UNAUTHENTICATED or credentials file not found: use the full absolute path, and log in again if your credentials expired. pipx or uvx not found: install pipx with Homebrew (or with Python 3.11+), or use the full path that which pipx prints. Source: Google's "Try the Google Analytics MCP server" guide and the googleanalytics/google-analytics-mcp repository.

    gcloud auth application-default set-quota-project YOUR_PROJECT_ID
DoneStuck on a step? Reply to any Daily AI Brief email and ask.
[ One tutorial a week ]

Get the next automation before it's posted.

One short email with the AI stories that matter. What happened in AI, why it matters, one tool worth trying. Free. Unsubscribe anytime.

More tutorials

All tutorials
01Find out what you missed in a long lecture with a free quiz and flashcards20 min · Beginner · 7 steps02Make Claude Code follow your project's rules in every session15 min · Beginner · 7 steps03Turn your most frequent app error into a tested fix you can review20 min · Intermediate · 7 steps
[ Daily AI Brief ]

The AI news that matters, in your inbox.

One short email with the AI stories that matter. What happened in AI, why it matters, one tool worth trying. Free. Unsubscribe anytime.