Rich-text Reply

Persist sticky sessions outside audience conditions

nazikus 01-28-17
Accepted Solution

Persist sticky sessions outside audience conditions

Hi,

 

I'm newcomer to Optimizely. I have a landing page and I'm trying to perform isolated A/B tests for two audiences. The way I split the audience is based on query parameters, then I setup A/B test for each audience separately and it works fine except the following - if the same visitor returns to landing page but without these query parameters in URL, he is not categorized to any of the audiences anymore, hence is shown no experiment (original landing page).

 

So my question is, how can I persist sticky session to visitor that have once fallen to one of the experiments (audiences), even if visitor does not meet audience matching conditions in returning sessions?

 

To be more specific.

I have a landing page: www.example.com

A visitor may come from compaign attaching a query to the URL: www.example.com/?user=type1 OR www.example.com/?user=type2

 

Then, a newcoming visitor falls to one of the experiments, but after he/she returns from elsewhere (lets say from organic search or directly entering "www.example.com"), no experiment is applied, but I'd like the same variation to persist for returning visitors.

 

 

Level 2

RyanC 01-30-17
 

Re: Persist sticky sessions outside audience conditions

We have the same problem from time to time and we tackle it by setting a cookie once the user is bucketed in the experiment for the first time. Then we set the audience with having the querystring or the cookie.

Setting a cookie is very simple by adding the below line into your custom code:

document.cookie = "myExp=Yes";
Ryan
------------------------------------------------
The best solution is the simplest.

https://www.linkedin.com/in/ryan-camilleri
http://midnightknights.com
Experimentation Hero
nazikus 01-31-17
 

Re: Persist sticky sessions outside audience conditions

Thanks for reply. And yes, that's exactly what I've ended up doing.

 

I'll just leave more detailed instructions here for newcomers.

 

After you have finished setting up experiment for one of your audiences (lets call it audience "X"), go to Experiment > Shared Code, and insert following javascript snippet to setup your custom cookie: 

document.cookie = "my_product_audience=X";

 

Then go to your audience conditions, add OR JavaScript condition with following code:

(function(){
    if (/my_product_audience=X;/.test(document.cookie)) {
      return true;
    }
    return false;
})();

And finally specific variation is chosen by Optimizely script automatically. That's it.

 

Repeat the same steps but for another audience ("Y"). This way you'll get "sticky" sessions for returning users, they will see the same variation regardless of a way they have returned.

Level 2
RyanC 02-01-17
 

Re: Persist sticky sessions outside audience conditions

You are welcome. On a side note Optimizely Audience specifically has one of the selections as "Cookie" so there is no javascript needed there.

Ryan
------------------------------------------------
The best solution is the simplest.

https://www.linkedin.com/in/ryan-camilleri
http://midnightknights.com
Experimentation Hero