MarTech & Automation

How to Connect Claude With GA4 Using MCP for Automated Analytics (No Coding)

MCP acts like a USB connector between Claude and Google Analytics 4. In this setup, Claude gets secure, permissioned access to GA4 reporting data through a local MCP server. Claude Code handles the technical setup, so you do not have to manually write the server code yourself.

By Shoaib Hassan··12 min read

Key takeaways

What is MCP, and why use it with GA4?

Model Context Protocol, or MCP, is a standard that allows an AI application such as Claude to connect to external tools and data sources through a defined interface.

For this GA4 workflow, the MCP server sits between Claude and the Google Analytics Data API:

Claude → MCP Server → Google Analytics Data API → GA4 Property

The Google Analytics Data API is Google's reporting API for GA4. It can return GA4 report data programmatically and supports report methods such as standard reports, pivot reports, realtime reports, and other analytics queries.

The important point is that Claude is not scraping the GA4 interface. The MCP server uses authorized access to query the GA4 reporting API.

Claude and GA4 MCP workflow showing Google Cloud service account, GA4 property, MCP server, Claude Desktop, analytics questions, and reporting
Claude and GA4 MCP workflow, from secure Google Cloud authentication through analytics questions and recurring marketing reporting.

What you need before starting

You will also need the numeric GA4 Property ID. Google documents this as the identifier used by Data API requests for a GA4 property.

1. Create a service account in Google Cloud

The service account is the identity your local MCP server will use to authenticate with Google.

In Google Cloud Console:

  1. Create or select a Google Cloud project.
  2. Create a service account.
  3. Create a JSON key for that service account.
  4. Download the JSON key file to your computer.

Keep that JSON file private. It contains credentials that should not be committed to GitHub, uploaded to a public folder, or shared in screenshots.

Google's Analytics API documentation supports service-account authentication for API access and documents the use of service-account credential files for client libraries.

2. Give the service account access to the GA4 property

Creating the service account is not enough. GA4 also needs to recognize that account as an authorized user of the property.

Copy the service account email address from Google Cloud. It normally looks similar to:

ga4-analytics@your-project-id.iam.gserviceaccount.com

Then open the relevant GA4 property and add that service account email through the property's access-management settings with the reporting access needed for your use case.

This is what allows requests authenticated by the service account to retrieve data from that GA4 property.

3. Find your GA4 Property ID

Your MCP server also needs to know which GA4 property to query.

In Google Analytics, open the property settings and copy the numeric Property ID.

Google's Data API expects this numeric identifier when requesting reports for a property.

4. Let Claude Code create the MCP server

This is the part that makes the setup effectively no-manual-coding.

Instead of writing the Python server yourself, open Claude Code and give it the following prompt:

Claude Code prompt Please set up a Google Analytics 4 MCP server for me. I want to be able to query my GA4 data directly from Claude. Create a server.py file in a folder called "mcp-server" in my home directory. Use FastMCP and the google-analytics-data library. Set it up so I can pass the service account JSON path and GA4 property ID as environment variables. Also update my claude_desktop_config.json file so Claude Desktop can connect to it automatically.

Claude Code can then create the local server structure, install or reference the required dependencies, and configure Claude Desktop to recognize the MCP server.

No coding does not mean no code exists. It means you are using Claude Code to create and configure the integration instead of manually writing the Python server yourself.

5. Move the downloaded JSON key into the MCP server folder

After Claude Code finishes, move the service-account JSON key you downloaded from Google Cloud into the mcp-server folder Claude Code created.

Claude Code should tell you the exact local path it created.

The MCP server needs the path to this file so the Google Analytics client can authenticate as the service account.

6. Add your GA4 Property ID

The second manual step is adding the GA4 Property ID.

You can provide it when Claude Code asks for it or place it in the configuration where the generated setup expects the property value.

The final configuration should give the MCP server two important pieces of context:

Service-account JSON path

Tells the server which Google credentials to use.

GA4 Property ID

Tells the server which Google Analytics property to query.

7. Restart Claude Desktop

After the local MCP configuration has been updated, restart Claude Desktop so it reloads the connector configuration.

If the server has been configured correctly, Claude should now be able to use the GA4 MCP tool when your question requires analytics data.

8. Test the connection with a simple query

Do not start with a complicated funnel report.

Use a simple query that is easy to verify manually in GA4:

Test prompt Please test my Google Analytics connection and show me sessions from the top 5 countries for the last 7 days.

If Claude returns the country breakdown successfully, you have confirmed several parts of the setup at once:

9. Start asking real marketing analytics questions

Once the connection works, you can move from a technical test to useful marketing questions.

Sessions by traffic source

Show me sessions for the last 30 days by session source and medium. Sort from highest to lowest.

