Tutorials

Server-Side A/B Testing with Deno and the Fresh Framework

Server-Side A/B Testing with Deno and the Fresh Framework

Flowsery Team
Flowsery Team
1 min read

TL;DR — Quick Answer

1 min read

Build 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 Request object 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...

Flowsery

Flowsery

Revenue-first analytics for your website

Track every visitor, source, and conversion in real time. Simple, powerful, and fully GDPR compliant.

Flowsery

Real-time dashboard

Goal tracking

Cookie-free tracking

Related Articles