How Do I Create a Variation that Redirects to Another Page Based on Certain Logic?

Understand Redirect Logic

Sometimes you might need to make your A/B experiment's variations redirect to another page based on some logic. Of course, you could just start writing your JS code that redirects to the new page but the problem is just half solved.

Doing that will result in your variation not recording any stats since it redirects before allowing for the stats to be stored. 

To fix that, we introduced a JS function that you can use to redirect to another page, without losing the ability to also store stats for that specific variation:


So, instead of using for example:


Use the following, instead:


Note: The above code has to be used only inside the "Custom Javascript" section inside the visual editor: 
If you need to transfer the query parameters, then you need to use this:

function redirectToNewUrlWithParam() {
    // Get the current URL
    var currentUrl = window.location.href;
    // Check if the URL already has query parameters
    if (currentUrl.includes('?')) {
      // If yes, append the new parameter with an ampersand
      currentUrl += '&ft=04nf23r';
    } else {
      // If no, append the new parameter with a question mark
      currentUrl += '?ft=04nf23r';
  // Redirect to the new URL


Adding Variation Code or Variation Custom Javascript

If you need to also change the styling of the variation pages where you are redirecting your visitors, you will need to create a deploy for each of the variation URLs where you are redirecting them, and implement the changes on the deploy.


Passing Convert Cookie Data for cross-domain tracking.

If your second-page domain is in a separate domain, the cookie data is passed automatically to the second domain.

Need assistance? Start a conversation with our Support Team.

Reliably Convert More Site Visitors, Even If Everything Else is Changing in Your Business.

✓ No Credit Card  ✓ Easy Set-Up  ✓ Access All Features