User context consists of multiple key-value pairs that are taken into account when searching results and getting recommendations. This context is used by Coveo™ Machine Learning (Coveo ML) to boost results based on other users with a similar profile. You can have as many values in your context as needed and Coveo ML automatically adjust to consider the most relevant ones (see Leveraging Custom Contexts in Coveo Machine Learning Features).
- Install at least the January 2017 (4.0.895) release of Coveo for Sitecore Cloud (see Release Notes for January 2017 - 4.0.895).
- Configure your site to enable recommendations (see Get Recommendations).
- Add the User Context Component before the Page View component (see Inserting and Customizing a User Context Component).
This section covers each option, when to use them and what to expect.
|Component||When to use it||Possible effects|
|Anonymity||You want different recommendations whether the user is logged in or not.||A logged in user will get more results visited by users that are logged in, while anonymous users will get more results visited by anonymous users.|
|Country||You want different recommendations based on the user country.||A user from a certain country will get more results visited by other users from the same country.|
|Device||You want different recommendations based on the user device.||A mobile user will get more results viewed by other mobile users.|
|Profile Cards||You want different recommendations based on the user Sitecore profile card.||A user with a specific profile card will get more results viewed by other users of the same profile card.|
EnableContextPipeline property is enabled, the
coveoUserContext pipeline is run to change properties in the user context. This pipeline is useful for more advanced logic when the other properties do not provide enough flexibility.
CustomContext property lets you add a static context directly within the rendering parameters. It is useful if you have different templates for different sections of your site and want a different context key for each section. For instance, in a news website, you could set the
section key with the
news value for news articles, and
blog for blog articles.
CoveoForSitecoreUserContext variable has a
handler that can modify the context.
You can get the current context using the following method: