UNPKG

@klevu/core

Version:

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

48 lines (47 loc) 2.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.sendMerchandisingViewEvent = void 0; const index_js_1 = require("../../events/index.js"); const extractActiveFilters_js_1 = require("../../utils/extractActiveFilters.js"); /** * This modifier should be used with merchandising query. It sends * automatically correct event data to Klevu * * @category Modifier * @param title Title of the category page viewed * @returns */ function sendMerchandisingViewEvent(title, override) { return { klevuModifierId: "sendMerchandisingViewEvent", ssrOnResultFE: true, onResult: (res, f) => { var _a, _b, _c, _d; if (!f.params) { return res; } const { id, abtest } = f.params; if (f.klevuFunctionId !== "categoryMerchandising" || !id) { return res; } const categoryFunction = (_a = f.queries) === null || _a === void 0 ? void 0 : _a.find((q) => { var _a, _b; return Boolean((_b = (_a = q.settings) === null || _a === void 0 ? void 0 : _a.query) === null || _b === void 0 ? void 0 : _b.categoryPath); }); const category = (_d = (_c = (_b = categoryFunction === null || categoryFunction === void 0 ? void 0 : categoryFunction.settings) === null || _b === void 0 ? void 0 : _b.query) === null || _c === void 0 ? void 0 : _c.categoryPath) !== null && _d !== void 0 ? _d : "unknown"; const queryResult = res.queriesById(id); if (!queryResult) { return res; } index_js_1.KlevuEvents.categoryMerchandisingView({ categoryTitle: title, klevuCategory: category, products: queryResult.records, pageStartsFrom: queryResult.meta.offset, abTestId: abtest === null || abtest === void 0 ? void 0 : abtest.abTestId, abTestVariantId: abtest === null || abtest === void 0 ? void 0 : abtest.abTestVariantId, activeFilters: (0, extractActiveFilters_js_1.extractActiveFilters)(queryResult), override, }); return res; }, }; } exports.sendMerchandisingViewEvent = sendMerchandisingViewEvent;