Events
The following events are provided by both textsearch and dualsearch instances to help you track and respond to search activities in your application.
Note that the data provided from these events may vary depending on whether you're using textsearch or aisearch functionality.
searchStarted
Event fired when a search operation begins. It provides all current search parameters and filter settings that will be used for the search.
const ts = window.yesplz.textsearch();
ts.on("searchStarted", function (data) {
/*
data: {
brands: string[], // Selected brand filters array
categories: string[], // Selected category filters array
colors: string[], // Selected color filters array
discount: string[], // Discount rate filters array
materials: string[], // Selected material filters array
sale: boolean, // Sale items filter flag
shipping: string[], // Shipping options filters array
sizes: string[], // Selected size filters array
sort: string // Sort method (e.g. "popular")
isAISearch: boolean, // Whether AI search is enabled
offset: number, // Page offset for pagination
}
*/
});
searchFinished
Event fired when a search operation completes. This event is emitted after results are retrieved from the server. It provides comprehensive information about the search results, including matching products, and available filters.
const ts = window.yesplz.textsearch();
ts.on("searchFinished", function (data) {
/*
data: {
counts: {
total: number, // Total number of products in database
},
filter: { // Available filters for the search results
brandName: object,
retailerCategory: array,
discountRate: object,
// ... other filter options
},
message: string, // AI generated message for AI Search
results: array, // Array of product objects matching the search
}
*/
});