Search

Redirects

Send visitors to pages of your choice for specific queries.
Redirects in my.clerk.io

Redirects allows you to create a direct connection between a query or keyword and a specific url. When can you use it?

For example, you have a stand-alone product for one category, and you want to make it possible for your costumers to directly search for the product page from the search, without passing by the search page.

This guide will be divided into two sections. The first one is to show you how to create a Redirect for your store and the second part the additional steps you will have to follow if you have a custom API store.

Creating Redirects #

  1. Go to Search > Redirects > New redirect.

  2. Insert the URL of the product or other page you want visitors to be sent to, when pressing enter after searching.

  3. Add one or more queries that should cause the redirect. Queries that match exactly will redirect if a user types that exact word or phrase, while Queries that contain will redirect if the word of phrase is a part of the full search.

  4. Click Save & Close to apply it.

API Setup #

If you have integrated Clerk with the API directly, the redirect link will be returned by the endpoints search/predictive and search/search for any queries that match the Redirect rules you created.

The Redirect URL will be included in the redirect key of the response.

Example:

# API Call
curl -X POST \
     -H 'Content-Type: application/json' \
     -d '{"key": "store_api_key",
          "query": "softball",
          "language": "english",
          "limit": 6,
          "visitor": "unique_visitor_id",
          "labels": ["Instant Search"]}' \
     http://api.clerk.io/v2/search/predictive

# Response
{
  "status": "ok",
  "query": "softball",
  "count": 2,
  "result": [
    37217,
    40058
    ],
  "hits": 2,
  "redirect": "https://www.thebaseballgeek.co.uk/softball"
}

Troubleshooting #

Many scripts add functionality to your search field, so if your redirect does not work, there is a good chance that another script is overwriting the functionality.

Below is an example of how you can overwrite existing functionality to force your Clerk redirects to be prioritised. It might require customisation for your setup.

<script>
(function() {
input_selector = document.querySelector('#{{ content.id }}').dataset.instantSearch;
document.querySelectorAll(input_selector).forEach(input=>{
  input.addEventListener('keyup', function(event){
      {% if redirect %}
      var currentRedirect = '{{ redirect }}';
      {% else %}
      var currentRedirect = undefined;
      {% endif %}
      if(event.which == 13 || event.which == 'Enter'){
          if(currentRedirect != undefined){
              event.preventDefault();
              window.location.replace(currentRedirect);
          }
      }
  });
});
})();
</script>