November Happy Hour will be moved to Thursday December 5th.

Using the self optimizing block with content delivery API (Episerver.Cms.AddOns.Blocks v2.4.1)

Vote:
 

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.

#221102
Apr 13, 2020 20:12
Vote:
 

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();

	if (RequestContext.IsPublicPageRequest(link))
	{
		var pageToCheck = _contentRepository.Service.Get<IContent>(link) as PageData;
		var session = OptimizingBlockSession.GetSession(OptimizingBlockSession.SessionName);

		if (session != null && pageToCheck != null)
		{
			session.CheckGoal(pageToCheck);
		}
	}
}
#222442
May 06, 2020 3:08
Vote:
 

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?

#222485
May 06, 2020 14:24
* 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.