How to build an AI marketing analyst with BigQuery, Dataform and Claude hero image

How to build an AI marketing analyst with BigQuery, Dataform and Claude

28 Nov 2026 • 19 min read

Letting an AI loose on your raw GA4 data is a quick way to get confident, wrong answers. Here's how I built a marketing data warehouse in BigQuery and Dataform, put a Claude MCP server on top, and ended up with an AI marketing analyst that gets the numbers right and tells you when it can't. There's also a blueprint at the end you can load into Claude to build your own.


Every marketing team has a similar slew of questions. Which channels drove sales last week? What's our cost per lead on brand search? Why did the checkout funnel drop on mobile?

The obvious shortcut is to connect an AI straight to BigQuery and let it write the SQL itself. I understand why - it's quick to set up, and it looks great in a demo.

Then you look at what it's actually doing. The GA4 export is nested, event-based and full of edge cases. Consent decides which rows you're allowed to count. "Conversions" means something different in GA4, Google Ads and Meta. Attribution has several defensible answers depending on the model. An AI writing SQL from scratch has to get all of that right, every time, for every question - and when it gets it wrong, the answer still looks completely plausible.

To be fair, human analysts get things wrong sometimes too. The problem with an AI writing its own SQL is that nobody can tell when it messes up.

An AI analyst is only as good as the definitions sitting underneath it, so I flipped it round. The warehouse makes every hard decision once, in code, with tests, and the AI gets a small set of safe, fixed tools on top. Its job is to pick the right tool and the right parameters - it never writes SQL and it never does the maths.

How it works

What an MCP server does

MCP (Model Context Protocol) is an open standard for giving AI assistants tools. You run a small server that says "here are the things I can do, and here's what each one needs", and an assistant like Claude can call those tools mid-conversation.

That means people can add the analyst to Claude as a custom connector, sign in, and ask questions in plain English. Claude does the conversation - working out what they're asking, following up, explaining the result. The MCP server does the data - fetching exactly the numbers the warehouse defines, with the caveats attached.

That split is the whole design. Claude is brilliant at language, but it shouldn't be your source of truth for what a conversion is.

The main alternatives are Looker's conversational analytics or a BigQuery data agent, both within the Google world, but I went with an MCP instead for three reasons. It lives in Claude, where the team already works, rather than in another tool they have to remember to open. MCP is an open standard, so the same server can sit behind Claude today and Microsoft Copilot tomorrow - it isn't tied to one AI vendor. And the definitions, caveats and context are owned in code, version-controlled and tested, rather than configured in a vendor's UI.

Note: you'll need a Claude plan that supports custom connectors. On Team or Enterprise, an Owner can add the connector once for the whole organisation, and on individual plans each person adds it themselves.

Who it's for

Despite the name, this isn't really a tool for analysts - think of it as the next step on from self-serve reporting.

I think dashboards have had their day. They're meant to help marketers make informed decisions, but most of them need a manual or a training session before anyone can use them properly, and they're usually locked down so that changing anything means raising a ticket with someone else and waiting. So people end up working with the numbers they were given rather than the ones they actually need. Building dashboards was a core part of my job even a year ago, and now I can't remember the last time I built a 'traditional' one (i.e. in Data Studio or Power BI). The AI analyst lets marketers ask the question they actually have, in plain English, including the follow-ups nobody thought to build a chart for, and get an answer with the context attached.

Human analysts, however, get something extra. They get the same bespoke marketing analyst MCP sitting alongside the standard BigQuery MCP, so they can go from a quick answer to a proper deep dive analysis in the same session. To stop the BigQuery MCP wandering across every dataset in the Google Cloud project, I always write and share a skill that points Claude at the core fact and dimension tables, explains the conventions, and keeps it away from the raw exports and staging tables unless it genuinely needs them.

And yes, that does mean the AI writes SQL for the analysts. The rule isn't that AI should never write SQL - it's that it shouldn't write SQL for someone who can't check it!

Keep it specialised

This is deliberately a 'marketing analyst', and not a 'data analyst'. Every tool description gets loaded into Claude's context on every question, so piling finance, product and other departments into the same server makes each answer slower and more expensive, and gives Claude more ways to pick the wrong tool.

On top of that, the same words mean different things to different teams - "sales" to finance is different to marketing, and a "conversion" in product isn't always the same in marketing. A do-it-all analyst ends up spending half its time explaining which one it means, with one set of access rules and caveats for audiences that need different ones.

My rule of thumb is specialised on top, shared underneath. If another team wants one, build them their own, with its own name and its own red lines - split by audience, not by table, so people aren't juggling ten connectors. But keep the same warehouse and metrics register underneath, or you'll end up with two analysts giving two different answers to "what was revenue last month?".

