Home>Connect>GA4 to Claude Code

Connect GA4 to Claude Code in One Command

By Ahmed Ashraf|Updated September 23, 2026
Google Analytics 4 Claude Code

Run claude mcp add --transport http paidsync https://mcp.paidsync.ai/mcp, type /mcp, and sign in with your PaidSync login. Claude Code then reaches your Google Analytics 4 properties through 26 tools: custom reports, realtime checks, key events, custom dimensions, audiences and Google Ads links. Claude Code asks before it runs each tool, and GA4 writes apply on the first call, with no dry run.

One command. OAuth sign-in, no key pasted. Free plan, 15 tasks a month, no card.

Free to start · No credit card · OAuth 2.0 sign-in · 530+ tools total

The command

Claude Code talks to remote MCP servers over Streamable HTTP. PaidSync is one of them. Add it once and the same terminal that edits your code can query and configure your GA4 properties.

claude mcp add --transport http paidsync https://mcp.paidsync.ai/mcp

By default that registers the server for the current project only. Add --scope user to make it available in every project on your machine. Run claude mcp list to confirm it is there, then start a session and type /mcp to sign in.

5-Step Setup

1

Sign up at paidsync.ai/signup

Takes 10 seconds. Google or email sign-in. The free plan is 15 tasks a month at $0, no card.

2

Connect GA4 in the PaidSync dashboard

Click Connect on Google Analytics 4. GA4 authorizes via Google OAuth, with the Google account that has access to your properties. It uses the same Google sign-in as Google Ads and asks for the analytics scopes, analytics.edit and analytics.readonly.

Already inside Claude Code? Ask it to run connect_ga4. The tool returns an OAuth link to open in your browser.

3

Pick the property Claude Code should work on

Inside a session, list_ga4_accounts and list_ga4_properties show every property your sign-in can reach. Name the property in your prompt, or pin it in your project’s CLAUDE.md so every session uses it.

4

Add PaidSync to Claude Code

In your terminal, run:

claude mcp add --transport http paidsync https://mcp.paidsync.ai/mcp

Start a session, type /mcp, pick paidsync, and sign in with your PaidSync login in the browser window that opens. Claude Code stores the OAuth token for you. No key is pasted anywhere.

Setting this up for a team? Commit a .mcp.json at the repo root so every engineer gets the same connector:

{ "mcpServers": { "paidsync": { "type": "http", "url": "https://mcp.paidsync.ai/mcp" } } }

Prefer an API key, for example for headless runs? Send it in a header, never in the URL, where it would end up in logs:

claude mcp add --transport http paidsync https://mcp.paidsync.ai/mcp --header "Authorization: Bearer $PAIDSYNC_API_KEY"

In a committed .mcp.json, add "headers": { "Authorization": "Bearer ${PAIDSYNC_API_KEY}" } so the key stays in each engineer's environment and never enters git. Applying a change to Google Ads still requires the OAuth sign-in. On other platforms a key can apply changes too, so treat it like a password and prefer OAuth.

5

Test the connection

In a Claude Code session ask: “Show me sessions and key events by source and medium for the last 28 days”

Claude Code runs a GA4 report on the property and returns the table. The connection is live.

Free plan includes 15 tasks a month. Pro from $99 a month, Team from $249.

Start Free See a Demo

GA4 prompts to try in Claude Code

Each prompt below maps to tools in the PaidSync GA4 group. Claude Code picks the tool. The last column says whether the call can change anything in the property.

AskTools it callsChanges your account?
“List my GA4 properties and their data streams”list_ga4_properties, list_ga4_data_streamsNo
“Sessions and conversions by source and medium, last 28 days”run_ga4_reportNo
“Is the purchase event firing right now?”run_ga4_realtime_reportNo
“Which key events are set up, and is Google Ads linked?”list_ga4_conversion_events, list_ga4_google_ads_linksNo
“Which enhanced measurement events are on for the web stream?”get_ga4_enhanced_measurementNo
“Mark generate_lead as a key event”create_ga4_conversion_eventYes, after you confirm
“Add a custom dimension for the plan_tier event parameter”create_ga4_custom_dimensionYes, after you confirm
“Link Google Ads account 123-456-7890 to this property”create_ga4_google_ads_linkYes, after you confirm

Run it headless with claude -p

The -p flag runs Claude Code without the interactive session. Sign in once through /mcp and the stored OAuth token carries over. A report that lands in a file looks like this:

claude -p "Run a GA4 report for the last 7 days of sessions and key events by source and medium, and flag any source whose key events dropped against the week before." \ --allowedTools "mcp__paidsync" \ --output-format json > reports/ga4-$(date +%F).json

Reads run straight through, and so do writes. --allowedTools "mcp__paidsync" allows every PaidSync tool, writes included, with no prompt. For an unattended job, allow only the read tools it needs, each by name as mcp__paidsync__tool_name.

What reads and what writes

Of the 26 GA4 tools, 11 only read and 13 can write. Reads and reports cover properties, data streams, key events, custom dimensions and metrics, audiences, Google Ads links, enhanced measurement, custom reports through run_ga4_report and the last 30 minutes through run_ga4_realtime_report.

Writes change property configuration: properties, data streams, key events, custom dimensions and metrics, audiences, enhanced measurement and Google Ads links. None of the GA4 writes has a dry run. Each one applies on the first call, so read the arguments in the Claude Code prompt before you allow it. Deletes need confirm_destructive.

Over MCP, the approval step is Claude Code’s own prompt. It asks before it runs a tool unless you allowed it with --allowedTools or in your settings. PaidSync adds checks on its side. Deletes, pauses and budget changes need confirm_destructive, and a pre-write rule check blocks unsafe arguments. The approval card and one-tap undo apply only in the PaidSync workspace.

Limits worth knowing

  • An event must already be firing in your data stream before create_ga4_conversion_event can mark it as a key event.
  • GA4 tools do not put tags on your website. Tags live in Google Tag Manager, which has its own Claude Code setup. setup_ga4_event creates a GA4 event tag in a GTM workspace, so it needs GTM connected too.
  • Removing a key event with delete_ga4_conversion_event stops it counting as a key event. GA4 keeps collecting the event itself.
  • The realtime report covers the last 30 minutes only. Use run_ga4_report for anything older.

Frequently Asked Questions

How do I connect GA4 to Claude Code?

Sign up at paidsync.ai, connect Google Analytics 4 in the dashboard with your Google sign-in, then run claude mcp add --transport http paidsync https://mcp.paidsync.ai/mcp in your terminal. Type /mcp inside a session, pick paidsync, and sign in with your PaidSync login.

Can Claude Code change my GA4 setup?

Yes. Claude Code can mark key events, add custom dimensions and metrics, create audiences, change enhanced measurement and link Google Ads. GA4 writes have no dry run and apply on the first call, so the Claude Code prompt is your check. Deletes need an explicit confirm.

Can Claude Code check whether tracking works?

Yes. run_ga4_realtime_report shows the last 30 minutes, so you can fire a test event on your site and ask Claude Code whether it arrived.

Does it work in headless mode with claude -p?

Yes. Once you have signed in through /mcp, claude -p reuses the stored OAuth token. Reads run straight through. Writes need care. No one is there to answer the Claude Code prompt, so any write tool you allowed with --allowedTools runs straight through. For an unattended job, allow only the read tools it needs.

Is it free?

Yes. The free plan is $0 for 15 tasks a month with no card. Pro starts at $99 a month and Team at $249 a month.

26 GA4 tools. One command in Claude Code.