Skip to content
For the complete Netlify documentation index, see llms.txt. Markdown versions of any documentation page are available by appending .md to its URL.

a-b-test-two-pages

Back to templates

Split traffic between two versions of a page using a Netlify Edge Function. Visitors stay on the same version across visits.

·Updated Mar 16, 2026·3 variables
Using a Netlify Edge Function, set up an A/B test that splits traffic between two versions of a page on this site. Page to test: {{PAGE_PATH}} What to test: {{TEST_DESCRIPTION}} Traffic split (defaults to 50/50 if not specified): {{SPLIT}} The implementation should: 1. Create a Netlify Edge Function that intercepts requests to `{{PAGE_PATH}}`. 2. On a visitor's first visit, randomly assign them to variant A or variant B based on the traffic split. 3. Store the assignment in a cookie so the visitor always sees the same variant on return visits. Use a descriptive cookie name like `ab-test-{{PAGE_PATH}}`. 4. Create the two page variants based on the test description. Variant A is the current page (control). Variant B is the modified version. 5. The edge function should rewrite the request to serve the correct variant — not redirect, so the URL stays the same. 6. Add a `X-AB-Variant` response header (value: `A` or `B`) so results can be tracked in analytics. 7. Add the edge function configuration to `netlify.toml`, scoped to the test page path. 8. Include a code comment explaining: - How to end the test (remove the edge function and keep the winning variant) - How to track results (filter by the `X-AB-Variant` header or cookie value in your analytics tool) - How to test locally with `netlify dev` Do not set any environment variables. The test runs entirely at the edge with no external dependencies.

Variables

How to split traffic between variants. Defaults to 50/50.

The URL path of the page you want to test.

What change you're testing — describe both the control and the variant.