How to implement recommendations using Coveo for Sitecore Hive

When building marketplaces, having recommended products based on previous users' interactions is a feature that can have a tremendous impact on how people interact with a website. Having recommended products (or anything) does not only personalize the user experience but it can also improve sales massively. Coveo for Sitecore Hive (and also the legacy framework) has a built-in module that uses Machine Learning and the user history to recommend things that might be of interest to the context user.

This blog is not intended to replace the documentation Coveo has put in place on how to implement the Recommendations component (, however, it can serve as an auxiliary document to make the implementation of this module even easier.

There are several steps in the official documentation which I will explain here:

1. First, we need to set up the Coveo Page View Analytics component which will be in charge of logging the page view events that will send information to the Coveo Cloud for further analysis.

In order to do this, we just need to go to the Standard Values of the template we would like to start analysing and add the Coveo Page View Analytics rendering located at /sitecore/layout/Renderings/Coveo Hive/Analytics/Coveo Page View Analytics to any placeholder available in our layout, like this:

After adding the rendering, we need to make sure we create the appropriate data source which will contain properties like the Content Type and Metadata. A good practice is to have all these data sources in one place, I created A Global Parameters folder (which is an instance of the /sitecore/templates/Coveo Hive/Structure/Global Folders/Global Parameters Folder template) under /sitecore/content and under this folder I have my Global Analytics folder (instance of /sitecore/templates/Coveo Hive/Structure/Global Folders/Global Analytics Folder) which contains the datasource for my Coveo Page View Analytics rendering which is an instance of the /sitecore/templates/Coveo Hive/Analytics/Coveo Page View Analytics template: 

This Product Coveo Analytics item contains the Content Type and Metadata fields as mentioned previously. These fields are optional and they allow us to give more information to the recommendation module so that the results are more accurate. The Content Type allows us to tag a page (where the datasource is used) so that the results can be filtered, these tag items live under: /sitecore/system/Settings/Buckets/TagRepository. The custom metadata field allows us to specify custom metadata to be logged with the page view events. 

Assign the data source just created to the Coveo Page View Analytics Rendering: 

2. Create a Pipeline for Recommendations ( Go to the Coveo Admin Console and under Query Pipelines add a new pipeline: 

3. Once the pipeline has been created, we need to create a new Coveo Machine Learning model. To do this, click on the pipeline we just created and select the "Edit Component" button that appears at the top. Then, click on the orange button "Add Model" and select Machine Learning model: 

A new window will appear: 

Fill all the necessary data, for now we will just change the model type to Event Recommendations and name the model as Product Recommendations (for more information on what each section does you can follow this link: The model will take an hour or two to get created, after that, it needs some data to train itself and recommend items:

We are done with the configurations in the Coveo Admin Console, it is now time to delve deep into Sitecore.

First, we need to add the Recommendations Rendering (It is very important to note that if further customization is required the best practice is to duplicate the Coveo renderings instead of making changes directly to the OOTB components) to the Standard Values of the page where we want to show the recommendations: 

Since the Recommendations rendering is a search interface, we need to add the Coveo Result List and the Coveo Result Template renderings in order to show the results and style them as needed. Add these renderings using the Experience Editor and make sure to set the datasources (remember to create these items in the Global Parameters folder mentioned above), you should end up with something like this: 

In the image above you can see that I have also added the Coveo Search Resources rendering, it's a good practice to have this rendering added on all the pages that use a Search Interface, if it is not added, the components might not work as expected. Make sure to add this rendering to an existing placeholder in your layout and point to a datasource in the Global Parameters folder. 

In the Coveo File Result Template datasource you can specify the template you would like to use to show your results and style them as needed, I created a new Recommendations.cshtml but you can use the default one by typing Default in the File Template Name field: 

If your Coveo Model is ready, you should now start seeing recommendations!!

Tip: the Recommendations component does not include the context language in the query unlike the standard Coveo Search Interface. In order to query the items based on the context language, we need to include the Sitecore Instance Filter rendering (using the Experience Editor) and point it to a valid datasource like this one:

Tip2: If we need to use the local JS files instead of the ones in, we can tell our Coveo components to do so in our Coveo Search Resources datasources, by checking the Use local files for Coveo JavaScript Search Framework checkbox: