Hi all. My team has a backend service that is utilizing the content delivery API to get block and page information from Episerver to our React app. Our client is interested in using the self optimizing block but I am having trouble getting it to work. I was able to properly render the block using the GetSelectedVariation call on the OptimizingBlock class like this
var targetContent = optimizingBlock.GetSelectedVariation();
I am having trouble getting Episerver to properly track conversions though. I have configured the goal page for the self optimizing block in the back office. How exactly does Epi track a conversion for this block? Or can anyone offer any more insight that would help me solve this? Note: A/B testing worked out of the box for our site using content delivery API.
The Optimizing block will check if the goal is met by this event (Assembly EPiServer.Cms.AspNet):
SiteBase.ValidateRequestAccess += CheckGoal;
When use content delivery API to render the page, so I think it will not raise the event then the page is not tracking. To make it work you need to somehow call OptimizingBlockSession.CheckGoal manually by yourself.
Here are the code how the event handler call CheckGoal method for your references:
private void CheckGoal(object sender, ValidateRequestAccessEventArgs validateRequestAccessEventArgs)
var link = RequestContext.GetContentLink();
var pageToCheck = _contentRepository.Service.Get<IContent>(link) as PageData;
var session = OptimizingBlockSession.GetSession(OptimizingBlockSession.SessionName);
if (session != null && pageToCheck != null)
Thank you Dac this code snippet is very helpful.
To make sure I am understanding correctly, in this example will a conversion occur if "pageToCheck" matches the goal page for the self-optimizing block?