Manage Trigger Rules

Members with the required privileges can use query pipeline triggers to define an action to execute in a search interface when a query meets the associated condition.

The list of query pipeline triggers for a Coveo organization is empty by default.

When a trigger rule is applied, an object representing the action to perform is generated inside the triggers property of the query response. The search interface from which the query originates is then responsible for translating this object into an action (e.g., executing a corresponding JavaScript function call, notifying the end user with a corresponding message, etc.).

Note

In a full Coveo JavaScript Search Framework interface, you use the Triggers component to automatically handle trigger actions.

To use the Triggers component in your full Coveo JavaScript Search Framework interface, make sure that the interface markup contains the following element:

<div class="CoveoTriggers"></div>

Since the March 2020 Release (v2.8521), standalone search boxes automatically handle Redirect triggers without the need for a Triggers component.

Create Trigger Rules

  1. On the Query Pipelines (platform-eu | platform-au) page, click the query pipeline in which you want to add a rule, and then click Edit components in the Action bar.

  2. On the page that opens, select the Advanced tab.

  3. In the Advanced tab, on the left-hand side of the page, select Triggers.

  4. In the upper-right corner of the page, click Add Rule to access the Add a Trigger Rule [1] subpage.

  5. Under Type, select one of the available methods (Notify, Query, Execute, or Redirect).

  6. In the box that opens, depending on the selected method, enter the desired value.

  7. On the right-hand side, under Condition, select a query pipeline condition in the drop-down menu or create a new one.

    Important

    If a trigger rule isn’t associated with a query pipeline condition, the rule is ignored.

  8. Under Description, optionally enter information that will help you manage the rule in the future.

  9. Click Add Rule.

Edit Trigger Rules

  1. On the Query Pipelines (platform-eu | platform-au) page, click the query pipeline in which you want to edit a rule, and then click Edit components in the Action bar.

  2. On the page that opens, select the Advanced tab.

  3. In the Advanced tab, on the left-hand side of the page, select Triggers.

  4. Click the rule you want to edit, and then click Edit in the Action bar [2] to access the Edit a Trigger Rule subpage.

  5. Under Type, select one of the available methods (Notify, Query, Execute, or Redirect).

  6. In the box that opens, depending on the selected method, enter the desired value.

  7. On the right-hand side, under Condition, select a query pipeline condition in the drop-down menu or create a new one.

    Important

    If a trigger rule isn’t associated with a query pipeline condition, the rule is ignored.

  8. Under Description, optionally enter information that will help you manage the rule in the future.

  9. Click Save.

Duplicate Trigger Rules

  1. On the Query Pipelines (platform-eu | platform-au) page, click the query pipeline for which you want to duplicate query pipeline rules, and then click Edit components in the Action bar.

  2. On the page that opens, select the Advanced tab.

  3. In the Advanced tab, on the left-hand side of the page, select Triggers.

  4. In the Triggers subtab, click the rule you want to duplicate within the same pipeline (typically to create a slightly different rule).

  5. In the Action bar, click Duplicate.

The duplicated rule appears at the bottom of the list in the pipeline component tab.

Review Information About the Rule’s Creation or Last Modification

You can verify who created or last modified a given trigger rule by inspecting the Details column of the Triggers subtab. The Details column also indicates the hour and date the rule was created or last modified.

  1. On the Query Pipelines (platform-eu | platform-au) page, click the query pipeline containing the rule for which you want to inspect the information of the Details column, and then click Edit components in the Action bar.

  2. On the page that opens, select the Advanced tab.

  3. In the Advanced tab, on the left side of the page, select Triggers.

  4. In the Triggers subtab, inspect the information of the Details column for the desired rule.

Delete Trigger Rules

  1. On the Query Pipelines (platform-eu | platform-au) page, click the query pipeline for which you want to delete query pipeline rules, and then click Edit components in the Action bar.

  2. On the page that opens, select the Advanced tab.

  3. In the Advanced tab, on the left-hand side of the page, select Trigger.

  4. In the Trigger subtab, click the rule you want to delete.

  5. Click Delete to confirm.

Change the Rule Order

Query pipeline rules are executed in the order in which they appear on the page until a condition is satisfied.

  1. On the Query Pipelines (platform-eu | platform-au) page, click the query pipeline for which you want to manage the rules' execution order, and then click Edit components in the Action bar.

  2. On the page that opens, select the Advanced tab.

  3. In the Advanced tab, on the left-hand side of the page, select Triggers.

  4. In the Triggers subtab, click the rule whose position you want to change.

  5. In the Action bar, click Move up or Move down to change the position of the rule.

Reference

Methods

When managing trigger rules, you can select one of the following trigger types:

Notify

When creating or editing a Notify trigger rule, in the String box, enter a message to display in the search interface.

Example

On your internal search page for parts, each time a query is performed without a model number, you want to show Add a model number to your query to the user.

Notify trigger being displayed in a search page
Note

You can use HTML in the String box. This means that HTML characters (e.g., < or >) may be interpreted as such when entered in the String box.

Therefore, if you want to specify these characters themselves, outside of HTML, you must use their entities equivalent.

Using HTML in Notify Rules

When creating a Notify trigger rule, you can use HTML in the String box.

For instance, you may want to format the message to display in the search interface or execute JavaScript functions.

Example

You want your trigger rule to display a formatted message that contains an external link which triggers an event when clicked by the user.

Therefore, you enter the following in the String box:

<span style='<HTML-STYLING>'><a href='<EXTERNAL-LINK>' onclick='<JS-FUNCTION>'><LINK-TEXT></a></span>

