João RamiresInstruction manual

Notebook

An A/B/C test with no cookies and no third-party script

This site comes in three art styles: pixel art, an inked comic and photoreal. I like all three, and that is the problem, so I asked the visitors. Each first visit now draws one style at random, and the site counts what people do with it. I set three limits before anything was built: no cookies, no analytics script from anyone else, and nothing about the visitor in any request the site makes.

On the first day Cloudflare’s Web Analytics ran, my site had 20 visits, and the math said I needed about 300 visits in each group before the numbers could choose for me. At 20 a day, that is weeks. This is how the test works inside those limits, what it can and can’t tell me, and why it has no winner yet.

Why not a tracking tool

My first idea was PostHog, which I like. But in the same message I wrote this:

I want to minimize the amount of scripts and js we add on my website header so the experience using it is the best possible.

A tracking tool means a script in every page, usually a cookie, and another company in the loop. I looked at what Cloudflare, which already serves the site, could do instead:

OptionVerdict
PostHogA third-party script on every page, and cookies by default.
Zaraz (Cloudflare’s tag manager)It runs only with a third-party tool switched on, and its Cloudflare-made analytics tool was not released yet.1In the dashboard on 29 November, Zaraz listed that tool with a “Register my interest” button.
Workers Analytics EngineIt needs a Worker. The site is static files and runs no code on the server.
Cloudflare’s traffic analyticsAlready on, free, no script. It counts every request by path and keeps 30 days.

The last row settled it. If every event is a request, Cloudflare, which already serves the site, is already counting it. I only had to make each event look like a page.

Drawing a style before the first paint

The style has to be chosen before the page is drawn, or the visitor sees one style flash into another. A short inline script in the page’s head does it, before anything paints:

Base.astro (head script)JS
if (!st && test) {
  st = styles[Math.floor(Math.random() * styles.length)];
  localStorage.setItem('jr-style', st);
  localStorage.setItem('jr-test', test + ':' + st);
}

st is the style the visitor already has, from an earlier visit or from a ?style= link. test is the name of the running test, set in one constant. When it is set to nothing, the test is over and the site falls back to its default style.

A visitor who arrives with a style in the link keeps it and sits outside the test, in a group called x. A visitor who was drawn into the test stays in that group for good, even after switching styles in the menu. The switch itself is counted. Statisticians call this intention to treat: you compare the groups you assigned, not the groups people chose, because people who switch are not a random sample.

Before launch I tried twelve fresh first visits on a local build. The draw gave photoreal five times, inked five times and pixel art twice, which is what chance looks like with twelve throws. A reload kept the style every time.

An event is a request for an empty file

Each event the site counts has its own empty file:

TEXT
/a/<group>/<event>.txt     for example /a/ink/engaged.txt

Four groups (the three styles and x) times eighteen events make 72 files of one byte each. Astro builds them from two lists with getStaticPaths, so adding an event is one word in a list. Counting an event is one line:

metrics.tsTS
fetch(`/a/${groupOf()}/${event}.txt`, { keepalive: true, cache: 'no-store' });

keepalive lets the request finish even when the visitor is leaving the page, which is when a click on the CV happens. no-store stops the browser from answering the second request from its own cache, which would hide it from the count. The files answer with Cache-Control: no-store and X-Robots-Tag: noindex, and robots.txt keeps crawlers out of /a/.

The events:

EventWhen
visita page loads
engagedthe page has been in view for 30 seconds
room, manualthe visitor enters the 3D room, or leaves it for the text version
open-…one per place in the room: the computer, the TV, the payphone and the rest
cv, email, videothe CV opens, an email link opens, a video plays
to-pixel, to-ink, to-realthe visitor switches style

The request holds the group and the event, nothing else. Like every request on the web, it reaches Cloudflare with the visitor’s address and browser name, and the site adds nothing to that.

Some readers are not counted. A browser that says it is automated, or a user agent with “bot”, “crawl”, “lighthouse” or “headless” in it, sends nothing. For my own visits, any link with ?notrack switches the counting off in that browser, and ?track switches it back on.

One check fooled me during testing. The browser’s Resource Timing API listed no requests to /a/, and the counting looked broken. Resource Timing does not list keepalive requests. The network panel shows them, and they were there all along.

Reading the result

In the Cloudflare dashboard, the traffic analytics filter “Path starts with /a/” and its list of top paths show the counts. The cloud agent that reviews the site every week (how it works) reads the same data with one GraphQL query:

the art-style test, last 30 daysGRAPHQL
httpRequestsAdaptiveGroups(
  limit: 100
  filter: { datetime_geq: $from, datetime_leq: $to, clientRequestPath_like: "/a/%" }
  orderBy: [count_DESC]
) { count dimensions { clientRequestPath } }

The comparison uses rates per group, in this order: contacts per visit (cv plus email), then engaged per visit, then style switches per visit, where lower is better. A style people leave is a style that lost.

How many visits is enough

Before the launch I worked out what the traffic can answer. For a two-proportion test at the usual settings (a 5% false alarm rate, and four chances in five to see a real difference), each group needs, for a single rate such as engaged or contacting:

Difference to detectVisits per group
20% engaged against 30%about 300
10% against 15%about 690
3% contacting against 6%about 750

So the rule is: name a winner only when a group has 300 visits or more and the test says the difference is real. Even then, the first question the data can answer is about engagement. Contacts are rarer, and a fair answer on them needs more than twice the traffic.

At 20 visits a day, 300 per group takes weeks, and the analytics keep 30 days. The agent’s Monday run writes the counts into a report in the repository, so the weeks add up even after Cloudflare forgets them.

What it can’t tell me

  • Visits are page loads, not people. The draw happens once per browser, but visit counts every page. A curious visitor who reads ten pages adds ten visits to one group, and page loads from one person move together. That makes the test surer of itself than it should be. The fix is to count the first page of each session separately. It is next on the list.
  • Storage can be lost. A private window, or a visitor who clears site data, draws again.
  • Blockers. A content blocker may drop the requests to /a/. I don’t know how many do. Not verified.
  • No winner yet. The test went live on 30 November at 01:06 UTC. Two hours later the groups stood at 4 visits for inked, 3 for pixel art and 1 for photoreal, which tells me nothing yet.

What I’d tell someone building the same

  • Before you add a script, look at what your host already counts.
  • Assign the variant before the first paint, in the page’s head.
  • Keep each visitor in the group you drew, and count the switch as an event.
  • Do the sample-size math before launch. It tells you which question your traffic can answer, and when.
  • Send the count with keepalive, so a click that leaves the page still arrives, and check it in the network panel, because Resource Timing doesn’t list those requests.
  • Count the first page of a session as the visit. Counting every page makes a test surer of itself than it should be.