The architecture

Everything runs in Google Cloud, with Claude on the front:

  • Sources - whatever marketing data you can land in BigQuery. For example, the GA4 export, ad platforms like Google Ads and Meta Ads through the BigQuery Data Transfer Service, and any other sources you use, such as a CRM or booking system.
  • Dataform - transforms raw data into staging, core and reporting layers, with assertions (data tests) throughout.
  • Daily orchestration - an event-driven Cloud Workflow that runs Dataform as soon as the day's GA4 data lands.
  • The MCP server - Python, on Cloud Run, reading only the reporting tables. For this post I'll call it "Flippy" (more on names later).
  • Claude - the interface. Users connect it once and sign in to auth their access.

Architecture diagram: GA4, Google Ads and Meta Ads flow into Dataform's staging, core and reporting layers in BigQuery. Flippy, the analyst MCP, reads reporting; the BigQuery MCP with the analyst skill reads core; both connect to Claude
Marketers ask Flippy. Analysts get Flippy and the warehouse.

The MCP server is cheap to run, too - Cloud Run scales to zero and each question is one small query against small reporting tables, so it comes in under 25p per 1,000 calls.

It's also easy to add new data sources later. Another ad platform, for example, is a new connection, a staging model and an entry in the ad platform config, and the reporting tables and tools pick it up from there.

Building the marketing data warehouse in Dataform

I used Dataform rather than dbt because it lives inside BigQuery, needs no extra hosting, and the JavaScript includes made shared definitions (columns, metrics, attribution models) easy to keep in one place. dbt would work fine with the same patterns, though.

Three layers, each with one job

  • Staging (stg_, int_) - one model per source table. Rename, cast, clean, unnest GA4's event parameters. No business logic yet.
  • Core (fct_, dim_) - the business facts and dimensions: events, sessions, users, conversions, ad campaign stats, channels, dates. Keeps IDs and raw source values, nested where it helps. This is where human analysts (with the companion skill) do their work.
  • Reporting (rpt_..._daily) - flat, daily, additive tables built for one purpose each. No nesting, no personal data. This is the only layer the AI analyst MCP can see.

Alongside those sit two small tables that do a lot of the heavy lifting: a data freshness table (so every answer can say how current it is) and a metrics register (more on that below).

The three Dataform layers - staging, core and reporting - with example model names in each
Staging cleans, core models the business, reporting serves the questions.

The conventions that made the AI reliable

Most of the reliability came from boring rules, enforced by CI so nobody (including Claude) could quietly break them.

One name, one definition. Every column in core and reporting is declared once, in a shared dictionary file, along with the tables it appears in - add() for dimensions, metric() for measures. Model configs pull their descriptions from it. If a PR adds a column that isn't in the dictionary, the build fails.

metric(
  "web_sessions",
  "Sessions that started on the day, consented users only.",
  ["rpt_channel_daily", "rpt_web_traffic_daily"],
);

No stored ratios. Reporting tables hold the parts - sessions, conversions, spend - never the conversion rate or ROAS. Ratios are calculated at query time from summed parts. It might sound pedantic (some say I put the 'dan' in pedantic), but it only takes one person averaging a column of daily conversion rates to get a number that's quietly wrong. Store the parts and every breakdown, rollup and comparison adds up properly.

No NULLs. Missing values get explicit labels of _unconsented, _na and _unknown - applied in a fixed order. A NULL could mean "zero", "not tracked" or "user said no to cookies", and an AI will just guess which. The one deliberate exception: ad spend is NULL on channels with no ad platform connected, so "we don't have spend data" never shows up as "£0 spend".

Attribution goes in the name. Every attributed number says which model produced it. On tables that hold several models, the model goes on the metric (attribution_first_conversions, attribution_last_non_direct_conversions). On tables that hold one model, it goes on the dimension (attribution_last_non_direct_channel). It's never both and never neither, and CI checks that too. I hold three basic models: GA4's last non-direct click (traffic acquisition), GA4's first click (user acquisition), and what each ad platform reports itself. The beauty of this architecture is that we can easily build our own attribution models, but more on that in a future blog...

Consent is explicit. Mixed tables carry a consent status. Session-based metrics are consented-only, and every answer says so. (More on why I force this in my other blog post consented or modelled data.)

The metrics register

Every metric is defined in one code file: its formula, inputs, unit, whether it's additive, who it covers, a technical definition - and a plain-English one. Dataform builds that into a metrics_register table.

When someone asks "how are you calculating ROAS?", the analyst reads the answer straight from the register - the same definition the warehouse uses, word for word. And if the MCP ever returns a metric that isn't registered, it still answers, but logs a warning.

Running it every day

