HomeDev GuideRecipesAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide

Disable personalized content

Control whether personalization runs for incoming requests using IPersonalizationEvaluator.

Disabling personalization prevents CMS from evaluating visitor groups and storing tracking data. This supports privacy compliance and gives visitors control over their experience. When personalization is enabled, CMS evaluates visitor group criteria and selects content based on matching groups. CMS stores tracking data in cookies or session state, depending on the criteria used.

When personalization is disabled, no matching occurs and no visitor belongs to any visitor group. Instead, CMS displays the fallback content defined on the personalized content item. No state is stored in cookies or sessions.

IPersonalizationEvaluator

Implement the IPersonalizationEvaluator interface to define custom logic that controls whether personalization runs for the current request. Use this interface to honor privacy signals, consent preferences, or other business rules.

/// <summary>
/// Signature for a component that determines if personalization should be performed or not for the current request
/// </summary>
/// <remarks>
/// Registration of an implementation is done by registering the implementation in IOC container
/// </remarks>
public interface IPersonalizationEvaluator {
  /// <summary>
  /// Determines if the current request should be personalized or not
  /// </summary>
  bool Personalize();
}

Example 1 – Do Not Track header

CMS includes an implementation that checks for a Do Not Track header. When the header is present, personalization does not run and no cookies are stored. Register it in ConfigureServices in the startup class:

public class Startup {
  public void ConfigureServices(IServiceCollection services) {
    services.AddTransient<IPersonalizationEvaluator, DoNotTrackPersonalizationEvaluator>();
  }
}

Example 2 – Cookie-based evaluator

Cookie-based personalization evaluator

A cookie-based evaluator checks whether the visitor has consented to personalization. The site provides a field where the visitor enables personalization, which sets a cookie. The following example demonstrates this approach:

[ServiceConfiguration(typeof (IPersonalizationEvaluator), IncludeServiceAccessor = false)]
public class CookiePersonalizationEvaluator: IPersonalizationEvaluator {
  public
  const string PersonalizeCookieKey = "Personalize";
  private readonly ServiceAccessor<HttpRequestBase>_requestaccessor;
  public CookiePersonalizationEvaluator(ServiceAccessor<HttpRequestBase>requestAccessor) {
    _requestaccessor = requestAccessor;
  }
  public bool Personalize() => _requestaccessor()?.Cookies[PersonalizeCookieKey] != null;
}

Check for enabled personalization

Use IAggregatedPersonalizationEvaluator to check whether personalization is enabled for the current request. This component aggregates the results from all registered IPersonalizationEvaluator instances. If any evaluator disables personalization, the aggregated evaluator returns a disabled result.