views:

360

answers:

4

What is the best and cleanest way to implement A-B testing in asp.net mvc? That is, when we make new changes to an asp.net mvc web site, we want to test the new html/css/js with a certain subset of visitors (defined on cookie, login id, etc) and then analyze some metrics (page response time, number of pages visited, $$$ in sales, etc) afterwards to measure the level of success of the changes.

I am looking for a clean way to implement a way of choosing what view (html/css/js, etc...) to render using asp.net mvc.

A: 

I think there isn't a ready to use solution for this and you will have to improvise.

Try to override your current functionality in well defined points without breaking it. Explicitly draw a border where your regular code and A-B testing code lives.

Inversion of control principle might help a lot here too (i.e. - controller factory could provide derived controller instead of original one). For views&partialviews - you could change viewengine so it would try to look for 'MyPartialViewAB.ascx' instead of 'MyPartialView.ascx'.

And it might be a good idea to take a look what performance counters are (in case you haven't).

Arnis L.
A: 

Google Website Optimizer? It's a Javascript based solution that doesn't require anything from your backend.

  1. You include Google's Javascript on your page
  2. The script randomly substitutes elements on your page as defined by your A/B test
  3. Google's site shows you a nice breakdown of the results...
Jesper Mortensen
+1  A: 

If you are using the spark view engine, you could probably do it with a variation of the theme filter (http://sparkviewengine.com/documentation/viewlocations#Extendingfilepatternswithdescriptorfilters). For each new visitor to the site, determine if you want them to see the existing or new version of the site and set a cookie. Wire up a descriptor filter that looks for the presence of the cookie and modify the view location to look in the folder containing the modified views. If an alternative view exists, the Spark engine will automatically render it in place of the "normal" view, otherwise it will render the normal view.

If you are using the normal WFVE, then the simplest way to manage this would be to define a folder under Views where your view alternatives live. When you want to provide an alternative view, you place it in a location that matches its position within the normal Views folder but rooted at the alternatives folder e.g. to provide an alternative to Views/Users/login.aspx place your new view at Views/Alternative/Users/login.aspx.

With a convention in place for locating your alternative views, you can extend the WebFormViewEngine and overload CreatePartialView / CreateView to inspect some aspect of the ControllerContext to determine whether to render the default or overloaded view and alter the path as appropriate e.g. changing .../Views/Users/login.aspx to .../Views/Alternative/Users/login.aspx.

Neal
I'm using spark.
Lamar