GA4's daily export table doesn't land at a fixed time - some days early morning, some days mid-afternoon, occasionally a day late. So the daily run is triggered by the table arriving rather than by the clock, and anything merged to main is live on the next run. The full setup is in the blueprint at the end.

The daily run: the GA4 table lands, a log sink publishes to Pub/Sub, Eventarc starts a Cloud Workflow, which runs Dataform and alerts Slack
Run when the data lands, not when the clock says so.

Designing the MCP server

Fixed tools, not free SQL

The server exposes a handful of tools:

  • describe_available_data - what's available, how fresh it is, and what it can't answer
  • get_metric_definitions - reads the metrics register
  • request_help - the "I can't answer that" path
  • One data tool per reporting table, for example:
    • get_channel_performance - conversions by channel, under any of the three attribution models (or all three side by side)
    • get_web_traffic_performance - sessions, engagement and landing pages
    • a funnel tool - each step of the conversion journey and the drop-off between them
    • get_ad_campaign_performance - spend, clicks, CPC, platform conversions, ROAS and cost per conversion
    • get_cookie_consent_rates - consent rates and the counts behind them

The tool descriptions are the model's only guide to when to use each one, and more of the quality came from rewriting those descriptions than from any new feature.

Each data tool is driven by a spec that lists exactly which metrics, rates, breakdowns and filters it allows. Nothing a user types ever reaches SQL except as a bound parameter, and column names only ever come from the spec.

CHANNELS = Spec(
    table="rpt_channel_daily",
    base={  # name: (SQL, returned by default)
        "web_sessions": ("SUM(web_sessions)", True),
        "attribution_last_non_direct_conversions": ("SUM(attribution_last_non_direct_conversions)", True),
        "attribution_last_non_direct_conversion_value": ("SUM(attribution_last_non_direct_conversion_value)", True),
        "ad_spend_gbp": ("SUM(ad_spend_gbp)", True),
    },
    rates={
        "conversion_rate": Rate("attribution_last_non_direct_conversions", "web_sessions", kind="rate", places=4),
        "roas": Rate("attribution_last_non_direct_conversion_value", "ad_spend_gbp", kind="ratio", places=2),
    },
    breakdowns=["channel", "channel_type"],
    filters=["channel"],
)

Each tool also answers in one query - totals, every breakdown, the comparison period, ranking and trimming, all in one statement - and comparisons happen in SQL, so the model never subtracts one result from another. On one build, that took a funnel question from 8 calls at 10-75 MB of BigQuery each down to 1 call, around 14 MB, in under a second.

Breakdowns matter more than they look, too. If device is a filter rather than a breakdown, comparing devices costs one call per device, so the model takes the cheap route and quotes the blended total - which on one build hid a 20-point gap between desktop and mobile.

Guardrails, split by who enforces them

It pays to be clear which tier each guardrail actually sits in:

  • Infrastructure - the bits no prompt can talk its way around. A read-only service account that sees the reporting tables and nothing else, so staging, core and the raw exports are physically out of reach. A hard cap on bytes billed on every query.
  • Server code - deterministic, runs every time. A dry run first and a refusal above 200 MB. A 1,000-row cap with an explicit truncation flag. A default of the last seven days when nobody gives a date range, anchored to the latest date actually in the table rather than today - because when the export lands late, anchoring to today returns empty days and reads as broken tracking.
  • The prompt - advisory only. It's useful, but at some point some model will ignore it, so it should never be the thing you rely on.

Give it a name

Every AI marketing analyst MCP I've built has a name, like Flippy here. It sounds like a gimmick, but it genuinely does two useful jobs.

First, adoption. "Ask Flippy" is easier to say, remember and share round a team than "use the marketing analyst MCP connector". It's also a bit of fun, which never hurts when you're asking people to change how they work.

Second, and more usefully, it makes Claude more efficient. The name goes into the server instructions and the start of every tool description, and people learn to start their questions with it - "Flippy, how did paid social do last month?". Claude then knows straight away which connector and tools to use, rather than working out for itself whether the question is for this MCP, the BigQuery MCP or a web search. That means fewer wrong turns and fewer wasted calls.

One rule: it's a name, not a persona - no character, no voice, and the figures are always attributed to the data.

Each one gets an avatar too - a tent for Bivvy, a shield for Rusty, a skateboard mid-kickflip for Flippy. It goes on the setup guide, the launch posts and the artifacts Claude builds from the analyst's numbers.

Three analyst avatars: Flippy the skateboard, Bivvy the tent and Rusty the shield
Flippy, and two friends.

What a question actually looks like

Someone asks Claude: "Flippy, tell me what happened last week compared to the previous week, specifically for our marketing".

Claude starts with the channel tool:

{
  "tool": "get_channel_performance",
  "period": "last_7_days",
  "compare_to": "previous_period",
  "breakdown_by": ["channel"]
}

