Server-Side A/B Testing with Deno and the Fresh Framework
Server-Side A/B Testing with Deno and the Fresh Framework
TL;DR — Quick Answer
1 min readBuild server-side A/B tests with Deno Fresh by storing variants in cookies, firing session-scoped experiment events, and attributing conversions through analytics event metadata filters.
This guide walks through building a server-side A/B testing setup using Deno's Fresh framework paired with a privacy-focused analytics tool. The example project is a fictional dinosaur shop called "Ordino" that tests four variations: two swapped product images (variants A and B) and two different form titles (variants C and D).
Core Principles
- Server-side variant selection: The chosen variant is stored in a cookie with a 24-hour expiry so users see a consistent experience throughout their session.
- Session-scoped experiment events: An A/B testing event fires once per session, carrying the variant metadata so you know which version was shown.
- Conversion attribution: When a user completes an order, the conversion event includes which variant was active, letting you tie outcomes back to specific variants.
- Dashboard filtering: Use event metadata filters in your analytics dashboard to compare performance across variants.
Implementation Notes
- A TypeScript analytics SDK is integrated via npm to handle event tracking.
- Page views are tracked from Fresh middleware, with a context-based mechanism to control which routes get tracked.
- A custom helper function maps the Deno
Requestobject into the format the analytics SDK expects. - Authentication uses an access key approach, so there is no need to manage separate client ID and secret credentials.
Analyzing the Results
After the experiment has collected enough data, open your analytics dashboard and filter events by variant metadata. Comparing the conversion rate for each variant reveals which version of the page drives better outcomes.
Was this article helpful?
Let us know what you think!
Before you go...
Related Articles
How to Run A/B Tests with Tag-Based Segmentation in Web Analytics
Learn how to set up lightweight A/B experiments using tag-based segmentation in privacy-focused analytics, from assigning variants to evaluating results through dashboard filters.
How to Analyze Landing Pages, Entry Pages, and Exit Pages on Your Website
Learn how to use page-level analytics to understand which pages attract visitors, hold their attention, and serve as departure points -- then optimize accordingly.
How Well Does Google Analytics Filter Out Bot Traffic? Testing Accuracy
Bot traffic can distort every analytics metric. Learn how GA4 filters bots, where it falls short, and how to audit your own traffic for automated visitors.