How to setup a google Optimize experiment that doesn't alter page layout?

120 Views Asked by At

I am new to Google Optimize A/B and multivariant test tools.

I am creating one experiment and noticed that I can/modify the look of the url I specify there. For example 50% of the traffic looks at variant a, the rest to b.

In my experiment I don't want to modify the page look, but instead I want to set for variant a a particular variable for example "groupA" and have my javascript code call a different API based on the group we belong.

Afterward the experiment result will monitor the conversion rate which is (nrPeopleClickingAButton / nrPeopleLandingOnThisPage).

Is there any way to achieve this?

How can I fetch the group name or experiement id or experiement name via Javascript in my code and let both variant a and b have exactly same look ?

I read one relevant article https://support.google.com/optimize/answer/9059383?hl=en#zippy=%2Cin-this-article

but they don't explain

  1. How I can get the experiement id for example for variant_a
  2. How can I avoid the editor changes being applied to my variants. I don't want any page look change, I just want to inject different JS variable based on the group we belong then handle that myself in JS. That is all
1

There are 1 best solutions below

5
SilviaGDLR On

You can get the experiment_id here:

enter image description here

If you are using optimize.callback, with this code:

function implementExperimentA(value) {
  if (value ==  '0') {
    // Provide code for visitors in the original.
  } else if (value == '1') {
    // Provide code for visitors in first variant.
  } else if (value == '2') {
    // Provide code for visitors in section variant.
  }
  ...
}
   
gtag('event', 'optimize.callback', {
    name: '<experiment_id_A>',
    callback: implementExperimentA
 });

You have to replace <experiment_id_A> with your Experiment ID (previous image), then in implementExperimentA function you have to change your page depending the variantion (0 - original, 1 - variant 1, 2 - variant 2...)

If you only want to change a variable and not to change the layout, you need to use "code editor" option and not make any more change, more info: add global js