How to Connect GA4 to Claude for Free (Apps Script, No Paid Connector)

By Rohan Babbar6 min read
How to Connect GA4 to Claude for Free (Apps Script, No Paid Connector)

You can connect Google Analytics 4 to Claude without paying for a connector. I do it with Google Apps Script, the GA4 Data API and one Google Sheet. Every morning the sheet pulls fresh GA4 data, and Claude reads it through Google Drive.

This post covers the GA4 side of that setup: which reports to pull, the exact dimensions and metrics, the code, and the mistakes that cost me time. The Google Cloud and permissions setup is shared with my Search Console tracker, and it's covered step by step in how I connected Google Search Console to Claude.

The options for connecting GA4 to Claude

  • Paid connectors. Several reporting tools sell a Claude connector for GA4. They're quick to set up, but they cost money once you need more than one data source or a longer history.
  • Google's GA4 MCP server. Google publishes an open-source Analytics MCP server, labelled experimental, that runs on your own computer.
  • Apps Script and a Google Sheet (this post). Free, runs in the cloud on a schedule, and puts GA4 next to Search Console and anything else in one place Claude can read.

I chose the third route because I wanted GA4 and Search Console in one table, refreshed daily, without a monthly bill.

What you need

  • A GA4 property, and its numeric property ID (GA4 → Admin → Property details). The G- measurement ID on your website won't work with the API.
  • A Google Sheet with an Apps Script project attached (Extensions → Apps Script).
  • A Google Cloud project with the Google Analytics Data API enabled, linked to the script. The steps are the same as in my Search Console post.
  • Claude, with Google Drive connected.

Step 1: Turn on the GA4 Data API inside Apps Script

GA4 is available in Apps Script as an advanced service called AnalyticsData. Add it, plus read-only Analytics access, in the manifest (appsscript.json):

"dependencies": {
  "enabledAdvancedServices": [
    { "userSymbol": "AnalyticsData", "version": "v1beta", "serviceId": "analyticsdata" }
  ]
},
"oauthScopes": [
  "https://www.googleapis.com/auth/spreadsheets",
  "https://www.googleapis.com/auth/analytics.readonly"
]

analytics.readonly means the script can read your GA4 data and can never change a setting.

Step 2: Decide which GA4 reports Claude actually needs

GA4 can return hundreds of dimension and metric combinations. Claude doesn't need them all. I pull five reports, each answering one question:

Tab Question it answers Dimensions Metrics
GA4_Daily How many visits per day, from which channel? date, sessionDefaultChannelGroup sessions, totalUsers, engagedSessions, keyEvents
GA4_Landing Which pages do visits start on, and do people stay? landingPage, sessionDefaultChannelGroup sessions, engagedSessions, keyEvents, engagementRate
GA4_Events What are people doing? date, eventName eventCount, totalUsers
GA4_Click_Destinations Where do people click out to? linkDomain, linkUrl, pagePath eventCount (filtered to the click event)
GA4_Organic_Page_Geo Where are organic visitors, and are they in my target markets? landingPage, city, region, country sessions (filtered to Organic Search)

The last two are the ones most setups miss. A portfolio site with no contact form has no obvious conversion, so I treat a click to my LinkedIn profile as an enquiry. And organic traffic from the wrong country is a cost, not a win, so every organic visit is checked against a list of target markets.

Step 3: Pull each report with one function

Every report follows the same pattern. Here's the landing-page report from my tracker:

function fetchGa4Landing(ss) {
  const request = {
    dateRanges: [{ startDate: daysAgo_(28), endDate: 'today' }],
    dimensions: [{ name: 'landingPage' }, { name: 'sessionDefaultChannelGroup' }],
    metrics: [{ name: 'sessions' }, { name: 'engagedSessions' },
              { name: 'keyEvents' }, { name: 'engagementRate' }],
    limit: 10000,
  };
  const resp = AnalyticsData.Properties.runReport(request, 'properties/' + CFG.ga4PropertyId);
  const rows = (resp.rows || []).map(r => [
    r.dimensionValues[0].value, r.dimensionValues[1].value,
    r.metricValues[0].value, r.metricValues[1].value,
    r.metricValues[2].value, r.metricValues[3].value,
  ]);
  writeRows_(getSheet_(ss, 'GA4_Landing'),
    ['Landing Page', 'Channel', 'Sessions', 'Engaged Sessions', 'Key Events', 'Engagement Rate'], rows);
}

