Add Analytics
Count visitors and the actions that matter (signups, clicks on Buy) with Umami: open source, no cookies, one script tag.
Before you launch, decide how you’ll know whether it’s working. Page views alone won’t tell you. You need to see how many people arrived, where they came from, and how many did the one thing you care about, such as joining the waitlist.
This guide uses Umami, an open-source analytics tool. It sets no cookies and collects no personal data, which keeps the setup simple. You can use the hosted version (free for small sites) or run it yourself later. The site is Astro, but the same steps work for any HTML page.
What you’ll have at the end
- Page views, referrers, countries, and devices for every page.
- Named events for the actions that matter:
waitlist-signup,buy-click. - Campaign tracking, so you can tell which post or newsletter brought people in.
- One number to watch: visitors who signed up, divided by visitors.
Before you start
- A deployed site on a real domain (see Ship It). You can add the script before deploying, but nothing is recorded until real visitors reach that domain.
- A free Umami Cloud account → https://umami.is, or your own Umami instance.
Step 1: Create the website in Umami
In Umami: Settings → Websites → Add website. Enter a name and your domain (without
https://). Open the new site’s settings and copy the Website ID, a UUID like
94db1cb1-74f4-4a40-ad6c-962362670409, and the tracking script URL it shows.
Step 2: Add the script to every page
Put it in the <head> of the layout every page uses. In this repo that’s
src/layouts/Base.astro:
<head>
<!-- ...existing tags... -->
<script
is:inline
defer
src="https://cloud.umami.is/script.js"
data-website-id="YOUR-WEBSITE-ID"
data-domains="yourdomain.com"
></script>
</head>
Two attributes matter here:
is:inlinetells Astro to leave this tag alone. Without it, Astro tries to bundle the script like your own code and the tracker doesn’t load as expected.data-domainslimits tracking to your real domain, so visits fromlocalhostand preview URLs don’t pollute your numbers.
Deploy, visit your site, and open Umami. Your visit appears in the realtime view within a few seconds.
Gotcha: if nothing shows up, check whether your own ad blocker is blocking
cloud.umami.is. Many do. Try another browser, and expect your numbers to undercount slightly for the same reason.
Step 3: Track the actions that matter
Page views tell you about traffic. Events tell you whether the page works. Pick two or
three actions, no more, and name them consistently in lower-kebab-case.
For clicks, use an attribute. No JavaScript needed:
<button id="buy" data-umami-event="buy-click">Buy now</button>
<a href="/pricing" data-umami-event="pricing-click">See pricing</a>
For outcomes, fire the event in code, after success. In the waitlist form from
Build a Waitlist Page, add one line inside the if (res.ok) branch:
if (res.ok) {
window.umami?.track("waitlist-signup");
// ...existing success message
}
And tell TypeScript the global exists, in src/env.d.ts:
interface Window {
umami?: { track: (event: string, data?: Record<string, string | number>) => void };
}
The ?. matters: when the tracker is blocked, window.umami is undefined and the signup
must still succeed.
Track the outcome, not the attempt. Firing
waitlist-signupon submit counts typos and failed requests. Fire it after the server says yes.
Never put personal data in events. No emails, names, or user IDs in the event name or its data. The signup itself lives in your database; analytics only needs the count.
Step 4: Tag your links so you know what worked
When you share the site, add UTM parameters to the link. Umami reads them and groups visits by campaign:
https://yourdomain.com/?utm_source=twitter&utm_campaign=launch
https://yourdomain.com/?utm_source=newsletter&utm_campaign=issue-12
Use the same utm_source spelling every time (twitter, not Twitter and x.com), or
the same channel gets split across rows.
Step 5: Read it once a week
Open Umami and filter to the last 7 days. Write down three numbers:
| Number | Where it comes from |
|---|---|
| Visitors | the dashboard’s visitor count |
| Signups | the waitlist-signup event count |
| Conversion | signups ÷ visitors |
Then look at referrers and UTM sources for the one that brought the highest conversion, not the most visitors. Ten visitors and three signups from a niche forum beat a thousand visitors and two signups from a big launch site.
Your database is the source of truth for counts. If Umami says 40 signups and your
waitlisttable has 46, the table is right; some visitors block the tracker. Use analytics for rates and sources, and the database for totals.
Optional: Host Umami yourself
Umami is a Next.js app with a Postgres database. When you want the data on your own
infrastructure, it runs from its official Docker image on any small server; follow the
install guide at https://umami.is/docs. Afterwards, change the script src to
https://your-umami-host/script.js. Nothing else in this guide changes.
You now have
Privacy-friendly analytics on every page, named events for the actions that matter, and campaign tags that tell you which channel converts. Check the three numbers weekly and spend your time on the source that works.
Troubleshooting
- No data at all → the domain in
data-domainsdoesn’t match the site exactly (www.counts), or the Website ID is wrong. - Script doesn’t load in production → missing
is:inline, so Astro rewrote the tag. - Events never appear → the event fires before the tracker loads, or only in a branch
that doesn’t run. Check the browser console for
window.umamiand test the click again. Property 'umami' does not exist on type 'Window'→ add the declaration tosrc/env.d.ts.- Do I need a cookie banner? Umami sets no cookies and stores no personal data, which is why many sites run it without one. Rules differ by country; check yours.