UNPKG

@klevu/core

Version:

Typescript SDK that simplifies development on Klevu backend. Klevu provides advanced AI-powered search and discovery solutions for online retailers.

45 lines (44 loc) 1.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.sendSearchEvent = void 0; const index_js_1 = require("../../events/index.js"); /** * This modifier should be used in the case when user hits enter (or presses button) to see * all results from search. * * @category Modifier * @returns */ function sendSearchEvent(override) { return { klevuModifierId: "sendSearchEvent", ssrOnResultFE: true, onResult: (res, f) => { var _a; if (!f.params) { return res; } const { id, term } = f.params; if (!id || !term) { return res; } const meta = (_a = res.queriesById(id)) === null || _a === void 0 ? void 0 : _a.meta; if (!meta) { return res; } index_js_1.KlevuEvents.search({ term, totalResults: meta.totalResultsFound, typeOfSearch: meta.typeOfSearch, override, tags: meta.tags, }); if (!f.params) { f.params = {}; } f.params.searchSendEventSent = true; return res; }, }; } exports.sendSearchEvent = sendSearchEvent;