A/B Testing - CMSContext.CurrentABTestName is null

Ashley Woodman asked on November 12, 2015 13:28


We are trying to set up an A/B test on our site using Kentico v7.0.103 and have followed the developer guide for setting up an A/B test.

If we recycle the app pool and load the page for the first time, within our code we can see CMSContext.CurrentABTestName and CMSContext.CurrentABTestVariantName are both correctly assigned, with a variant selected at random (e.g. Variant B).

The CMSAB____ cookie gets correctly created, so if we then reload the page the content remains consistent (Variant B's content is still shown). The problem is CMSContext.CurrentABTestName and CMSContext.CurrentABTestVariantName are now both null - they are only correctly set when the page first loads after recycling the app pool.

I'm guessing something is going wrong here and those values should be set every time the page loads. Has anyone encountered this before, or does anyone have any ideas how to fix/work around it?

Thanks for your help in advance.

Recent Answers

Pavel Jiřík answered on November 16, 2015 15:35 (last edited on November 16, 2015 15:36)


When AB test is assigned to a page, it runs only for that one page and randomly chooses which variant to show. Both CurrentABTestName and CurrentABTestVariantName members take information from a current page. This means that if there is an AB test running on a current page, both members will contain some value. If you, however, would go to one of the variant pages directly (or to any other pages), both members would be null, because there is no AB test set for them.

I created an AB test on my instance of Kentico 7.0.103 to test the above scenario and everything was working as expected -> I got null value only on the pages that had no AB test set and running on them.

0 votesVote for this answer Mark as a Correct answer

Ashley Woodman answered on November 16, 2015 16:26 (last edited on November 16, 2015 16:29)

Hi Pavel.

Thanks for your reply.

To add more information, we have the following nodes set up in the Content Tree:

/Home - this has the A/B test set up on it with one child (/Home/VariantB)

The A/B test has 2 variants listed:
Control - /Home
VariantB - /Home/VariantB

When I visit the root of the site (the /Home node), the first time I get randomly assigned the content from either the /Home node or the /Home/VariantB node as expected, and the CurrentABTestName and CurrentABTestVariantName are set correctly.

If I simply reload this page, or visit the root URL of the site, the CurrentABTestName and CurrentABTestVariantName values are now both null - although the content is still shown from VariantB in the case where I was assigned VariantB on first load.

Can you confirm that your test is setup similarly, and that these values are not null after refreshing/revisiting the page? I'm unsure what could be causing the values to not be set after reloading the page.

Thanks for your help.

0 votesVote for this answer Mark as a Correct answer

Pavel Jiřík answered on November 19, 2015 15:01 (last edited on November 19, 2015 15:01)

Hi Ashley,

Yes, I have tried exactly the same setup as you had described and everything has been working fine. Whenever I landed on a page that had an AB test running, I was able to read CurrentABTestname or CurrentABTestVariantName values. Even if I reloaded the page, correct values were still there. On any other pages (where no AB test was running), the values were null.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.