Blog

· 3 min read

Set up analytics from Claude Code in a minute

Hark's MCP server can add a site, put the tracking snippet in the right file of your codebase and check that events arrive, all from your coding agent.

  • MCP
  • Setup

Adding analytics to a site usually means leaving your editor: sign up, find the snippet, work out where your framework wants it, deploy, then come back to the dashboard to see if anything arrived. If you already have a coding agent open in the repository, it can do all of that for you.

Hark, a cookieless Google Analytics alternative, has an MCP server with tools for setting a site up as well as for reading its stats. Connect it once and you can ask your agent to add Hark to the project it's working on.

Connect Hark to Claude Code

Start a free trial (no card), create a key on the API keys page, then add the server:

claude mcp add --transport http hark https://harkstats.com/mcp --header "Authorization: Bearer YOUR_KEY"

Cursor, VS Code and other MCP clients work too; the setup instructions have the config for each. Claude and ChatGPT can connect without a key, by signing in.

Ask for it in plain English

In the repository for your site, ask something like:

Add Hark analytics to this site. The domain is example.com and we're in London.

The agent then works through the setup tools:

  1. create_site adds example.com to your account with the Europe/London timezone and returns its tracking snippet.
  2. get_install_instructions says where the snippet goes for your framework. For a Next.js App Router project, that's the <head> of app/layout.tsx. There are guides for plain HTML, Next.js, Astro, WordPress, Webflow, Ghost, Phoenix and Vite (which covers React, Vue, Svelte and SvelteKit).
  3. The agent edits the file. The snippet is one line:
<script defer data-domain="example.com" src="https://harkstats.com/js/script.js"></script>
  1. Once you've deployed and opened the site, check_install confirms events are arriving. If they aren't, it lists what to check: that data-domain matches, that a cache isn't serving an old copy of the page, that an ad blocker isn't blocking the script, and that localhost visits only count with data-local.

The script is under 1 KB, sets no cookies and needs no consent banner, so there's nothing else to add.

Goals, funnels and campaign links

The same conversation can go further. Ask the agent to track a signup and it can add a custom event where your form succeeds:

window.analytics?.("Signup", { props: { plan: "pro" } })

Then:

  • save_funnel saves a funnel such as "pricing page, then signup" on your dashboard.
  • create_campaign_link builds a link with utm_source, utm_medium and utm_campaign for your newsletter or a post, and keeps it with the site so its visits are easy to find.
  • update_site changes the timezone, or counts a staging domain's events alongside the main one.

And when there's some traffic, ask about it: "Where did yesterday's visitors come from?" uses the same server's stats tools.

What it can't do

The tools that change things say so in their descriptions, so your client can ask before using them. None of them deletes anything, makes a dashboard public or touches billing: those stay on the dashboard, where you can see what you're doing.

The MCP server is on every plan, including the $5 Starter plan and the free trial. Try it on your own site.

Try Hark on your own site

Cookieless analytics with a live visitor map, funnels and an MCP server on every plan. 14 days free, no card.

More from the blog