1. Functions

widgetFacetClick

Version:
TypeFunction
Import path@sitecore-cloudsdk/search/server

Sends a facet click event.

Signature

export async function widgetFacetClick(
  widgetFacetClickEventParams: WidgetFacetClickEventParams
): Promise<EPResponse | null>

Parameters

NameTypeDescription
widgetFacetClickEventParamsWidgetFacetClickEventParamsData for facet click events.

Return value

Returns a promise.

Examples

Example 77. Running the widgetFacetClick function

Note

To run this function, you have to first initialize the Cloud SDK.

See more examples and other data you can include in the event.

Here's an example of how to use the widgetFacetClick function:

import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";
import { CloudSDK } from "@sitecore-cloudsdk/core/server";
import { widgetFacetClick } from "@sitecore-cloudsdk/search/server";
import type { WidgetFacetClickEventParams } from "@sitecore-cloudsdk/search/server";

export default async function middleware(request: NextRequest) {
  const response = NextResponse.next();

  // Initialize the SDK and the package...

  // Send event:
  const eventData: WidgetFacetClickEventParams = {
    filters: [
      {
        displayName: "Color",
        facetPosition: 1,
        name: "color",
        title: "Color",
        value: "Blue",
        valuePosition: 5
      }
    ],
    request: {
      keyword: "green",
      numResults: 3,
      totalResults: 3,
      numRequested: 10
    },
    pathname: "/search",
    widgetId: "rfkid_7"
  };

  const widgetFacetClickResponse = await widgetFacetClick(request, eventData);
  console.log("Sent widget facet click event.", widgetFacetClickResponse);

  return response;
}

:::

If you have suggestions for improving this article, let us know!