Search code examples
ab-testinggoogle-optimize

Can I create a single Redirect Test for my create and edit page in Google Optimize?


We are trying to run a Redirect Test with Google Optimize on our booking page. So basically there are two different page that we want to test. But each page, has two different URL. One for create and another for edit.

For example:

  1. Variant A

  2. Variant B

So basically we want to create a test that when users visit whether create or edit url they will be redirected to the variant they get respectively.

Let's say I get Variant A from the beginning. So when I visit create page, I will be redirected to Variant A create page. And when I visit edit page, I will also be redirected to Variant A edit page. This rule also apply if I get Variant B.

Is this possible to implement in a single Google Optimize Redirect Test? Or any other suggestion that can achieve this?

Thanks in advance.


Solution

  • You could achieve this with custom Javascript in your variation code.

    1. Edit variation
    2. Choose Select elements
    3. enter head as the selector
    4. Click Add Change and select Javascript
    5. Enter the javascript code to redirect accordingly

    An example of that script might be (and there are many, many ways you might want to code this):

    switch(location.pathname){
      case '/create/booking/a':
        location.assign('/create/booking/b'); 
        break;
    
      case '/create/edit/a':
        location.assign('/create/edit/b');
        break;
    
      default:
          console.log('Here is a scenario you forgot about, or the URL targeting is too broad');
    }
    

    example javascript

    Step 1