Every agency and consultant I know has the same problem: pulling Google Analytics reports takes too long. You log in, export a CSV, reformat the data in Google Sheets, create charts, copy them into a slide deck, write summaries, and email it to the client. That's 90 minutes per client, every week or month. With five clients that's seven and a half hours — almost a full workday spent on copy-paste busywork.
I automated the entire pipeline with Claude Code. Now it takes about eight minutes from start to finish. The script pulls the data from GA4, formats it into a report template, generates insights, and emails a PDF. I still review the output before it goes out, but the heavy lifting is done.
Here's exactly how I built it and how you can do the same.
Why Google Analytics Automation with Claude Code Makes Sense
Google Analytics reporting is a perfect automation candidate because it's 90% pattern and 10% judgment. The metrics you pull are the same every time: sessions, bounce rate, conversion events, traffic sources, top pages. The structure of the report is consistent. The insights follow predictable logic — if traffic is down, flag it; if a campaign drove a spike, call it out.
Claude Code can handle all of that. What it can't do — and shouldn't — is decide which metrics matter to a specific client or how to position bad news in a way that keeps the relationship intact. That's still your job. But the hours of manual data wrangling? That's gone.
For Vancouver agencies billing clients monthly retainers, this is one of the fastest ROI wins. You're already pulling these reports. Automating them doesn't change what you deliver — it just gives you back your time.
Setting Up the Google Analytics API Connection
The first step is connecting Claude Code to your client's Google Analytics property. You'll need API credentials from Google Cloud Console. The process is straightforward but has a few steps that trip people up, so here's the exact sequence:
- Go to Google Cloud Console and create a new project
- Enable the Google Analytics Data API (GA4) for that project
- Create a service account and download the JSON key file
- In Google Analytics, add that service account email as a viewer on the property
- Save the JSON credentials somewhere Claude Code can access them
Once that's done, you can authenticate and pull data. The GA4 API uses a different structure than Universal Analytics — it's dimension and metric based, not pre-built reports. That's actually better for automation because you specify exactly what you want and get clean JSON back.
The biggest mistake I see here is people skipping step 4. The service account needs explicit permission in GA or the API calls will fail with a cryptic 403 error. Add it as a viewer, not an editor — you're only reading data.
Building the Data Pull Script
With the API connection working, the next step is writing the script that pulls the metrics you care about. I use Python for this because the Google Analytics Data API has solid Python client libraries. Claude Code can write the entire script if you tell it what you need.
Here's the structure I use for most client reports:
from google.analytics.data_v1beta import BetaAnalyticsDataClient
from google.analytics.data_v1beta.types import DateRange, Dimension, Metric, RunReportRequest
# Authenticate with service account JSON
client = BetaAnalyticsDataClient.from_service_account_json('credentials.json')
# Define property ID and date range
property_id = 'properties/123456789'
date_range = DateRange(start_date='30daysAgo', end_date='yesterday')
# Request metrics
request = RunReportRequest(
property=property_id,
date_ranges=[date_range],
dimensions=[Dimension(name='sessionDefaultChannelGrouping')],
metrics=[
Metric(name='sessions'),
Metric(name='totalUsers'),
Metric(name='bounceRate'),
Metric(name='averageSessionDuration')
]
)
response = client.run_report(request)
print(response)
This pulls the last 30 days of traffic by channel. You can add more dimensions (landing page, device category, city) or metrics (conversions, revenue, engagement rate) depending on what the client cares about. The API response is a structured object that's easy to parse.
I usually run three separate queries: one for traffic overview, one for top pages, and one for conversion events. Then I merge the results into a single data structure that feeds the report template.
Formatting the Report Automatically
Once you have the data, the next step is turning it into something a client can read. I generate reports as Google Docs using the Google Docs API, but you could also do PDFs, HTML emails, or Google Slides depending on client preference.
The report template I use has four sections:
- Executive summary — one paragraph with the top three insights (traffic trend, best performing channel, key conversion metric)
- Traffic overview — total sessions, users, bounce rate, average session duration compared to last period
- Channel breakdown — sessions and conversions by source (organic, paid, direct, referral, social)
- Top pages — the five pages with the most traffic and their conversion rates
Claude Code writes the text for each section based on the data. I give it rules for how to phrase insights — positive trends get highlighted, declines get contextualized with a reason if I know it, and any metric that's outside normal range gets flagged.
For example, if organic traffic dropped 15% but I know the client paused their blog publishing, the script notes that. If a specific landing page saw a conversion rate spike, it calls that out as a win. The output reads like something a person wrote because the logic mirrors how I'd write it manually.
Automating Google Analytics Dashboards for Ongoing Monitoring
Beyond one-off reports, I also use Claude Code to maintain live dashboards that update daily. This is especially useful for clients running paid campaigns where performance shifts fast and you need to catch issues before they burn budget.
The setup is similar but instead of generating a document, the script writes data into a Google Sheet that's formatted as a dashboard. I use conditional formatting to highlight metrics that cross thresholds — if cost per acquisition goes above the target, the cell turns red. If conversion rate improves week-over-week, it turns green.
I run this script on a cron job every morning at 6 AM. By the time the client checks their dashboard at 9 AM, yesterday's data is already in there. No manual updates required.
This approach works particularly well for Google Ads campaign tracking where daily monitoring matters. You can connect both the GA4 API and the Google Ads API to the same script and cross-reference performance across platforms.
What You Can't Automate (And Shouldn't Try)
Automated reporting saves time, but it's not a substitute for strategic analysis. Claude Code can tell you what happened — traffic went up, conversions went down, mobile users increased — but it can't tell you why or what to do about it. That requires context the script doesn't have: your client's business model, their campaign calendar, competitive dynamics in their market.
The pattern I follow: automate the data collection and formatting, but always add a human interpretation layer before the report goes to the client. I review the automated draft, add strategic commentary, and adjust the tone based on how the relationship is going. That takes about five minutes per report instead of the 90 it used to take to build the whole thing manually.
Also worth noting: if a client is paying you for reporting as a standalone service, automating it and keeping the same price is a judgment call. Some consultants drop their rates when they reduce effort; others keep pricing the same because the value to the client hasn't changed. I lean toward the latter — clients pay for insights, not hours — but that's a business decision you'll need to make.
Getting Started with Your Own Analytics Automation
If you want to build this for your own client base, start with one client and one report type. Pick the client whose reporting process is most standardized — same metrics every time, predictable format. Build the script for them, test it over a few cycles, and refine the logic until it matches what you'd write manually.
Then expand. Once you have one working template, adapting it to other clients is fast. The data pull logic stays the same; you just adjust which metrics you're requesting and how the insights are phrased.
The tools you'll need:
- Google Cloud account with Analytics Data API enabled
- Python environment with the
google-analytics-dataclient library - Claude Code for writing and iterating on the script
- A way to schedule the script (cron job, GitHub Actions, or a simple scheduler like Zapier)
Total setup time for the first implementation is about 4–6 hours if you're comfortable with APIs. After that, each additional client takes 30–45 minutes to configure.
If you're running a marketing agency or freelance consultancy in Vancouver and want a faster path to this, I walk clients through the full build in my client reporting automation workflow. You can also check the FAQ for common questions about API rate limits and cost.
The leverage is real. You're already doing this work. The question is whether you want to keep doing it manually or give those hours back to yourself.