To report on outbound clicks, filter to GA4's click event and flag the destinations that count as enquiries:

dimensionFilter: { filter: { fieldName: 'eventName', stringFilter: { value: 'click' } } }
// then, per row:
const flag = CFG.enquiryDomains.some(d => domain.includes(d)) || /^mailto:/i.test(linkUrl)
  ? 'ENQUIRY' : '';

GA4 only records these clicks if Enhanced measurement → Outbound clicks is turned on (Admin → Data streams).

Two rules from experience:

  • Write each tab in one batch with setValues, not row by row. Apps Script stops any run after 6 minutes.
  • Schedule it. I run the GA4 pull at 06:00 every morning with a time-based trigger, then build the export for Claude an hour later.

Step 4: Build one export tab for Claude

Five tabs with different layouts make Claude guess. So the GA4 reports are also copied into a single Claude_Export tab, alongside Search Console, with fixed columns (sessions, engaged_sessions, key_events, event_count and so on) and a summary row per report stating its date range.

The script does the maths, and Claude interprets it. For example, the geo block's summary row already states total organic sessions and how many came from India, so Claude never has to add them up.

One detail that took me a while to find: when Claude reads a Google Sheet through Drive as CSV, it only sees the first tab. Keep the export tab first.

Step 5: Ask Claude real questions

With the sheet in Drive, questions like these get specific answers:

  • "Which landing pages get visits but almost no engaged sessions?"
  • "How many enquiry clicks did each page produce this month?"
  • "Are my organic visitors coming from my target markets?"

What it showed on my own site

  • Organic visitors stay, social visitors don't. Search visitors to my homepage had a 73% engagement rate. When I shared a new article on LinkedIn, the first four visitors from LinkedIn all left without engaging. That told me the top of the article needed to work harder, not the post.
  • Every organic visit came from India, even though Search Console showed most impressions coming from other countries. That mismatch led me to split Search Console data by country, which showed the foreign impressions were company-lookup searches with no intent behind them.
  • Contact clicks are now measurable. Clicks to my LinkedIn profile are flagged as enquiries per page, so I can see which pages actually start conversations.

Mistakes to avoid

  • Using the G- measurement ID. The API needs the numeric property ID.
  • Adding up totalUsers across days. Users aren't additive: one person visiting on three days is one user, not three. Sum sessions instead.
  • Forgetting Enhanced measurement. Without outbound-click tracking switched on, the click report stays empty.
  • Counting every event as a conversion. Decide which events are real key events first, then report on those.

If you want help setting up analytics like this, or marketing more broadly, see digital marketing consultant in India.

FAQ

Can I connect GA4 to Claude for free?

Yes. Google Apps Script can pull GA4 data through the GA4 Data API into a Google Sheet at no cost, and Claude can read that sheet through Google Drive.

Do I need the GA4 property ID or the measurement ID?

The numeric property ID, found in GA4 → Admin → Property details. The G- measurement ID is for your website tag and won't work with the API.

Can the script change my GA4 settings?

No. With the analytics.readonly scope it can only read data.

Why does Claude only see one tab of my sheet?

When a Google Sheet is read through Drive as CSV, only the first tab comes through. Put the tab you want Claude to read first.

How often does the data refresh?

As often as you schedule it. I use a daily time-based trigger at 06:00.


I'm Rohan Babbar, a Digital Marketing Manager in Delhi who builds the systems that measure paid media and SEO. Connect with me on LinkedIn.

ga4claudeapps scriptgoogle analyticsmarketing analytics
ShareLinkedInX
Rohan Babbar
Rohan Babbar

Digital marketing, SEO and paid media. Connect on LinkedIn