London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!

A/B testing - How to know if page is showing test content

Vote:
0

Hi,

I have a requirement to identify if the page is showing the test content (to find if A/b testing is running for current page). So, is the a way like particular cookie or code snippet to identify? Expecting some good solution to do that. :)

Thanks is Advance.

#209218
Nov 11, 2019 15:00
Vote:
1

You can inject the ITestDataCookieHelper, you can then use this to work out which version of the test you are in

var allActiveTests = _testDataCookieHelper.Service.GetTestDataFromCookies();
var activeTest = allActiveTests.FirstOrDefault(x => x.TestId == testId);
if (activeTest != null)
{
	switch (Model.ViewingVersion)
	{
		case "Any":
			break;

		case "Control":

			break;

		case "Challenger":

			break;
	}
}
#209222
Nov 11, 2019 15:31
Vote:
1

Hi Praful

You could do something like this:

bool anyActiveTests = IMarketingTestingWebRepository.GetActiveTestsByOriginalItemId(myPage.ContentGUID, "en").Any();

It tells you whether the page has any active tests, but it doesn't tell you whether you are right now viewing the page as a test.

I don't know if that comes close enough for you. If not, you will have to dig deeper (looking at the cookies and stuff).

#209234
Nov 12, 2019 6:50
Vote:
0

Hey Guys thanks for the response.

@Stefan Holm Olsen Your solution worked, the only issue were with "en", I got this error 

error CS1503: Argument 2: cannot convert from 'string' to 'System.Globalization.CultureInfo'

Even I got the hint and solved it. Actually I got the active test without passing that culture info (as I can ignore language based for my requirement).

Thanks for the solution.

#209260
Nov 12, 2019 16:19
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.