Self-hosted analytics on AWS: Umami, access logs, web vitals
In 2022 I wrote that you could run your own web analytics for free, with Umami on Vercel and its database on PlanetScale. That stopped being true: PlanetScale retired its free Hobby plan on April 8, 2024. When I looked this November, my site had no analytics at all. Nothing was reading the campaign tags on the links I was posting, and a second post from 2022 that promised self-hosted web vitals had never grown past 73 words.
This post is the replacement for both. It describes what I run now, what it costs, and what the numbers do and do not mean.
TL;DR
- The site is counted twice. Umami, on one small EC2 host, counts browsers that ran its script. A daily job archives the hosting access logs, and a script counts requests from them.
- It costs about $13.59 a month: $13.38 for the Umami host and $0.21 for the log archive. It is not free, and most of it is one virtual machine and its public address.
- No cookie is set and no IP address is kept, in either system. A database trigger enforces that for Umami, because its collection endpoint is public.
- The two counts differ by a factor of almost seven. On the first full day, Umami showed 53 page views and the logs 353. Most of the gap is automated traffic that claims to be a browser.
- One click is counted: the résumé download. Over the whole archive, bots fetched the file 118 times and browsers 59 times, and only 4 of those 59 came from a page of the site. The download now hides its address from crawlers, the way the site already hides my email.
- Core Web Vitals come from the same Umami script, with one attribute. On a Next.js site it needed a 25-line fix, because the script was reporting an early, wrong LCP. The first five days put LCP at 3.07 s at the 75th percentile, over Google's 2.5 s line, on pages that Lighthouse scores 94 to 97.
The two counts
A script in the page and a server log answer different questions.
- Umami sees a visit only if the browser loaded and ran its script. It misses visitors who send Do Not Track, who block the script, or who leave at once. It also misses bots that run no JavaScript, which is the point.
- The access logs see every request, including the ones made before I installed anything. They cannot tell a person from a program that sends a browser's user agent.
I keep both, side by side, and I do not load log data into Umami. Umami is my estimate of people. The logs are the ceiling, and the only record of crawlers, blocked scripts and 404s.
Umami on one small host
Umami now needs PostgreSQL. I compared Lightsail, a managed database, Fargate and plain EC2, and chose the cheapest option that still had backups I could restore: one t4g.micro running Umami, PostgreSQL and Caddy (for HTTPS) in Docker Compose.
- No SSH. Port 22 is closed. I reach the host through AWS Systems Manager Session Manager.
- The data is on its own encrypted volume, with a daily snapshot kept for 7 days. I tested a restore before trusting it.
- Five alarms email me: the health check failing, either disk above 80%, memory above 90%, and no snapshot for two days.
- Secrets are in Parameter Store, read at start. None is in the repository or in a file on the host.
- It fits. After a day idle, the three containers used 463 MB of the host's 904 MB.
What Billing showed for the first days, scaled to a month:
| Item | Monthly cost |
|---|---|
EC2 t4g.micro | $6.05 |
| Public IPv4 address | $3.60 |
| Two encrypted volumes, 16 GB and 10 GB | $2.08 |
| Route 53 health check over HTTPS | $1.13 |
| Five CloudWatch alarms | $0.50 |
| Snapshots | $0.02 |
| Umami total | $13.38 |
| Log archive (S3, Lambda, two alarms) | $0.21 |
The estimate before building was $13.36, so the bill matched it. The address costs more than half as much as the machine.
A database trigger, because the endpoint is public
Umami's collection endpoint accepts events from anyone. So a privacy rule in my page's script would not hold: a direct request could still store a full query string, a referrer path, or free-form data. In a test, that route stored an email address.
The rule therefore lives in the database, as a BEFORE INSERT trigger:
CREATE OR REPLACE FUNCTION umami_privacy_clear() RETURNS trigger AS $$
BEGIN
NEW.url_query := NULL;
NEW.referrer_query := NULL;
NEW.referrer_path := NULL;
NEW.url_path := split_part(NEW.url_path, '#', 1);
NEW.gclid := NULL;
-- and the other five click IDs
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
The three utm_* columns and the referring domain stay, because the campaign question needs them. A second trigger drops every row bound for Umami's event-data and session-data tables. The upgrade script re-applies the triggers and runs a check that sends marked events and reads them back, before it reopens the service.
Umami does not store IP addresses. It does store country, region and city, which it estimates from the address. I chose to keep those.
The tracker tag
One tag, in one component, rendered only by the production build:
<script
defer
src="https://analytics.jpmti2016.com/script.js"
data-website-id="…"
data-domains="www.jpmti2016.com"
data-do-not-track="true"
data-performance="true"
data-before-send="umamiBeforeSend"
></script>
Each attribute is in Umami's tracker configuration. Three of them matter here:
data-domainslimits reporting to the public hostname. Without it, a production build opened on Amplify's default domain or on my machine would report too.data-do-not-trackis opt-in. The tracker honors the browser's signal only when the tag asks it to.- The tag is absent from preview and local builds, so test traffic never reaches the dashboard.
The tests never send anything to the live service. They serve the local build under the real hostname by intercepting requests, and answer the Umami host themselves. One thing surprised me: a headless Chrome gets a 200 from Umami and is not counted. Umami recognizes it as a bot and answers {"beep":"boop"}. A 200 alone proves nothing.
The site also has a privacy page that says all of this in plain words, and every claim on it maps to a test or a checked result.
The logs: most requests are not page views
Amplify Hosting serves its access logs through GenerateAccessLogs. It does not keep them forever: when I asked for one day at a time, days up to 60 days back came with rows and days 90 days back came empty. A Lambda function now runs once a day, fetches the days that are complete, removes the visitor IP address from every row, and writes them to S3.
A local script reads the archive and applies three small rules. Over the first 71 days and 366,556 rows:
| Step | Rows |
|---|---|
| All requests | 366,556 |
Successful GET of an HTML page on the production host | 21,354 |
| Left after the bot rule | 11,161 |
| Arrived from outside the site | 8,085 |
| Of those, carrying a campaign tag | 13 |
Only 5.8% of requests are page loads, and the bot rule removes about half of those. Another 104,675 responses were "not found" pages, mostly scanners probing paths such as /wp-content/ and /.env.
The campaign number is the humbling one. The archive held 68 requests with a utm_* tag. Most were preview bots from the social networks, HEAD requests and redirects. Counting tagged rows would have overstated the campaign about fourfold.
The report says in its own output that it counts requests, not people. It cannot count unique visitors, because the archive has no addresses to group by. That is the price of not keeping them.
Umami against the logs
On 2026-11-12, the first full day with both running:
| Umami | Log report | |
|---|---|---|
| Page views | 53 | 353 |
| Visits | 35 | 277 |
| Home page | 4 visitors | 104 page views |
The logs show about 6.7 times what Umami does. The log day has a shape that fits automation: 294 of the 353 views claim to be Chrome, 97 different pages were loaded, and one hour holds 77 loads. A client that sends Chrome's user agent and never runs JavaScript counts in the logs and never reaches Umami. I cannot prove which requests were people; this is an inference from the counts.
Umami is not clean either. Of its 33 visitors that day, 19 were located in Singapore and 15 arrived in one hour, with a 91% bounce rate. Those look like automated browsers that do run JavaScript.
Neither number is "the" number, and I do not expect them to converge.
One click: the résumé download
The résumé is a PDF, so opening it is not a page view. The logs record it, and they show the problem. Over the whole archive, 82 days:
| Résumé requests | Count |
|---|---|
| Removed by the bot rule | 118 |
| Kept as downloads | 59 |
| Of those, arriving from a page of the site | 4 |
| Of those, with no referrer | 55 |
A request with no referrer can be a person with a bookmark or a crawler pretending to be a browser. The logs cannot say.
The file had a second problem. The PDF contains my email address, which the rest of the site hides behind a button that only a real click reveals. The download was a plain link in the page, so any crawler reading the page could fetch the file and harvest the address.
So the download now works like the email button:
- The page holds no address for the file. It is encoded, and only a real click or key press decodes it. A click dispatched by a script does nothing.
- The file moved to an unlisted address, served with an
X-Robots-Tag: noindexheader. The old addresses answer 404. I chose not to redirect them, because a redirect would hand the new address to every crawler that knew the old one. - The same click handler counts the download in Umami, by name only:
resume-download-enorresume-download-es. Umami's owndata-umami-eventattribute would have counted scripted clicks on a button too. - The request now carries the page as its referrer. The old link had
rel="noreferrer", which is why the logs could almost never tell a click on my own button from a direct fetch. That explains the 4 out of 59.
One finding for anyone counting PDF downloads: Chrome asks for the file twice. The new tab's request carries the referrer; Chrome's built-in viewer then fetches it again with none. So in the logs one download in Chrome is one "from the site" request and one "direct" one. The number to compare with a click count is "from the site".
This stops the cheap crawler that reads pages. A scraper driving a full browser with simulated clicks still gets the file, and anyone who downloads it can share the address.
The click count has been live since 17 November. Up to the 21st, Umami recorded four download clicks, and all four were my own checks: no visitor clicked the button. From 17 to 19 November, the logs kept 13 downloads of the old addresses after the bot rule, and 12 of those had no referrer. So the downloads the logs were showing were not people clicking on my site. (A visitor who sends Do Not Track or blocks the script would also be missing from Umami, so "not people clicking" is the likely reading, not a proof.)
I will add the before and after comparison here once two weeks have passed since the change.
Core Web Vitals from the same script
For field data I compared three ways to collect LCP, CLS and INP:
useReportWebVitals, a Lambda function URL and DynamoDB | Umami's performance mode | Amazon CloudWatch RUM | |
|---|---|---|---|
| New AWS resources | A function, its URL, a table | None | An app monitor and its access setup |
| Monthly cost at my traffic | Under $0.01 | $0 added | About $0.15 to $4.50, estimated |
| Script added to every page, compressed | 2.7 KB | 0 | 42.4 KB |
| Reading the 75th percentile per page | A script to write | Built into the dashboard | Not verified |
CloudWatch RUM costs $1 per 100,000 events. I did not measure how many events one page load produces, so its range is an assumption of 10 to 50.
I chose Umami's data-performance attribute. The script I already load measures LCP, CLS, INP, TTFB and FCP, and Umami stores them in columns it already has. On a local copy with my triggers applied, the values were stored, the query string was still cleared, and nonsense values were refused.
The fix it needed on Next.js
My tests failed the first time. One page load was sending two sets of timings.
Next.js calls history.replaceState with the same address while a page hydrates, a few hundred milliseconds in. Umami's script treats every history call as the end of a page. So it sent an early event and started over:
| When | What the script sent for the home page |
|---|---|
| 370 ms | TTFB 52 ms, FCP 260 ms, LCP 260 ms |
| 10 seconds | LCP 660 ms, CLS 0.059 |
The browser's own entries said the largest paint came at 660 ms. The early event carried a candidate, not the LCP. Stored as they came, there would be two rows per page and a 75th percentile that read too low.
The tracker has a hook for this. data-before-send names a function that sees each event before it is sent and may change or cancel it. Mine holds back an event that is early (same address, page still visible, well before the script's 10-second timer) and folds its values into the event that does end the page:
// TTFB and FCP happen once: keep the first.
// LCP candidates only get later, and CLS and INP only get worse: keep the largest.
if (early) {
fold(held, payload)
return null // cancel this one
}
fold(payload, held)
return payload // send one event, with the final values
Now each page sends one event, and a test checks that its LCP equals the browser's last largest-paint entry to within a millisecond.
What these numbers are not
- They stop at 10 seconds. The script sends after 10 seconds or when the page is hidden. Layout shifts and interactions after that are missed, so CLS and INP are lower bounds, and they will not match Search Console.
- Pages reached by a link have no LCP. The browser reports LCP, FCP and TTFB per document load. After a client-side navigation the event carries CLS and INP at most.
- Small numbers are noise. At about 50 page views a day, a percentile for one page needs weeks of data.
Google judges each vital at the 75th percentile: LCP at or under 2.5 seconds, INP at or under 200 milliseconds, CLS at or under 0.1.
The first five days
From 17 to 21 November, with 85 LCP measurements, the 75th percentile for the whole site:
| Metric | 75th percentile | Google's "good" |
|---|---|---|
| LCP | 3.07 s | at or under 2.5 s |
| INP | 62 ms | at or under 200 ms |
| CLS | 0.027 | at or under 0.1 |
| FCP | 2.58 s | not a Core Web Vital |
| TTFB | 950 ms | not a Core Web Vital |
Interactivity and layout are fine. Loading is not: LCP is over the line, and most of the time passes before anything is drawn, with almost a second before the first byte arrives. Lighthouse on my machine scores the same pages 94 to 97 for performance. That gap is the reason to collect field data at all.
I have not found the cause yet, and I am not going to guess at a fix from five days. A percentile per page needs more measurements than my traffic gives in a week; one weekly timeline post read 10.3 s, which may be a single slow visit. The next step is to see which pages and which part of the request account for the time.
What AWS offers for the same job
I am using two AWS building blocks and neither of its analytics products.
- Amazon CloudWatch RUM is the managed answer: a web client that reports page loads, errors and web vitals. It suits a site that needs alarms, sessions and error tracking. For a portfolio it costs 18 times the script weight of what I load now.
- Access logs with Amazon Athena would replace my report script with SQL. At 3 MB of compressed logs for 71 days, a script that runs in seconds is enough. The archive's keys are partitioned by date, so Athena stays possible.
- Amazon Pinpoint is not an option. AWS ended support for it on October 30, 2026, and recommends Amazon Kinesis for event collection.
What I would tell my 2022 self
- "Free" was a property of two companies' pricing pages, not of the design. Price the thing you would still run if the free plan ended.
- Put the privacy rule where the data is stored. A rule in the page is a suggestion.
- Count twice, with different methods, and write down why the counts differ. One number invites trust it has not earned.
- Test the tracker against the real script. Both surprises in this project, the bot answer and the early LCP, came from behavior no documentation described.
If you are fixing the search side of a site too, the sitemap error that was not about the sitemap is a related story from this same site. And each part of this one was built from a spec with its diagrams, as I describe in diagrams in spec-driven development.