Sitebase
All articles

How to add analytics to a site built with Claude Code

Give Claude Code a precise installation prompt, check pageview tracking, and use the first numbers to improve your website.

Claude Code can build your website and publish its pages. To find out whether anyone visits them, you need to install analytics.

Start with a few questions you can act on. Which pages get visitors? Where do those visitors come from? Are people reaching the page with your signup form?

Sitebase includes cookieless visitor analytics. Its tracker reports pageviews to the dashboard and supports client-side navigation.

Sitebase is currently in private beta. The instructions below assume you have dashboard access. You can join the waiting list if you’d like to use it when access opens.

Enable analytics for your website

Create your website in Sitebase with Analytics selected, or enable it from + Add more on an existing site.

Open Analytics in the sidebar, then its Setup tab. Copy the site-level tracking snippet.

Notice the attribute data-sitebase-site. It identifies the website being measured. Feature embeds use data-sitebase-widget instead; don’t swap those keys when installing the tracker.

Ask Claude Code to install the snippet

The tracker belongs in the shared layout so it loads on every public page. For a plain HTML site without a shared layout, it needs to appear in each page you want to measure.

Give Claude Code the real snippet from your dashboard, together with this instruction:

Add the Sitebase analytics snippet below to the shared layout used
by every public page. Preserve its script URL and data-sitebase-site
attribute exactly. Check for an existing Sitebase tracker first so
we don't install it twice. If this is Astro, use is:inline to keep
the external script unchanged. Tell me which file you changed and
how I can verify tracking on the published site.

Here’s the snippet format. YOUR_SITE_KEY must be replaced with your website’s public key:

<script
  async
  crossorigin="anonymous"
  src="https://sitebase.dev/embed.js"
  data-sitebase-site="YOUR_SITE_KEY"
></script>

The public site key is safe to include in browser code. Installing analytics doesn’t require giving Claude Code a private Sitebase API key.

If the project uses a frontend framework, ask the agent to inspect how its document layout loads third-party scripts. The exact file depends on your project. Keep the installation in the shared layout rather than letting the agent add a separate copy to each component.

Check the published site

After publishing, open the public URL and visit a couple of pages.

Return to Sitebase’s Analytics page. The first recorded pageview should make the data view available. Check that the pages you visited appear in the report.

For a site with client-side routing, click between pages without reloading. Check that those navigations appear too. Then reload a page directly to cover both entry paths.

If nothing appears, open your browser’s Network panel. Look for the request loading embed.js, followed by a request to /v1/event. Check whether an extension, a content security policy, or a network error blocked either request. An accepted event request is a useful clue; the dashboard is where you confirm the recorded result.

A browser with a content blocker may suppress analytics. Test once in a clean browser profile before changing the installation.

Avoid duplicate installation

A Sitebase feature embed also reports pageviews. If you already have a waiting list or contact form on a page, account for that when adding the site-wide tracker.

Ask Claude Code to inspect all existing Sitebase snippets and preserve the feature embeds. You still want site-level tracking on pages that have no feature.

You don’t need to build your own route-change listener for Sitebase’s standard tracker. Test its existing navigation tracking before adding more code.

Use the numbers to make a decision

The first report can help you spot basic issues. If visitors reach your homepage but rarely open the contact page, check whether the contact link is visible. If an article brings visitors, make sure its next step is relevant to that article.

For more specific actions, Sitebase also has custom events and funnels. Add those when you have a concrete question, such as how many visitors start and finish a signup flow.

See the analytics documentation for the available reports. If you’re adding email capture next, follow the waiting list tutorial.