Skip to end of metadata
Go to start of metadata

Cloud only
In this topic:

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).

Icon

Only for the January 2017 release (4.0.895), context keys should be in lowercase and contain only alphanumerical characters and the underscore (_ )character. In later releases, non-alphanumerical characters are automatically translated to underscore characters. 

Requirements

Available Options

This section covers each option, when to use them and what to expect.

ComponentWhen to use itPossible effects
AnonymityYou 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.
CountryYou 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.
DeviceYou want different recommendations based on the user device.A mobile user will get more results viewed by other mobile users.
Profile CardsYou 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.

UserContextPipeline

If the 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.

Example:

The following processor adds a static value to the user context.

In the Process method, add some code to add, change, or remove keys and values from the user context. The pipeline is run after all the other properties have been added, so you can conditionally remove options that were previously enabled in the parameters.

To use this processor, access the Coveo.SearchProvider.Custom.config file (Website\App_Config\Include\Coveo), and in the pipeline node, add the following:

The processor args also provides the current Sitecore context in the p_Args.SitecoreContextproperty.

CustomContext

The 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.

JavaScript Library

It is also possible to add context using a JavaScript object, for instance, if you need to add information related to the client. The CoveoForSitecoreUserContext variable has a handler that can modify the context.

You can get the current context using the following method:

  • No labels