Where:

  • <HTML-STYLING> is replaced with the inline CSS styling for the link (e.g., font-size:24pt).

  • <EXTERNAL-LINK> is replaced with the URL where you want users to be redirected (e.g., https://docs.coveo.com/en/0/coveo-documentation).

  • <JS-FUNCTION> is replaced with the JavaScript function you want to be executed when users click the link.

  • <LINK-TEXT> is replaced with the text you want to be dipslayed on the clickable link (e.g., Coveo Documentation).

Reporting on Notification Clicks

You may want to capture information about clicks made by your end users on notification links.

For example, if you have a Notify trigger rule that displays a link when end users perform a certain query, you might want to capture information about its usage and leverage it in usage analytics (UA) reports.

The approach to capture clicks on notification links differs depending on whether the links redirects to items in your index or external resources (i.e., resources that aren’t in your index):

  • When notification links redirect to items in the index, log these clicks as regular click events.

    These clicks are taken into account in the Search Event Click-Through metric and Coveo Machine Learning (Coveo ML) Automatic Relevance Tuning (ART) models can learn from them.

  • When notification links redirect to external resources, the best approach is to log these clicks as custom events.

    Since the resources aren’t in your index, you don’t have all the information necessary to send the required request body properties to the Coveo UA Write API when logging click events.

    When logging notification clicks as custom events, consider that:

    • These events can’t be used by Coveo ML ART models.

    • If you want to calculate the click-through rate related to these clicks, you must use report cards. The default Search Event Click-Through metric can’t be used since clicks logged as custom events aren’t considered as regular click events from a Coveo UA perspective.

      For example, you could have one metric card showing the number of times the notification link was shown (query count), one metric card showing the number of clicks on the notification link (click count), and one calculated metric card dividing the click count by the query count multiplied by 100.

      click-through usage analytics metric cards
    Tip
    Leading practice

    Considering these facts, we recommend that you add these external resources to your Coveo index. This way, you could use these clicks to feed Coveo ML ART models and a default metric to report on the click-through rate.

Query

When creating or editing a Query trigger rule, in the Query box, enter a query to perform as a new search in the search interface.

Note

This method can be used as a custom Did You Mean feature or a thesaurus.

Execute

When creating or editing an Execute trigger rule, in the Function box, enter a JavaScript function to execute in the user’s browser.

Examples
  • You recently deprecated the ACME CTRLR product, but realize that your support agents still search for it. To make sure that all your agents are aware of that recent change, you configured the deprecatedProduct() JavaScript function in your search interface to ask them to confirm their query when they’re about to send the ACME ctrlr query:

    function deprecatedProduct() {
        var currentQuery = Coveo.state(Coveo.$$(document).find("#search"), "q");
        confirm("The '" + currentQuery + "' product has been deprecated. Are you sure you want to continue?");
    };

    Since you want this function to execute only when the ACME ctrlr query is sent, you configure an Execute trigger rule that targets the deprecatedProduct() function and that executes only when a user sends the ACME ctrlr query.

    execute trigger rule in the Administration Console
  • A user searches webcam. Since this query can refer to any model, you create a function to generate a carousel of webcams each time webcam is queried, and then let the user select the one they’re looking for.

  • You want a box to appear at the top of the search results when users search for the name of a product. This box contains a download link and links to the product documentation guides.

    Admin-TriggerEx

Redirect

When creating or editing a Redirect trigger rule, in the URL box, enter a URL to redirect the user.

Example

For certain queries, you always want a specific web page to be opened. A user searching find stores is automatically redirected to your Store Finder page instead of being shown search results that contain the phrase find stores.

QPL Syntax

Use the following query pipeline language (QPL) syntax to define a trigger rule:

execute <function> | notify <message> | query <expression> | redirect <url>

<function>

A string that contains the JavaScript function call to execute (e.g., myFunction()). Boolean, integer, and quoted string function arguments are allowed.

Note

When specifying a function containing arguments (e.g., myFunction(true, 123, "abc")), the arguments aren’t executed in the function as is. The argument values are rather returned in an object as follows:

{
  element: div.CoveoTriggers,
  param1: true,
  param2: 123,
  param3: "abc"
}

Therefore, the corresponding function must be implemented accordingly on client-side. For example, if the trigger expression is execute myFunction(true,123,"abc"), the corresponding function could be configured as follows:

function myFunction(paramValues) {
    /*
    `paramValues` appear in an object:
      {
         element: div.CoveoTriggers,
         param1: true,
         param2: 123,
         param3: "abc"
      }
    */
    alert("Hi, This is your answer:  " + paramValues.param3); // paramValues.param3 is "abc"
};

<message>

A quoted string that contains a message to display to the end user (e.g., "Hello world!").

<expression>

A query expression to perform against the index (e.g., coveo OR "machine learning").

<url>

A quoted string that contains a URL to which the browser is redirected (e.g., "http://www.example.com").

Order of Execution

The following diagram illustrates the overall order of execution of query pipeline features:

order of pipeline execution

Required Privileges

By default, members of the Administrators and Relevance Managers built-in groups can view and edit elements of the Query Pipelines (platform-eu | platform-au) page.

The following table indicates the required privileges to view or edit trigger rules (see Manage Privileges and Privilege Reference).

Action Service - Domain Required access level

View trigger rules

Organization - Organization
Search - Query pipelines

View

Edit trigger rules

Organization - Organization

View

Search - Query pipelines

Edit


1. (Advanced) You can click Menu, and then select Add rule with code to define the rule using the appropriate QPL syntax.
2. (Advanced) You can click More, and then select Edit code to edit the rule using the appropriate QPL syntax.