EPiServer.Personalization allows a single Commerce installation to connect to more than one Personalization Engine instance, that is, multiple personalization accounts. To support multiple personalization accounts, EPiServer.Personalization supports the concept of scope,see Using Scopes in a Multisite Installation.
This example describes how to connect personalization accounts with scopes.
- An Optimizely Commerce site v12.4.1 to v13. For Commerce 14, see Installing Optimizely (.NET5).
- Quicksilver sample site, v12.4.1 or higher (optional).
- EPiServer.Personalization.Common, v2.0.0 or higher.
- Personalization API base URL, client token, admin token and site.
Scopes are useful for example in scenarios where you have personalization on multiple sites. If you only have one site with personalization features, you can use scopeless settings.
If you need to configure multiple scopes, the scope name must be the site's SiteDefinitionID. To find that value, log into the CMS and go to Admin mode > Config tab > Manage Websites. In Optimizely CMS versions 11.5.0 and higher, this value is shown for each site. See Using Scopes in a Multisite Installation.
These are some examples of defining and using scopes.
Settings with no alias suffix are called "scopeless". You can consider all settings in earlier versions of the configuration schema as scopeless.
Scopeless settings are used as a fallback if a requested setting is not defined for a specific scope, meaning that the configuration schema is backwards compatible.
Example of using personalization with a specific scope to score search results.
public static IQueriedSearch<TSource, FunctionScoreQuery> UsingPersonalization<TSource>(this ISearch<TSource> search, string scope)
Example of tracking search with a specific scope, only effective if the EPiServer.Find.Personalization package is installed.
public static ISearch<TSource> Track<TSource>(this ISearch<TSource> search, string scope)
You get a default implementation of the scope feature with the EPiServer.Personalization and EPiServer.Find.Personalization packages. This implementation assumes that each CMS site uses one Commerce catalog and one Personalization Engine instance. If this setup fits your needs, set it up using the configuration only. For a more specialized setup, you need to write custom code.
The default implementation stores preference attribute data in cookies in the same way as earlier versions. If you have a single site using Personalization, you do not need to modify this behavior. To add additional scopes, you probably need to implement your own IPreferenceRepository and modify CUID and SessionID storage behavior. See Using Scopes in a Multisite Installation.
If your installation differs from what is supported by the default implementation, you can write custom code as described in the following.
Preference attribute data depends on the CUID and SessionID. This data is created by the Personalization Engine and is only valid for the Personalization Engine instance that created them. So, these values need to be siloed per scope.
The default implementation stores preference attribute data in cookies bound to the current domain. This implementation covers the common scenario where domains are not shared between scopes. To support the sharing of two scopes with a single domain, write custom code.
Another possible scenario is splitting an existing scope in two. In this case, make sure that existing cookie values are not used for the new scope.
To control how cookies are created and read for a scope, replace the default IPreferenceRepository implementation with your custom implementation. You also need to change the default ICookieService implementation used in EPiServer.Personalization.
Updated 3 months ago