Top pages

Show me the top 10 landing pages by sessions for the last 30 days, including engaged sessions and key events where available.

Country performance

Compare sessions and engaged sessions by country for the last 30 days versus the previous 30 days. Show absolute and percentage change.

Channel trend

Compare Organic Search, Paid Search, Direct, Referral, and Organic Social sessions this month versus last month. Highlight changes greater than 15 percent.

This is where the connector starts becoming useful for Marketing Operations rather than simply being a technical integration.

10. Separate retrieval from interpretation

I recommend using the same pattern as other AI-powered reporting workflows:

Retrieve

Ask Claude to return specific GA4 dimensions and metrics.

Validate

Check the date range, dimensions, metrics, and totals.

Analyze

Compare periods, segments, and conversion behavior.

Interpret

Separate observations from hypotheses about why performance changed.

For example, first ask:

Retrieve sessions, engaged sessions, and key events by session source / medium for September 2026. Show the raw grouped results and do not explain performance yet.

Then, after reviewing the data:

Using the verified report above, compare each source against August 2026. Identify channels where traffic increased but engagement or key-event performance weakened. Separate factual observations from possible explanations.

11. Be precise about GA4 dimensions and metrics

Claude can only query what the MCP server and the GA4 Data API expose.

Common dimensions you may want to work with include:

Common metrics include:

The exact dimensions and metrics available depend on the Data API schema and the implementation of your MCP server.

12. Use the setup for recurring marketing reports

Once the connection is stable, you can use it to shorten recurring reporting workflows.

A weekly GA4 brief might include:

This can then feed a broader marketing performance dashboard or a recurring leadership brief.

13. Combine GA4 and HubSpot later

The GA4 connector becomes even more valuable when paired with CRM context.

GA4 can help answer:

HubSpot can help answer:

Together, these two connectors can support a much stronger end-to-end reporting workflow. For the HubSpot side, see How to Connect Claude With HubSpot for Marketing Operations and Automated CRM Reporting.

14. Security and credential handling

The service-account JSON key is the most sensitive part of this setup.

Do not:

Give the service account only the GA4 access required for reporting and keep the credential file local and protected.

15. Common setup problems

Problem Likely area to check
Claude cannot see the GA4 tool Claude Desktop MCP configuration and application restart
Authentication error Service-account JSON path and credential file
Permission denied Service account has not been granted access to the GA4 property
Property not found Incorrect numeric GA4 Property ID
Metric or dimension error Requested field is not supported by the Data API query
Numbers look unexpected Date range, dimension definition, metric choice, or GA4 reporting logic

16. Why this is useful for Marketing Operations

The value of this setup is not that it replaces GA4.

It removes friction between the question and the report.

Instead of opening GA4, rebuilding filters, exporting a table, and then moving into another analysis tool, you can ask a structured question and let Claude retrieve the relevant GA4 report through the MCP server.

That creates a useful layer for:

This fits directly into the broader Marketing Automation Best Practices principle: use automation to remove repeatable manual work while keeping the data logic visible and governed.

Frequently asked questions

Can Claude connect to GA4 directly?

In this setup, Claude connects to GA4 through a local MCP server. The MCP server authenticates with Google using a service account and queries the Google Analytics Data API for the configured GA4 property.

Do I need to know Python to set this up?

No manual Python coding is required in this workflow. Claude Code creates the server.py file and configures the local MCP connection for you. You still need to complete the Google Cloud and GA4 access steps and handle the credential file correctly.

Why do I need a service account?

The service account provides a Google identity that the local MCP server can use to authenticate with the Google Analytics API. The same service-account email is granted access to the GA4 property.

What can I ask Claude after connecting GA4?

You can ask for reports supported by your MCP implementation and the GA4 Data API, such as sessions by country, traffic sources, landing pages, engagement, device performance, campaigns, key events, and period comparisons.

Can I combine this with HubSpot data?

Yes. GA4 and HubSpot answer different parts of the funnel. A later cross-tool workflow can use GA4 for website acquisition and behavior and HubSpot for lead, pipeline, and customer outcomes.

Final thoughts

This setup gives Claude a practical way to work with GA4 without requiring you to manually build the integration code yourself.

Create the service account. Give it access to the GA4 property. Let Claude Code build and configure the MCP server. Add your JSON credential path and Property ID. Restart Claude Desktop. Then test the connection with a simple report before moving into more advanced analytics.

Once that foundation works, you can turn everyday GA4 questions into repeatable Marketing Operations workflows and later connect them with CRM data for deeper funnel analysis.

Shoaib Hassan
Shoaib Hassan

Data Analytics & Marketing Operations Specialist focused on building systems that improve visibility, CRM quality, reporting, and cross-functional execution.

← Back to all articles