Manually activating experiment multiple times

Manually activating experiment multiple times

I have an experiment where I have changed the look of a menu and I'd prefer this test to run only when the user clicks in the menu (since otherwise I will pay for 95% who never even see the experiment). In order to start the experiment, I have set it to manual activation and in GTM, I have set a click event which checks that it is the menu that is clicked. This works ... OK at least (better would have been to send a dataLayer event but there is no time from the site team for this right now). The problem is, I activate the Optimizely experiment several times and each time the code runs (which the second time gives a totally different look).

Now, I have solved this in the code of the experiment, by checking for an element that is removed once the code has run and therefore it wont run again. Now I am wondering - will there be any problems regarding this that I cannot forsee? Such as a new visit being logged the second time the experiment is activated? Or is there a button somewhere in Optimizely to say "activate only ones per session"? I have also tried with a session storage check in GTM to only activate once but this does not seem like the best solution, since a new tab would remove this. I guess a cookie would be possible, but seems a little bit much for this.

3. You are checking if an element is removed (user is currently seeing a variation) and if so your code prevents the activation call from executing again.

When an experiment gets activated Optimizely checks if the visitor meets the audience and targeting conditions and buckets him into a variation (this information will be stored in a cookie). He will only see this variation as long as the experiment is active. If the experiment gets activated again Optimizely will check again if he meets all the requirements and if so it puts him back into the same variation (that is stored in the cookie). A good description how Optimizely works can be found here.

"The problem is, I activate the Optimizely experiment several times and each time the code runs (which the second time gives a totally different look)." Do you mean that every time the activation is triggered the visitor gets to see a different variation? Could you please give an example?

Re: Manually activating experiment multiple times

Hm, no I am not actually checking in the activation code if an element is removed but perhaps this would solve the whole problem.

As it is now, I check in the code in the experiment, if (object has not been removed) { do these changes }. But if those changes are done more than once, they move things around in a strange way and make the html look bizarre. I thought that activating an experiment multiple times would not run the experiment code multiple times but this is not the case.

Re: Manually activating experiment multiple times

it sounds like that your variation code keeps on changing elements that were already changed. Is it possible that your are using too universal CSS selectors? In this case specifying the selectors might help.

How about changing the if (object has not been removed) { do these changes } statement into if (object has not been removed) { do these changesAND do something to change the if() condition to false} ?

Through this you could prevent the variation code executing a second time, since the if() condition is set to false. You could also wrap the API call window.optimizely.push(["activate", xxx]); with an if(global variable==xyz) condition, set a global variable and change it through the variation code to prevent multiple activations.

Re: Manually activating experiment multiple times

I have just implemented (but yet not tested) a check in GTM like this, where variable NUMBER_OF_EXPERIMENT is set to a fixed number):

if (optimizely.activeExperiment.indexOf(NUMBER_OF_EXPERIMENT) === -1) then

window.optimizely.push(["activate", NUMBER_OF_EXPERIMENT]);}

And in the actual experiment, I have a safety code line around the whole execution code where I say "check for this object, if not there then don't run the test").

I have yet to test this. The only thing that surprised me is that multiple executions of the activation script means that the experiment code runs several time. But I guess it is no biggie, just something to adapt to.