I'm Vas. I run a small comparison site, Best NMN UK, that lines up 15 NMN supplements sold in the UK by price per 500mg and lab testing. The whole site exists for one button: "Check price". So the number I care about most is how many people click through to a brand.
I wanted that number without a cookie banner deciding what I can see. Plenty of visitors reject cookies, and Google Analytics never hears about them. Here is the setup that ended up working, in Laravel, with nothing stored about the person.
1. Every brand link goes through one redirect
Every "Check price" button points at /go/<brand>/?at=<button>. The server counts the click, then sends the visitor on with a 302:
public function go(Request $request, string $slug): RedirectResponse { $p = Catalog::find($slug) ?? abort(404); $at = preg_replace('/[^a-z-]/', '', (string) $request->query('at', '')) ?: null; Clicks::record($request, $slug, $at); return redirect()->away(Clicks::destination($p, $at), 302) ->withHeaders(['X-Robots-Tag' => 'noindex, nofollow', 'Cache-Control' => 'no-store']); } at is the button code: the comparison table, the mobile card, the editor's pick box, a review page. One rule I learned the hard way: never rename a code. Old rows keep the old name, and the history splits in two.
The row in the database has the brand, the button, the page, where the visit came from and the time. No IP, no user agent, no cookie. The brand still sees us in its own analytics, because the redirect adds UTM tags with the button code in utm_content.
2. Most "clicks" in week one weren't people
The first numbers looked great. Then I read the logs. Scanners request /go/ links directly, often with a fake google.com referrer. Three checks removed most of them:
- the referrer has to be one of my own pages;
- the request has to be a real navigation (
Sec-Fetch-Mode: navigate), and a prefetch (Sec-Purpose: prefetch) doesn't count; - known bots by user agent are skipped.
3. Bots that replay scraped links
This one took longer to spot. About 60 "clicks" a day came from proxies all over the world, with my own pages as the referrer and a normal browser user agent. Something had scraped the links and was replaying them.
The fix: every page view gets a signed one-off key, and a few lines of JavaScript add it to the brand links on that page. A bot that never runs the page never has a valid key.
public static function viewKey(): string { $id = bin2hex(random_bytes(5)); $hour = intdiv(time(), 3600); return $id.'.'.$hour.'.'.self::sign($id.'.'.$hour); } The server checks the signature and that the key is less than 48 hours old, so a tab left open overnight still counts and a link scraped last week doesn't. The redirect works for everyone either way; a click without a key just isn't counted.
A nice side effect: the random id is per page view, not per person, so it can't track anyone, but it lets me count people instead of clicks. Someone who opens three brands from one page counts once.
4. Where the visitor came from, still without cookies
Each visit is stored once, on the page it starts on, with its source: an ad click id, UTM tags or the referrer. A click on that same page carries the same source, because the script adds ref=<where they came from> to the brand links on the landing page only.
If someone browses to a second page first, the click can't be tied back to the source without a cookie. I show those as "after browsing our pages" and accept the gap. It's a minority of clicks, and an honest "unknown" beats a guess.
5. What I'd tell myself on day one
- Never filter by IP. iCloud Private Relay can change the IP between two requests from the same phone.
- Leave yourself out. Opening my admin marks my own browsers, and their visits and clicks are skipped.
- Write the contract down and test it. Every button, its code, the redirect and the UTM tags are in one document, and a test fails if a template loses a button or a code. Redesigns stopped breaking the numbers.
- Expect ad platforms to count fewer. The Google Ads conversion tag waits for cookie consent. In one week Ads reported about 80 conversions while my server counted 91 clicks to brands from ad visitors. I use the server number for decisions.
The result
It's two small PHP classes and a few lines of JavaScript, no third-party script, and the brands see the same traffic in their own analytics through the UTM tags. If you run an affiliate or comparison site, it's worth an afternoon.
You can see the buttons on bestnmnsupplement.co.uk. Questions about the setup are welcome in the comments.
