Disable personalized content
Describes how you can disable personalization, such as audiences, within CMS. It is enabled by default.
When personalization is enabled, and a requested content item uses audience personalization, the visitor is evaluated against the used audience and audience criteria. The content displayed to the visitor is selected depending on which audience matches the request. Depending on the used criteria, this can cause tracking data to be stored in cookies and/or session state.
When personalization is disabled, no matching occurs, and the visitor is not considered part of any audience. Instead, the visitor is displayed the "fallback content", if that is defined on the personalized content. When personalization is disabled, no state is stored in cookies or for the visitors' sessions.
IPersonalizationEvaluator
There is an interface that can be implemented to control whether personalization should occur or not. The interface is specified as:
/// <summary>
/// Signature for a component that determine if personalization should be performed or not for the current request
/// </summary>
/// <remarks>
/// Registration of an implementation is done by register the implemenation in IOC container
/// </remarks>
public interface IPersonalizationEvaluator {
/// <summary>
/// Determines if current request should be personalized or not
/// </summary>
bool Personalize();
}
Examples
Optimizely Content Management System (CMS) includes an implementation that checks for the presence of a Do Not Track header. If the header is present, no personalization is done for the request, and no cookies are stored. It can be registered in ConfigureServices
in the Startup
, as in this example:
public class Startup {
public void ConfigureServices(IServiceCollection services) {
services.AddTransient < IPersonalizationEvaluator, DoNotTrackPersonalizationEvaluator > ();
}
}
Another example could be to check for the existence of a certain cookie which specifies that the visitor has agreed that audience personalization could occur. In that case, the site could have a field where the visitor can enable personalization. When the visitor selects that field, a cookie is added for the visitor. Such an example could look like:
[ServiceConfiguration(typeof (IPersonalizationEvaluator), IncludeServiceAccessor = false)]
public class CookiePersonalizationEvaluator: IPersonalizationEvaluator {
public
const string PersonalizeCookieKey = "Personalize";
private readonly ServiceAccessor < HttpRequest > _requestaccessor;
public CookiePersonalizationEvaluator(ServiceAccessor < HttpRequest > requestAccessor) {
_requestaccessor = requestAccessor;
}
public bool Personalize() => _requestaccessor()?.Cookies[PersonalizeCookieKey] != null;
}
Check if personalization is enabled
The IAggregatedPersonalizationEvaluator
component can be used to check whether personalization is enabled for a request. The signature is similar to IPersonalizationEvaluator
and it returns an aggregated result from registered IPersonalizationEvaluator
instances. If any personalization evaluator states that personalization should be disabled, then the aggregated evaluator states that no personalization should occur.
Updated about 2 months ago