DEV Community

ImageAPI AI
ImageAPI AI

Posted on

Ask Claude Code why your traffic spiked (an MCP walkthrough)

Disclosure: I built measuremy.site, the analytics tool used in this post. All the numbers below are from my own site, including the unflattering ones.

I check analytics dashboards about once a week, and when I do, I mostly look at the chart, see a bump, and move on without knowing what caused it. What I actually wanted was to ask "why did traffic jump on Monday?" in the same place I already work, my terminal with Claude Code open, and get an answer with numbers.

This walkthrough connects website analytics to Claude Code over MCP (Model Context Protocol), then uses it to answer three questions about a real site:

  1. How is traffic doing?
  2. What caused that spike, and was it even human?
  3. Did the post I published actually bring anyone?

1. Connect the MCP server

The server is remote and signs in with OAuth, so there's no API key to paste into a config file. In Claude Code:

claude mcp add --scope user --transport http measuremysite https://a.measuremy.site/mcp
Enter fullscreen mode Exit fullscreen mode

--scope user makes it available in every project, not just the current one. Restart Claude Code (claude -c keeps your conversation), run /mcp, pick measuremysite and choose Authenticate. A browser window opens, you sign in with an emailed code (or start the trial) and pick the site.

If you haven't added tracking to your site yet, you can skip the steps above and paste one sentence instead. The agent connects the server, asks you to sign in, and adds the script tag to your layout:

Add measuremy.site analytics to this project: connect the measuremy.site MCP server at https://a.measuremy.site/mcp for all my projects (claude mcp add --scope user; it signs in with OAuth, no key, and one sign-in covers every site), then tell me how to sign in. Details: measuremy.site/llms.txt
Enter fullscreen mode Exit fullscreen mode

The tracker itself is one deferred script tag with no cookies, so there's no consent banner to add:

<script defer src="https://a.measuremy.site/t.js" data-key="pk_..."></script>
Enter fullscreen mode Exit fullscreen mode

Cursor, VS Code, Codex and Gemini CLI connect to the same URL; the config for each is in the MCP docs.

2. "How is traffic doing?"

My first question was "give me an overview of the last 30 days". Claude calls get_overview and get_timeseries, and gets back plain JSON:

{
  "pageviews": 1066,
  "visitors": 478,
  "top_sources": [
    { "name": "(direct)", "visitors": 362 },
    { "name": "google.com", "visitors": 45 },
    { "name": "news.ycombinator.com", "visitors": 40 },
    { "name": "reddit.com", "visitors": 12 }
  ]
}
Enter fullscreen mode Exit fullscreen mode

The interesting part was the daily series, which Claude summarised better than the chart did for me:

Day Visitors
Oct 3 (launch: Show HN + Reddit) 115
Oct 4–8 36–71
Oct 9–13 11–20

That's the classic post-launch decay. Its follow-up observation was the useful one: almost everything I'd done since launch (directory listings, docs, SEO pages) pays off over weeks, so nothing was replacing the launch traffic in the short term. Fair.

3. "What caused that spike? Was it a bot?"

Next: "find the traffic spikes in the last two weeks and explain the biggest ones". Claude calls find_traffic_spikes.

How a spike is detected matters, so here's the method. Every hour is compared with the same hour of the week in earlier weeks, so a quiet Sunday night and a busy Monday morning each have their own baseline. An hour counts as a spike when it has at least 10 extra pageviews and is at least 50% above normal. Then each spike's causes are ranked: which source, landing page and event rose above their own normal level.

Here's one from my site (trimmed):

{
  "start": "2026-10-08T22:00:00Z",
  "pageviews_above_baseline": 26,
  "causes": [
    { "kind": "source", "name": "google.com", "lift": 28, "share_of_spike": 1 },
    { "kind": "page", "name": "/login", "lift": 6 },
    { "kind": "page", "name": "/docs/install", "lift": 4 }
  ],
  "likely_bot": {
    "pageviews": 28,
    "seconds": 9,
    "browser": "Chrome",
    "os": "Linux"
  }
}
Enter fullscreen mode Exit fullscreen mode

On a dashboard, that hour looks like a nice burst of Google traffic. In fact it was 28 pageviews in 9 seconds, all Chrome on Linux: a crawler with a Google referrer. The spike's summary says plainly not to count it as a marketing win, which is exactly the mistake I'd have made by eyeballing the chart.

The biggest real spike was on Oct 5: +32 pageviews in one hour, 98% of it direct traffic landing on the homepage and the live demo. "Direct" is the unhelpful answer: those visits came from somewhere, I just hadn't tagged the link. Which leads to the third question.

4. "Did my post bring anyone?"

The fix for "it was all direct" is to tag every link you share. You can ask Claude to do it as part of writing the post:

"I'm posting this on Reddit, make me a tracked link to the homepage."

It calls create_tracked_link, which returns a UTM-tagged URL and logs the campaign so later visits and signups are credited to it. A few days later:

"How did my Reddit post do?"

get_campaign_results answers with real numbers. My launch-week Reddit post:

{
  "campaign": "reddit-launch",
  "visitors": 12,
  "converted_visitors": 0,
  "first_visit": "2026-10-04T03:47:23Z",
  "last_visit": "2026-10-04T18:52:36Z"
}
Enter fullscreen mode Exit fullscreen mode

Twelve visitors over about 15 hours and nothing after that. That's humbling, but it's useful: a Reddit post's life is about a day, so judge it the next day and move on.

The same query showed me something worse: five tracked links I'd created on Oct 6 had zero visits. Those posts either never went out or were removed by moderators. I wouldn't have noticed without asking.

Two more habits make this loop work:

  • Log what you do. When you publish, deploy or send an email, ask Claude to add an annotation ("record that I posted on dev.to"). Spikes list any annotation from the 24 hours before them, so the cause sits next to the jump.
  • Ask what to do next. get_growth_actions ranks channels and pages by what converted and suggests what to repeat. It's only as good as your tagging, which is another reason to tag everything.

What I'd tell myself a month ago

  • Ask questions, don't stare at charts. "Why did X happen?" gets a ranked answer; a chart gets a shrug.
  • Assume spikes are bots until shown otherwise. One in my top three was.
  • Tag every link you share. "Direct" was 76% of my visitors, and most of it is unexplained because I didn't.
  • Expect launch traffic to decay within days. Plan the next thing before the launch, not after.

Try it

You can browse the live dashboard for my own site, with the same data as above, no signup: measuremy.site/share/measuremy.site.

To connect your own site, the Claude Code setup guide has the one-sentence prompt. There's a 30-day free trial with no card, then paid plans.

If you try it, I'd like to hear one thing: did the install work first time in your agent? And what would you want to ask about your own traffic that this can't answer yet?

Top comments (0)