Guides
Redirect tests
Split URL tests that send visitors of a page to different addresses, without code.
A redirect test sends visitors of a page to different addresses: half of / to /next and half to /next-dark, say. It needs no code beyond the website snippet, which makes it the quickest way to test a redesigned landing page built separately.
Set one up#
- Experiments → New experiment → Redirect test (split URL).
- Pages to test: a saved location or custom page rules (include and exclude, with the same match types as locations). The URL tester shows which page each address would be sent to.
- Destinations: the original (an empty URL keeps visitors on the page) and one or more alternatives, each with a share. A destination is a path like
/nextor a fullhttps://address. - Choose the audience, goals and guardrails as for any experiment, and start it.
What the snippet does#
The snippet decides before the page shows, sends the exposure, and redirects the visitors who get the alternative. UTM tags and click ids come along, and each arrival is counted.
- It matches the page before deciding, so only visitors of the tested pages are enrolled and exposed. Visitors elsewhere on the site are not counted.
- It redirects with
location.replacewhile the anti-flicker style still hides the page, so the original never flashes and the back button doesn't loop. The exposure is sent withsendBeaconbefore leaving. - With keep query string and keep hash (both on by default), UTM tags, click ids and anchors are carried over. When the destination has a parameter of the same name, the destination's value wins.
- Arrivals are counted as the event
redirect_landed:<flag key>, added to the experiment as a secondary metric, so you can see how many visitors actually reached each destination. - A short-lived marker in
sessionStorageprevents redirect loops: a visitor who arrived through a redirect is never redirected again from there.
Regular-expression groups#
With a regular-expression page rule, groups can be used in destinations as $1 to $9:
Page rule (regex): ^https://shop\.com/products/(\d+)
Destination: /p2/$1 → /products/42 goes to /p2/42Behind the scenes#
A redirect test is an ordinary flag named redirect_<name>, with one variation per destination. Each variation holds its address in the text variable redirect_url. The datafile's redirects section tells the snippet which pages are tested. A redirect test on a saved location is published with the location's rules copied in, so older snippets keep working. Because the redirect happens before the page shows, the location must activate on page load.
API#
{
"kind": "redirect",
"name": "New landing page",
"environment": "production",
"redirect": {
"include": [{ "type": "simple", "value": "/" }],
"exclude": [{ "type": "contains", "value": "preview=1" }],
"preserveQuery": true,
"preserveHash": true,
"destinations": [
{ "name": "Original", "url": "" },
{ "name": "Next", "url": "/next" },
{ "name": "Next dark", "url": "/next-dark" }
]
},
"primaryMetric": { "eventKey": "signup", "type": "conversion" },
"start": true
}redirect
includeUrlMatch[] | Pages to test. Each: { type, value, caseSensitive? }, type simple | exact | startsWith | contains | regex. Up to 20. |
excludeUrlMatch[] | Pages left out even when included. |
locationkey | Saved page-load location instead of include/exclude. |
preserveQueryboolean | Carry the query string over. Default true. |
preserveHashboolean | Carry the #hash over. Default true. |
destinations[{ name, url, weight? }] | 2–10. Empty url = stay on the page. Weights in buckets; omit everywhere for an even split. |