In the case of Coveo, Triggers are a feature in the query pipeline. They define a function or action that will be taken (within the client-side search interface), when a certain search query meets a query pipeline condition. For example, you type in "Coveo" into the search and something happens because that search query was the trigger.
Before you setup triggers you need to understand your audience and have reviewed your analytics to see what type of queries people are making. Otherwise you could be creating a trigger than will never be hit.
There are four actions that make up the Trigger feature:
notify- will display a message in the search interface to the user
query- will run a new query that may or may not include text from the one entered by the user
redirect- will redirect the user to a specific URL based upon a set of conditions
Before a Trigger will operate, two areas need to be setup.
First, a Trigger (with a Condition) needs to be added to the query pipeline in the Platform Admin.
Second, the component, if not already done so, needs to be added to the search UI. Let's have a look at each to know how to set them up properly.
In order to add a Trigger, via the Platform Admin, login and go to Query Pipelines, then select the pipeline in use. Once there, click on Triggers as shown below.
Once there, click
Add Rule. You'll then be presented with selecting a trigger type on the left, and a condition on the right. The trigger type is one of the four options listed above. The conditions, which typically would be based on a type of query (i.e. $query) but are anything available within the Advanced Query, are added on the right side either by creating a new condition or selecting a global condition.
It's important to understand what "problem" or "challenge" you're trying to solve when it comes to implementing a condition.
This might be as simple as directing users to particular pages based upon queries.
It might be that your company has identified an issue and improving the search itself, getting users to better results reduces calls or emails to your support staff. Whatever it is, while creating a condition that is based upon information readily available is easy, be sure to create a condition that makes sense and is focused, testable and repeatable.
Conditions are also one of those things that, the fewer in number, the better.
If you've created conditions via the rules in the Query Pipeline it might seem impossible to know all the ones you've created. While you can add conditions via any aspect of a Query Pipeline setup, they are also found in their own area, aptly titled, Conditions shown below.
Just as queries have their own syntax, so do conditions. The syntax is fairly similar, which you can find here.
You can, like the majority of options in Coveo Cloud, create a condition via point and click measures, but perhaps your condition needs fine tuning.
In that case, like many options, you can also enter "developer mode" and construct your condition manually using the proper syntax of course.
Once a condition has been created, go to the Conditions area in Coveo Cloud, select said condition, and then click
... More followed by
Edit code. A modal will pop-up displaying the condition in the code form.
Now that we've got a Trigger type selected and a condition for which it will occur; next steps are to add it to the Search UI. Which is remarkably easy. How easy? Just copy this code into the DOM where you want a trigger to appear (if you're doing a
With that in place, you'll really just need to style it according to your liking. As
redirect all perform an action that will result in either the search page refreshing or redirecting to another page or doing something else entirely you won't need to do much else.
Now that we've got a Trigger setup, let's see each of them in action, shall we?
As discussed, the
notify trigger is intended to inform users of something based upon a query and an optional condition. In this example we wanted to post a message to users if they entered the word "Coveo".
query trigger we can, based upon a query string or other condition, cause the search to perform an a different query. In this case, if we entered in "McDonald's" we want it to search for "burger".
While it resembles a notify trigger in this case, it's more flexible in what you can do. A few things to note:
Perhaps the most useful of the set,
redirect allows you to simply redirect the user based upon a set of conditions.
In my example, if the user enters the word "Search" I'm redirecting the browser to coveo.com.
This is useful if you have specific products you're launching, or you want to redirect users to a solution if they enter in a specific error perhaps.
Determining if your Trigger is working or not can sometimes be cumbersome. Luckily you can find it within the api call as shown below when a successful trigger is made.
Go to your Developer Tools and open up the
Network tab and locate the query submission.
Seeing this it tells me the trigger is setup properly on the Coveo side. But if I never saw my function run, then I know the issue is on the client side.
I hope you're better prepared to work with Triggers. The possibilities are endless. However, use as with all things in Coveo, use sparingly.
I highly doubt users want to be redirect on a common phrase or notified of messages based upon every other word. The nice thing is they can streamline workflow, add some nice features, and in the end improve a visitors experience.
We're on the look out for talented developers to join our team.
Think you have what it takes?