← Back to Campaign Tracking & UTM Systems
Technical Growth Cookbook · Recipe 001

Split one campaign URL between two landing pages and track the variant with UTMs

A practical JavaScript recipe for campaign testing: one public URL, two possible destinations, a 50/50 split, and clean UTM labels so the results can be analyzed later.

JavaScript UTM tracking A/B testing Analytics

The business problem

Let’s say a food delivery business wants to promote one QR code, but it is not sure which landing page will sell more.

Menu A promotes family combo meals. Menu B promotes quick lunch options. Instead of printing two different QR codes, the business uses one campaign URL and splits visitors between both menu pages.

The important part is not only the redirect. The important part is that each visitor is labelled correctly with UTM parameters, so the business can later compare conversions, checkout starts, order value, and revenue per visitor.

The recipe

This example uses fictional food delivery URLs. The method is reusable, but real client URLs, IDs, prices, and private business parameters should not be published.

export default {
  async fetch(request) {
    const menuA = "https://example-food.co/menu/family-combos";
    const menuB = "https://example-food.co/menu/quick-lunch";

    const variant =
      Math.random() < 0.5 ? "menu_a_family_combos" : "menu_b_quick_lunch";

    const target = variant === "menu_a_family_combos" ? menuA : menuB;

    const url = new URL(target);

    url.searchParams.set("utm_source", "restaurant_qr");
    url.searchParams.set("utm_medium", "qr");
    url.searchParams.set("utm_campaign", "menu_ab_test_june");
    url.searchParams.set("utm_content", variant);

    return Response.redirect(url.toString(), 302);
  }
};

How it works

  1. Create one public campaign URL.
  2. Define two destination pages.
  3. Randomly assign the visitor to Menu A or Menu B.
  4. Add UTM parameters to label the campaign and variant.
  5. Use a temporary redirect because this is an experiment.

What to measure

  • Users by variant
  • Menu views
  • Checkout starts
  • Orders or leads
  • Conversion rate
  • Average order value
  • Revenue per visitor