UNPKG

@klevu/core

Version:

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

163 lines (162 loc) 8.36 kB
import { KlevuKMCRecommendations, KlevuRecord, KlevuTypeOfSearch } from "../index.js"; import { KlevuRecommendationsEventV2Data, KlevuEventV2DataStaticContent, KlevuV1CategoryProductsClick, KlevuV1CategoryProductsView, V1ProductTrackingEvent, V1SearchEvent, V2CheckedOutProductsEvent, KlevuV1ImageBannerClick } from "./eventRequests.js"; export type RecommendationViewEventMetaData = KlevuKMCRecommendations["metadata"]; /** * @category KlevuEvents */ export declare class KlevuEvents { /** * Tell Klevu what products where bought by the user * * @param items Items user bought * @property amount count of bought products * @property product KlevuProduct that is being bought * @property variantId optional variantId that is being bought * @property override optional override any settings of sent data * */ static buy({ user, items, }: { user?: { ip_address?: string; email?: string; }; items: Array<{ amount: number; product: Pick<KlevuRecord, "id"> & Partial<Pick<KlevuRecord, "currency" | "itemGroupId" | "salePrice" | "name">>; variantId?: string; orderId?: string; orderLineId?: string; override?: Partial<V2CheckedOutProductsEvent["event_data"]["items"][number]>; }>; }): void; /** * When recommendation banner is shown in the page * * @param recommendation Metadata of what recommendation is shown * @param products List of all products that are shown * @param bannerInfo Information about the static banner that is shown * @param override Ability to override any analytical keys in low level */ static recommendationView({ recommendationMetadata, products, bannerInfo, override, }: { recommendationMetadata: Partial<RecommendationViewEventMetaData> & Pick<RecommendationViewEventMetaData, "logic" | "recsKey" | "title">; products?: Array<Pick<KlevuRecord, "id"> & Partial<Pick<KlevuRecord, "itemGroupId" | "variantId" | "name" | "price" | "currency" | "brand" | "category">>>; bannerInfo?: KlevuEventV2DataStaticContent; override?: Partial<KlevuRecommendationsEventV2Data>; }): void; /** * When product has been clicked in the recommendation banner * * @param recommendationMetadata Metadata of what recommendation is clicked * @param bannerInfo Information about the static banner that is shown * @param product Which product is clicked in the list * @param productIndexInList What is the index of the product in the list. Starting from 1 * @param override Ability to override any analytical keys in low level */ static recommendationClick({ recommendationMetadata, product, bannerInfo, productIndexInList, variantId, override, }: { recommendationMetadata: RecommendationViewEventMetaData; bannerInfo?: KlevuEventV2DataStaticContent; product?: Pick<KlevuRecord, "id"> & Partial<Pick<KlevuRecord, "itemGroupId" | "name" | "salePrice" | "currency" | "brand" | "category">>; productIndexInList?: number; variantId?: string; override?: Partial<KlevuRecommendationsEventV2Data>; }): void; /** * When product is clicked. Do not use this for recommendations * * @param searchTerm * @param product */ static searchProductClick({ product, searchTerm, variantId, activeFilters, tags, override, }: { product: Pick<KlevuRecord, "id"> & Partial<Pick<KlevuRecord, "itemGroupId" | "name" | "url">>; searchTerm?: string; variantId?: string; activeFilters?: string; override?: Partial<V1ProductTrackingEvent>; tags?: string[]; }): void; /** * What user has last searched. This is important for Klevu to function * properly. Use `sendSearchEvent()` modifier with search query to send results * * @param term What was searched * @param totalResults Total number of results (can be found in result meta) * @param typeOfSearch Type of search used (can be found in result meta) * @param override Ability to override any analytical keys in low level */ static search({ term, totalResults, typeOfSearch, activeFilters, tags, override, }: { term: string; totalResults: number; typeOfSearch: KlevuTypeOfSearch; activeFilters?: string; override?: Partial<V1SearchEvent>; tags?: string[]; }): void; /** * * @param categoryTitle This is the name of the category being visited. For example, Stackable Rings. The name should not include parent categories. * @param klevuCategory This is the complete hierarchy of the category being visited. For example, Jewellery;Rings;Stackable Rings. Please note the use of a semicolon as the separator between a parent and a child category. * @param products Products in the view * @param pageStartsFrom Offset of the first product being shown on this page. For example, if you are displaying 30 products per page and if a customer is on the 2nd page, the value here should be 30. If on the 3rd page, it will be 60. * @param abTestId The AB test id currently running * @param abTestVariantId Id of AB test variant * @param activeFilters The string version of active filters applied to the query that got the products. * @param override Ability to override any analytical keys in low level */ static categoryMerchandisingView({ categoryTitle, klevuCategory, products, pageStartsFrom, abTestId, abTestVariantId, activeFilters, override, }: { categoryTitle: string; klevuCategory: string; products: Array<Pick<KlevuRecord, "id">>; pageStartsFrom?: number; abTestId?: string; abTestVariantId?: string; activeFilters?: string; override?: Partial<KlevuV1CategoryProductsView>; }): void; /** * * @param product Product clicked * @param categoryTitle This is the name of the category being visited. For example, Stackable Rings. The name should not include parent categories. * @param klevuCategory This is the complete hierarchy of the category being visited. For example, Jewellery;Rings;Stackable Rings. Please note the use of a semicolon as the separator between a parent and a child category. * @param variantId This is the child/variant ID of the clicked product. eg. 12345. For compound products with a parent and multiple child/variant products, this is the ID of the specific variant. * @param productPosition Position of the product on the category page when it was clicked. For example, the value would be 0 if it is the first product on the first page. The value will be 30, if it is the first product on the 2nd page with 30 products being displayed per page. * @param activeFilters The string version of active filters applied to the query that got the products. * @param override Ability to override any analytical keys in low level */ static categoryMerchandisingProductClick({ product, categoryTitle, klevuCategory, variantId, productPosition, abTestId, abTestVariantId, activeFilters, override, }: { product: Pick<KlevuRecord, "id"> & Partial<Pick<KlevuRecord, "itemGroupId" | "name" | "url" | "salePrice" | "sku">>; categoryTitle: string; klevuCategory: string; variantId?: string; productPosition?: number; abTestId?: string; abTestVariantId?: string; activeFilters?: string; override?: Partial<KlevuV1CategoryProductsClick>; }): void; /** * When user clicks on the banner that is in quicksearch or on search landing page */ static imageBannerClick({ term, bannerId, bannerName, imageUrl, targetUrl, override, }: { /** * Search term used to get the results */ term: string; /** * Id of the banner */ bannerId: string; /** * Name of the banner */ bannerName: string; /** * Url of the image */ imageUrl: string; /** * Url where the user is redirected */ targetUrl: string; override: Partial<KlevuV1ImageBannerClick>; }): void; }