Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Loading...
Area: Optimizely CMS
Applies to versions: Not applicable

Advance API

Recommended reading 

This topic introduces Episerver Advance, the related NuGet packages and sample code, and how to install and configure the tracking.

How it works

Episerver Advance is based on a content service for retrieving content recommendations, and client packages, for configuring the tracking for your website.

EPiServer.Tracking.PageView

The EPiServer.Tracking.PageView package tracks page views and sends data in a pre-defined format to a Profile tracking instance. That data will be the source for the recommendation service.

This package depends on EPiServer.Profile.Client and EPiServer.Tracking.Core NuGet packages, so its requirements are the same as the requirements for these two packages.

Installation and configuration

  1. Install the EPiServer.Tracking.PageView NuGet package from Episerver NuGet source to your site.
  2. Add the PageViewTrackingAttribute to your controller, and the page will be tracked.
    [PageViewTracking]
    public ActionResult Index(StartPage currentPage)
    {}
     
    [ValidateInput(false)]
    [PageViewTracking]
    public ViewResult Index(SearchPage currentPage, string q)
    {}]]

EPiServer.Personalization.CMS

The EPiServer.Personalization.CMS package connects to Recommendation Service to retrieve recommendations for content.

Installation and configuration

When you place and order for and register Recommendation Service, Episerver provides a HMAC key pair and a service URL.

  1. In web.config, set the values in the following appSettings keys:
    <add key="episerver:RecommendationServiceKey" value="application key" />
    <add key="episerver:RecommendationServiceSecret" value="secret key" />
    <add key="episerver:RecommendationServiceUri" value="" />
  2. Install the EPiServer.Persionalization.CMS NuGet package from the Episerver NuGet source to your site.
  3. Retrieve recommendations for content:
    1. Create a recommendation request with following parameters
      • siteId. The ID of the site that has the content that needs to receive recommendations.
      • contentId. The ContentGuid of the content.
      • languageId. The language of the content.
      • numberOfRecommendations. The number of recommendations that you want to have for the content.
    2. Retrieve recommendations using the instance of IRecommendationService.
    3. The recommendation result is a list of RecommendationResult objects.

    For example:

    public async Task<ActionResult> Index(SamplePage currentPage)
      {
          var siteId = SiteDefinition.Current.Id.ToString();
          var contentId = currentPage.ContentGuid.ToString();
          var languageId = currentPage.Language.Name;
     
          var rRequest = new RecommendationRequest
          {
              siteId = siteId,
              context = new Context { contentId = contentId, languageId = languageId },
              numberOfRecommendations = 5 //or another number as needed
          };
     
          var recommendationService = ServiceLocator.Current.GetInstance<IRecommendationService>();
     
          var result = await recommendationService.Get(this.HttpContext, rRequest);
          ……
      }

Sample code

Use the available sample code package to explore Episerver Advance. The sample code contains a CMS block that can be added to a page for displaying recommended content. The sample code block is available for download on Episerver GitHub.

Related topics

Do you find this information helpful? Please log in to provide feedback.

Last updated: May 23, 2018

Recommended reading