1. Functions

widgetSuggestionClick

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

Sends a suggestion click event.

Signature

export async function widgetSuggestionClick(
  widgetSuggestionClickEventParams: WidgetSuggestionClickEventParams
): Promise<EPResponse | null>

Parameters

NameTypeDescription
widgetSuggestionClickEventParamsWidgetSuggestionClickEventParamsData for suggestion click events.

Return value

Returns a promise.

Examples

Example 79. Running the widgetSuggestionClick 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 widgetSuggestionClick function:

import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";
import { CloudSDK } from "@sitecore-cloudsdk/core/server";
import { widgetSuggestionClick } from "@sitecore-cloudsdk/search/server";
import type { WidgetSuggestionClickEventParams } 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: WidgetSuggestionClickEventParams = {
    request: {
    keyword: "green"
    },
    pathname: "/page",
    widgetId: "rfkid_6"
  };

  const widgetSuggestionClickResponse = await widgetSuggestionClick(request, eventData);
  console.log("Sent widget suggestion click event.", widgetSuggestionClickResponse);

  return response;
};

:::

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