Analytics & Reports
Analytics
StoreFront

Recently Searched For

Business Goal: I want to show recent searches done within the same session, as customers frequently compare and contrast different sets of results.

This can be rendered on the front end a list of suggested searches, for example within SAYT:

Personalization

In this example, you see the recently executed search for red dress, followed by popular keywords. For more on Search As You Type and how to bring back the Navigations, please see the SAYT documentation.

Sample query

This query relies on 3 factors:

  1. The sessionId, visitorId, or loginId if you wish to make the recent searches more sticky. Picking the shortest one (sessionId) will reduce how long the suggested searches stick; picking loginId will let you help customers across their devices as long as they are logged in.

    The exact syntax to filter down to the session ID is: "matchExact":{"and":[{"visit":{"customerData":{"sessionId":"<current session ID>"}}}]}

  2. The partial match (matchPartial) on query - we will use top

  3. The window of how far back we want to look (this can be day, week, or month) - this example uses day

curl
curl -H "Authorization: --clientKey--"  -XPOST \
"https://--customerId--.groupbycloud.com/wisdom/v2/events/search" \
-d '{"window":"day","matchPartial":{"and":[{"search":{"query":"top"}}]}, "matchExact":{"and":[{"visit":{"customerData":{"sessionId":"<current session ID>"}}}]}}'
Note:

In the above example, you must check with a specific session ID to see sample recall.

Response

In the response you can grab the .result.recent[].search.query fields, which will contain all the searches done within the filtered session.The format of the response is:

json
"status": {
    "code": "200",
    "message": "OK",
    "additionalInfo": "null"
},
"result":{
  "window": "day",
  "count": "3",
  "recent": [
    { "search": {
      "id": "id of this search",
      "query": "the full query",
      "other": "other portions of the search response"
    },
    "clientVersion": "your beacon version",
    "customer": "your customer ID and Area",
    "visit": {
      "customerData": {
          "sessionId": "...",
          "visitorId": "..."
      },
      "generated:": {
        "deviceType": "desktop",
        "localTime": "...",
        "other": "other generated metadata"
      }
    }
  }
  ]
}
Note:

count returns the number of events that this customer had with these parameters. This example only shows the first object in the array that would contain 3 response objects.