It then calls get_ad_campaign_performance for the paid media detail, i.e. spend, impressions, click-through rate and what each ad platform reports for itself.

The server returns totals, a row per channel, the change against the previous period, and - just as importantly - the context Claude needs to answer honestly: the exact dates used, who's included (consented sessions only), which attribution model was applied, how fresh the data is, and notes like "this period contains a partial week" or "conversion rate on fewer than 100 sessions". Claude turns that into a plain-English answer, with the caveats where they belong.

It's important the caveats only show up where they actually apply, though. The consent caveat only appears on tables that are genuinely consent-filtered - put a caveat on everything and nobody reads any of them.

Claude answering
One question, caveats included

When the answer is "I don't know"

Not being able to answer should be a proper path, rather than treated as a failure. If someone asks something the warehouse can't answer - say, revenue from a finance system that isn't connected - Claude calls the request_help tool, which:

  1. Redirects if another tool can actually answer it (with the exact call to make).
  2. Names the specific gap - not a generic "I can't do that".
  3. Gives a partial answer where possible - here's what we can say, and the calls that get it.
  4. Drafts the data request to the right person, with the question, why it matters and what data would be needed.

Claude answering
No TikTok spend and no profit data, so it says what's missing and answers what it can.

Every request_help call gets logged, so the refusals become the roadmap, built from what people actually asked for rather than what we guessed they'd want when we scoped the tables.

Authentication and monitoring

Authentication: an allowlist, not an access system

I deliberately kept this simple. Signing in with Google through the Claude connector only confirms who the person is. The server checks the token was issued for this connector, that the email is verified, and that its domain is on an allowlist. If all three pass, they're in.

No managing or refreshing user tokens, no per-user BigQuery permissions, no roles to maintain. Users never get access to BigQuery at all - the server queries it with its own service account, which can read the reporting tables and nothing else. Adding a new team or client domain is one setting, and the client secret lives only in Claude's connector settings - not on the server, not in the repo.

The trade-off: anyone with an allowed email sees everything the tools expose, and where a client runs Microsoft 365, people sign in with Google accounts on their work addresses, which the client's IT doesn't control. That's fine for read-only, aggregated reporting numbers - and it's exactly why the reporting layer holds no personal data. I'd revisit it the day revenue or customer data lands, though.

Logging what people were trying to do (not what they said)

I don't track anyone's prompts - their conversation with Claude stays in Claude.

What I do log is the tool call itself: who called it, which tool, the parameters (period, breakdowns, filters), the outcome, rows returned, bytes billed and how long it took. When request_help is called, it also records a short description of what they were trying to find out.

I've built a few of these now, for different clients, and they all log in the same shape, so I built a Claude dashboard artifact that pulls the logs from all of them into one view. It shows me usage over time, which tools get called, what each call costs, where things fail, and - the most useful bit - every time an analyst couldn't help and what the person was after.

The monitoring dashboard's log of help requests, empty results and errors across the Bivvy and Rusty analyst MCPs, showing when each happened, which tool was called, and the question or parameters behind it
Every help request, empty result and error, across every analyst MCP.

How I tested it

I built the warehouse against a 3-day sample first, so changing my mind about the model ten times a day cost pennies. It then had to pass three sign-off gates: checked on the sample, full history reconciled to the ad platform UIs by month (spend landed within about 0.01%, all down to days the platform had adjusted after the fact), and two clean automatic daily runs in a row.

That last gate is why the whole build takes about a week, assuming the raw data is already in BigQuery. The build itself is quick, but much of that week is waiting for the daily processes to trigger on the following day so the whole run can be tested end to end. That doesn't include any new data engineering, such as building pipelines for sources without a native BigQuery connector.

For the analyst, I wrote a bank of the 15-20 questions the marketing team actually asks and checked every answer against a hand-written query, then the red lines: no date given, a question that's too big, data we don't hold, a sign-in from the wrong domain.

The most useful test was the simplest, though - I opened a fresh Claude chat and used it like a marketer would. I substantially rebuilt the MCP toolset the same day, just off the back of that one session!

Build your own AI marketing analyst

I've turned everything I learned into a blueprint you can load straight into Claude - the discovery questions, the phases and gates, the Dataform conventions and repo layout, the daily orchestration, the MCP design, naming, sign-in, logging, the source quirks and the full list of gotchas. There's space left throughout for your own decisions and your own spin.

Download the blueprint marketing-warehouse-mcp-blueprint.md, drop it into Claude or your CLAUDE.md, and ask Claude to help you scope your version. It'll start by asking you questions rather than jumping straight into code.

If you build one, I'd love to hear what you do differently! Easiest is to message me directly on LinkedIn.