Rich-text Reply

Logged and unlogged users to view same variation

phightower 11-13-14

Logged and unlogged users to view same variation

We are looking to display a variation of a particular page to half the users whether logged into their account or not. However, logged in users view this page at a different URL than unlogged users. Also the buttons do different things on the logged vs. unlogged versions of the page. The issue with this is, we don't want an unlogged user to see the original view and then see the variation after they either log in or sign up, given that there would be a 50% chance of this happening.  After some time researching, it looks like doing a Multipage experiment would be the answer to this, where we can include the logged and unlogged pages along with the variations of each. However, I'd like to know if is there another approach to this while keeping the experiment type as an A/B test. Can anyone make a suggestion? I hope what I've explained makes sense! Thanks.

JDahlinANF 11-13-14

Re: Logged and unlogged users to view same variation

[ Edited ]

If I'm undetstanding correctly:


URL1 - Anonymous users

-- Variation A

-- Variation B


URL2 - Remembered/Authenticated users

-- Variation A

-- Variation B


Your concern is that users seeing "URL1 Variation A" are switched to variation B when they log in?


Solution: This is an A/B Test with two URLs for targeting and two variations.

-- Inside Variation A: do nothing, because they see the current content.

-- Inside Variation B: place code that alters both URL1 and URL2 (whichever URL the user happens to be on)


By creating this as a single experiment that runs on both URLs, you can rest assured that users will not switch between variations when they log in.

Since the guest vs logged in users see different URLs, we can use that to tell Optimizely which code to run on each specific page.  (This can be any element that distinguishes the two pages from each other, but for this example, URL works nicely.)


For this example, let's presume your URLs are like:


To accomplish Variation B, your code would look like this:


try {

  if (window.location.pathname == "/account/guestUsers") {

    //They are NOT logged in, alter the guest page

  } else {

    //They must be logged in, alter the logged in page


} catch(e) { }


edit: removed [code] tag and used the "insert code" button Smiley Happy

Junan 11-14-14

Re: Logged and unlogged users to view same variation

@JDahlinANF is spot on with this solution. Essentially, this recreates a similar logic to a Multi Page test within an A/B test. You can set the URL targeting to point at each page and then let the logic within your variation code determine how to behave based on the URL.
Junan Pang
phightower 11-17-14

Re: Logged and unlogged users to view same variation

Thanks so much, this has been a huge help!