One item often overlooked when setting up your Coveo organization is the use of the Search Hub. It's vital however if you are going to utilize Analytics but it does so much more.
Why Bother?
For one, it allows you to identify, if you have multiple search interfaces, which search interface the query originates from. It also allows you to create a condition-based query pipeline based upon the search hub, leverage Coveo ML, and as mentioned, filter data in your analytics reporting.
How To Set Coveo Search Hub Up
In the past, we would explicitly state the Query Pipeline in the initialization. And depending on your implementations, you would then have to programmatically change it if you needed to use a different one.
There are three ways we can go about setting up the Search Hub. They are all valid, but one way is more secure than the others.
- Configuring the Search Endpoint
- Configuring the Analytics Component
- Configuring the Search Token (Recommended)
Now, while one way is recommended over the others, you may not have the ability to do it (depending on the implementation), hence why there are multiple ways to configure it. The important thing to understand is that in both the Search Endpoint setup and the Analytics component setup, it's technically feasible to have this altered or tampered with. Updating the Search Token prevents this from happening (hence the recommendation).
Let's walk through each method.
Configuring The Search Endpoint
If you are using the API Key
method of authenticating and you're not looking to use the CoveoAnalytics
component then this is the approach you should take. For example: setting up a standalone search box.
To do it, locate your initialization script, which likely looks like the following, and update the queryStringArguments
to include searchHub
.
document.addEventListener("DOMContentLoaded", () => {
Coveo.SearchEndpoint.configureCloudV2Endpoint(
"abccompanyorganization",
"xxxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"https://platform.cloud.coveo.com/rest/search",
{
"queryStringArguments": {
"searchHub": "ABCCompanyMainSearch"
}
});
})
In this method, it's important that the API Key
used only as appropriate access.
Configuring The Analytics Component
Perhaps the simplest way to go about updating the searchHub
is by adding it to the CoveoAnalytics
component.
To do this locate, or add your CoveoAnalytics
component and add in the data-search-hub
attribute.
<div class="CoveoAnalytics" data-search-hub="ABCCompanyMainSearch"></div>
Configuring The Search Token (Recommended)
This is only possible if you're using search token authentication
, so if you're not you'll need to look at the other options. Typically you'll be using search token authentication
if you have users logged in and some if not all of your content is secured in some fashion.
If you want to understand more about it, you can read up on it here.
To configure the Search Hub as part of the token, you'll want to add it into the JSON payload shown below.
{
"searchHub": "ABCCompanyMainSearch",
"userIds": [
{
...
}
]
}
The JWT token that returns as part of the authentication method will contain the searchHub information.
Note: If you're using Coveo for Salesforce the search token method is used and the search hub is already part of it.
Configure Your Query Pipeline To Use Search Hubs
Log into the Platform Admin and select Query Pipelines
. For each query pipeline that you have, you will want to repeat these steps.
On the right, click Create a new condition
.
Then create the condition where Search Hub
is the desired value.
Click Add condition
and then save your query pipeline. Once done, you will have properly enabled Coveo Analytics and the Coveo Machine Learning capabilities.