Can I manually initiate an A/B testing evaluation?

Vote:
 

Can A/B test evaluation be triggered from events other than those in IContentEvents? Ideally, can I manually trigger an evaluation cycle from C# code?

There is a TestManager.EvaluateKpis() method, but it requires the list of KPIs to evaluate. I would like it to simply evaluate whatever is active.

#180551
Jul 14, 2017 0:18
Vote:
 

KPI's can be evaluated from any .NET event that the KPI is registered to look for. I gave a demo of attaching a custom KPI to a custom defined .NET event at Ascend in Las Vegas earlier this year. Below is the implementation of the IKpi interface methods that attaches the AB event handler to my demo event:

private EventHandler<ABDemoEventArgs> myHandler;
public event EventHandler EvaluateProxyEvent {
add
{
myHandler = new EventHandler<ABDemoEventArgs>(value);
var demoEvents = ServiceLocator.Current.GetInstance<AB_Demo_Event.ABDemoEvents>();
demoEvents.DemoABEvent += myHandler;
}
remove
{
var demoEvents = ServiceLocator.Current.GetInstance<AB_Demo_Event.ABDemoEvents>();
demoEvents.DemoABEvent -= myHandler;
}
}

public IKpiResult Evaluate(object sender, EventArgs e)
{
var arguments = e as ABDemoEventArgs;
var convert = arguments != null; // evaluate was called on the event we want to convert on

//We evaluate true when called because we are only called when we hook into our custom event
//We could do some work here to make sure the result meets the requriement
return new KpiConversionResult() { HasConverted = convert, KpiId = this.Id };
}

You could call the evaluate yourself with the method in the TestManager you mentioned. You would have to make another TestManager call to get the Active tests (which should be in their own cache and thus fairly lightweight) and read all the KPI's for the Active tests from all the TestData returned. What you wouldn't get is the cookie management that is built into the ProxyEventHandler that the AB package passes to custom KPI's in the EvaluateProxyEvent implementation.

#180603
Edited, Jul 14, 2017 21:49
Vote:
 

How about not using an event at all, and just doing this:

public class ConvertController : Controller
{
  public string Index(string token)
  {
     var myKpi = new MyKpi();  
     myKpi.Evaulate(null, new MyCustomEventArgs());
   }
}

Does the TestManager handle the cookie management to prevent variant tracking and prevent duplicate conversions?

#180604
Jul 14, 2017 21:56
Vote:
 

The TestManager does not handle the cookie in any way, so to do what you are suggesting you would have to either update the cookie manually or track test conversions in a different manner. The ProxyEventHandler code that is passed to the KPI when the instance is created as part of an AB test contains the logic for checking for active tests, calling evaluate, and updating the cookie when a conversion happens.

In my demo I just raised my custom event in the controller to trigger the AB package to fire and trigger the evaluation that way cookie management was done without any extra code.

public class TestLandingPageController : PageControllerBase<TestLandingPage>
{
public ActionResult Index(TestLandingPage currentPage)
{
var model = PageViewModel.Create(currentPage);

var demoEvent = ServiceLocator.Current.GetInstance<ABDemoEvents>();
demoEvent.RaiseDemoEvent(this, new ABDemoEventArgs());

return View(model);
}
}
#180605
Jul 14, 2017 22:10
Vote:
 

Hello!

We are trying to implement a custom kpi for our A/B testing and i came across this thread when trying to implement a custom event to trigger the evaluation.

I have implemented the eventhandler and try to raise the event in the same way as above but with no success.

The issue im facing is that the PageLoad event is always null so it is never invoked.

        private EventHandler<AddToCartEventArgs> eventHandler;
        public override event EventHandler EvaluateProxyEvent
        {
            add
            {
                eventHandler = new EventHandler<AddToCartEventArgs>(value);
                var demoEvents = ServiceLocator.Current.GetInstance<AddToCartEvents>();
                demoEvents.PageLoad += eventHandler;
            }
            remove
            {
                var demoEvents = ServiceLocator.Current.GetInstance<AddToCartEvents>();
                demoEvents.PageLoad -= eventHandler;
            }
        }
public class AddToCartEvents
    {
        public event EventHandler<AddToCartEventArgs> PageLoad;

        public void OnPageLoad(AddToCartEventArgs e)
        {
            PageLoad?.Invoke(this, e);
        }
    }

Here is where i try to trigger the event:

public ActionResult Index(ProductDataModel currentContent, string v)
        {
            var model = _productViewModelFactory.Create(currentContent, v, Request);

            var testEvent = ServiceLocator.Current.GetInstance<AddToCartEvents>();
            testEvent.OnPageLoad(new AddToCartEventArgs());

            if (model == null)
            {
                return HttpNotFound();
            }

            return Component.For(model);
        }

#279658
Edited, May 03, 2022 9:21
* 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.